PWM 1-bit audio paper [message #393438] |
Mon, 04 May 2020 09:11 |
sicklittlemonkey
Messages: 570 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
For those interested in Pulse Width Modulation for 1-bit audio, this recent paper might be of interest:
The 1-Bit Instrument: The Fundamentals of 1-Bit Synthesis, Their Implementational Implications, and Instrumental Possibilities
https://online.ucpress.edu/jsmg/article/1/1/44/2337/The-1-Bi t-InstrumentThe-Fundamentals-of-1-Bit
It was written by Dr. Blake Troise who makes chiptunes under the moniker Protodome.
https://protodome.com/
https://protodome.bandcamp.com/
He released an album that can be played on a $2 8-bit, 8-pin microcontroller, complete with source code.
https://scruss.com/blog/2020/04/02/protodomes-wonderful-chip tunes-how-to-play-them-on-your-own-attiny85-chips/
https://github.com/protodomemusic/mmml
ATtiny85
"The high-performance, low-power Microchip 8-bit AVR RISC-based microcontroller combines 8KB ISP flash memory, 512B EEPROM, 512-Byte SRAM."
I wonder if his album could be ported ... ; - )
Cheers,
Nick.
|
|
|
|
|
|
|
|
|
|
Re: PWM 1-bit audio paper [message #393573 is a reply to message #393442] |
Mon, 04 May 2020 20:56 |
Michael J. Mahon
Messages: 1767 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
Frank M. <frank_o_rama@hotmail.com> wrote:
> There's also delta-sigma encoding (0 bit = waveform goes up, 1 bit =
> waveform goes down, rather than trying to create a DAC) but samples won't
> fit into 8k. I'm not sure, but I think that will give higher quality than
> DAC522 but at the expense of sample file size.
>
> https://www.romanblack.com/btc_alg.htm
>
> https://github.com/oliverschmidt/Play-BTc
>
Give it a try.
I think you’ll find that the reproduction quality of DAC522 is hard to
improve on, particularly with limited RAM.
I’ve done several experiments with BTc at very high bit rates, and the
results were far inferior to DAC522.
The reason is pretty intuitive. DAC522 generates a stream of pulses at
22kHz where each pair of pulses is precisely timed at 32 distinct widths,
varying by a single cycle—the maximum timing resolution for a 1MHz clock.
As a result, the energy of each pulse pair varies in 32 equal steps and
this precise energy is delivered to the speaker for each sample.
BTc, on the other hand, delivers a stream of fixed width pulses, or not, at
a fixed frequency, which may be as high as 72kHz on a 1MHz Apple. So in
any 92-cycle interval (about 11kHz), there will be about 6-1/2 BTc pulses
which are either present or not (1 or 0). Since all pulses have the same
energy, there are only a little more than six different total energy
possibilities during each 11kHz sample time, or about 2.5 bits of “delta”
per sample time.
For low bandwidth signals, this might be sufficient for reasonable
reproduction, but if the 11kHz sample stream contains signal frequencies
over one kilohertz, BTc will severely attenuate them.
11kHz sample streams are sometimes characterized as “AM radio quality”, and
one reasonably expects frequency response to be limited only by the Nyquist
frequency—in this case, 5kHz is a practical upper limit, and these
frequencies require nearly full-scale changes in one sample time.
DAC522 can change the speaker drive full-scale in one sample time, while
BTc will require 5 x 6 pulse times (5 sample times) to achieve the same
32-fold speaker drive change.
The easiest way to use DAC522 to play arbitrary sample streams (of up to
about two second duration) is to run SOUND.EDITOR (available on my
website). The sample stream should be 8-bit mono, unsigned, at 11.025
kHz—easily done in Audacity.
The fundamental issue of using sampled sound on an 8-bit Apple is the
space-quality tradeoff. SOUND.EDITOR reserves a 20K buffer for sampled
sounds, hence the 2-second duration limit. The SOUND.EDITOR disk image
contains documentation and several sampled sounds to try out.
Of course, it would be possible to back DAC522 off by one bit of precision
(making it DAC422 ;-), allowing two samples to be packed per byte. You can
easily experiment with DAC precision less than or equal to five bits by
simply masking the low bits of the sample stream. (I did this demo a few
years ago at KFest.) I decided that the fifth bit was worth it, and that
the ability to play “unpacked” sample streams was handy.
I began my experimentation with Apple II sound with simple 1-bit sampling
through the cassette port, but the quality did not remotely approach the
quality of even 3-bit PWM audio, which I first heard from Scott Alfter’s
“Insert Disk” demo.
I then progressed to 4-bits, 5-bits, and 6-bits, all running at a pulse
rate of 11kHz. But the intense screech of the 11kHz “carrier” inspired me
to trade one bit of precision for doubling the pulse rate to produce
DAC522. The 22kHz pulse rate is high enough that it’s tolerable for younger
ears and almost inaudible for older ones. ;-)
SOUND.EDITOR also has a 2:1 ADPCM compressor and decompressor, allowing
twice as much sampled sound on a disk.
I recommend switching to cassette port output and playing it through an
amplifier with the “treble” turned down to attenuate the pulse stream
without limiting the signal. The sound amplifier attached to the AppleCrate
II has a 5-pole lowpass filter tuned to attenuate sound above 5kHz, which
delivers great sound.
--
-michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
|
|
|
|
Re: PWM 1-bit audio paper [message #393577 is a reply to message #393573] |
Tue, 05 May 2020 01:14 |
sicklittlemonkey
Messages: 570 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
On Tuesday, 5 May 2020 10:56:57 UTC+10, Michael J. Mahon wrote:
> I think you’ll find that the reproduction quality of DAC522 is hard to
> improve on, particularly with limited RAM.
You're likely right, which is why I put this in my answer:
Probably the ultimate evolution of Apple II 1-bit audio are projects written using Michael Mahon's DAC522, including RT.SYNTH and Digital Music Synthesizer & Drummer:
https://retrocomputing.stackexchange.com/a/14661/71
BTW, I sent you an email a while back about your website (and another matter) but got no reply. It seems to be using 8-bit characters like "Em Dash" in a Windows charset (probably 1252) which show up as Chinese for me.
I.e. https://www.compart.com/en/unicode/U+2014
Hopefully the following line will illustrate what I see (if this comment is in UTF8):
Apple II Networking and Parallel Computing湧adaNet 3.1 ...
Cheers,
Nick.
|
|
|
Re: PWM 1-bit audio paper [message #393578 is a reply to message #393441] |
Tue, 05 May 2020 01:25 |
sicklittlemonkey
Messages: 570 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
On Tuesday, 5 May 2020 01:13:50 UTC+10, fadden wrote:
> For anyone not on the retrocomputing Q&A...
Thanks Andy.
Your comment about Airheart was dead on BTW! I'd forgotten about that. Not only in the in-game enemy distance-volume relationship, but the repeated "chiming" sound that fades away. Definitely my pick for finest graphical programming on an Apple II, and contender for finest use of sound.
Cheers,
Nick.
|
|
|
Re: PWM 1-bit audio paper [message #393579 is a reply to message #393577] |
Tue, 05 May 2020 02:33 |
Michael J. Mahon
Messages: 1767 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
Nick Westgate <nick.westgate@gmail.com> wrote:
> On Tuesday, 5 May 2020 10:56:57 UTC+10, Michael J. Mahon wrote:
>> I think you’ll find that the reproduction quality of DAC522 is hard to
>> improve on, particularly with limited RAM.
>
> You're likely right, which is why I put this in my answer:
> Probably the ultimate evolution of Apple II 1-bit audio are projects
> written using Michael Mahon's DAC522, including RT.SYNTH and Digital
> Music Synthesizer & Drummer:
> https://retrocomputing.stackexchange.com/a/14661/71
>
> BTW, I sent you an email a while back about your website (and another
> matter) but got no reply. It seems to be using 8-bit characters like "Em
> Dash" in a Windows charset (probably 1252) which show up as Chinese for me.
> I.e. https://www.compart.com/en/unicode/U+2014
>
> Hopefully the following line will illustrate what I see (if this comment is in UTF8):
> Apple II Networking and Parallel Computing湧adaNet 3.1 ...
>
> Cheers,
> Nick.
>
Nick, I didn’t receive your email, though I don’t know why not. I don’t
lose messages to a spam folder, so I’m perplexed about what happened.
Please resend—I’m curious about the “other matter”. ;-) BTW, I’m writing
this on my iPhone, and I note that it, too, has replaced my double hyphen
above with an em dash! Is this a more compatible one, or is it the same
problem? It shows up here as a dash, not a Chinese character.
Of course, you are correct, I do use an em dash. Years ago, I created my
initial web pages using Word 97 (!), and it auto-replaced a two-hyphen
“dash” with an em dash, which is a more authentic dash to my eye. Since
then, I’ve copied and pasted that original dash several times into other
pages. It never occurred to me that this was not a standard character. In
the next month or so I’ll revisit my site and clean this up, along with a
few other “proofreading” changes. It’s disappointing that character set
issues still exist in this >8-bit character world.
Thank you for introducing DAC522 in the Stack Exchange thread. I was
unaware of it until this csa2 thread.
--
-michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
|
|
|
Re: PWM 1-bit audio paper [message #393962 is a reply to message #393438] |
Tue, 05 May 2020 10:13 |
|
Originally posted by: Frank M.
Hi Michael,
Thanks for the additional info. I always enjoy your responses.
I read a little more yesterday. The technique presented here is 3 voice + 1 noise, OR-added PWM. The author uses PWM 'samples' for each voice, but it doesn't sound like the Apple II would have enough processing power to do all that (the AVR runs at 8mhz with instructions taking 1 cycle, 32x faster than a 'typical' 4 cycles per instruction on the 1mhz A2).
Correct me if I'm wrong, but one downside of DAC522 is that is discards the last 3 bits of each byte. Again, the tradeoff of quality vs size.
I should try adapting DAC522 with ProRWTS2 for a streaming audio player. Ramp masking the speaker would still be an issue there as it was with using delta-encoding, though.
Frank
|
|
|
Re: PWM 1-bit audio paper [message #393965 is a reply to message #393579] |
Tue, 05 May 2020 10:52 |
|
Originally posted by: fadden
On Monday, May 4, 2020 at 11:33:43 PM UTC-7, Michael J. Mahon wrote:
> [...] It’s disappointing that character set
> issues still exist in this >8-bit character world.
The web has evolved a bit over the years, but some browsers always manage to get it wrong. Looking at your pages, you're explicitly specifying CP1252:
CONTENT="text/html; charset=windows-1252"
If a browser chooses to mis-interpret '—' as Chinese, that's not on you. :-)
Actually, it is a little, since web standards have moved away from "legacy" encodings in favor of UTF-8 (or explicit code points, e.g. "—"). You can see a full list of complaints by running it through a web site validator, e.g.:
https://validator.w3.org/nu/?doc=http%3A%2F%2Fmichaeljmahon. com%2FRTSynth.html
All(?) of my pages are "XHTML 1.0 Transitional" because it's close to HTML 1.0 and I can't be bothered to learn the new stuff.
Anyway. Back to the Apple II, where lower case isn't a given. :-)
|
|
|
Re: PWM 1-bit audio paper [message #394018 is a reply to message #393965] |
Tue, 05 May 2020 19:08 |
sicklittlemonkey
Messages: 570 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
On Wednesday, 6 May 2020 00:52:05 UTC+10, fadden wrote:
> CONTENT="text/html; charset=windows-1252"
But not on the home page.
> If a browser chooses to mis-interpret '—' as Chinese, that's not on you. :-)
Yeah, partially my fault. My browser had ja-JP too high up in my Accept-Language list.
> Back to the Apple II, where lower case isn't a given. :-)
Yeah, constraints make things simpler. All audio should be 1-bit!
Cheers,
Nick.
|
|
|
Re: PWM 1-bit audio paper [message #394079 is a reply to message #393962] |
Wed, 06 May 2020 02:38 |
Michael J. Mahon
Messages: 1767 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
Frank M. <frank_o_rama@hotmail.com> wrote:
> Hi Michael,
>
> Thanks for the additional info. I always enjoy your responses.
Thanks! ;-)
> I read a little more yesterday. The technique presented here is 3 voice +
> 1 noise, OR-added PWM. The author uses PWM 'samples' for each voice, but
> it doesn't sound like the Apple II would have enough processing power to
> do all that (the AVR runs at 8mhz with instructions taking 1 cycle, 32x
> faster than a 'typical' 4 cycles per instruction on the 1mhz A2).
Right. I could never find the cycles to actually add two or more sample
streams while doing on-the-fly resampling for pitch. The demo recording
seems to identify “chiptunes” with squarewave voices, for which OR-ing
substitutes for addition.
> Correct me if I'm wrong, but one downside of DAC522 is that is discards
> the last 3 bits of each byte. Again, the tradeoff of quality vs size.
Right, it only plays the high 5 bits. There’s not enough time to unpack a
stream of 5-bit fields, so the sample stream is 8-bit samples.
A DAC611 is doable for 11kHz samples, with pulse width varying by 64
cycles, but the 11kHz screech is maddening without a really sharp low pass
filter.
I wrote that possibility off decades ago (at the urgent request of my
family!). The sixth bit of precision does not reduce quantization noise
enough to make it a good tradeoff.
> I should try adapting DAC522 with ProRWTS2 for a streaming audio player.
> Ramp masking the speaker would still be an issue there as it was with
> using delta-encoding, though.
Yes, any interruption in the pulse stream is quite audible. It is possible
to finesse bank switching to allow playing long sample streams without
interruption.
Digital Music Synthesizer and DMS Drummer both deal with this by using
several sample pages per voice, selected by an envelope counter, to produce
almost unlimited <pitch, duration, voice> notes with limited RAM.
Ultimately, 64KB and multimedia are somewhat antithetical to each other.
;-)
> Frank
>
--
-michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
|
|
|
Re: PWM 1-bit audio paper [message #394080 is a reply to message #393965] |
Wed, 06 May 2020 02:38 |
Michael J. Mahon
Messages: 1767 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
fadden <thefadden@gmail.com> wrote:
> On Monday, May 4, 2020 at 11:33:43 PM UTC-7, Michael J. Mahon wrote:
>> [...] It’s disappointing that character set
>> issues still exist in this >8-bit character world.
>
> The web has evolved a bit over the years, but some browsers always manage
> to get it wrong. Looking at your pages, you're explicitly specifying CP1252:
>
> CONTENT="text/html; charset=windows-1252"
>
> If a browser chooses to mis-interpret '—' as Chinese, that's not on you. :-)
>
> Actually, it is a little, since web standards have moved away from
> "legacy" encodings in favor of UTF-8 (or explicit code points, e.g.
> "—"). You can see a full list of complaints by running it through
> a web site validator, e.g.:
>
> https://validator.w3.org/nu/?doc=http%3A%2F%2Fmichaeljmahon. com%2FRTSynth.html
>
> All(?) of my pages are "XHTML 1.0 Transitional" because it's close to
> HTML 1.0 and I can't be bothered to learn the new stuff.
>
> Anyway. Back to the Apple II, where lower case isn't a given. :-)
>
Thank you for the clarification.
I’ll replace all my em dashes with —, though it’s nicer when they look
like dashes in the un-rendered HTML. ;-)
--
-michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
|
|
|
Re: PWM 1-bit audio paper [message #394081 is a reply to message #394018] |
Wed, 06 May 2020 02:38 |
Michael J. Mahon
Messages: 1767 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
Nick Westgate <nick.westgate@gmail.com> wrote:
> On Wednesday, 6 May 2020 00:52:05 UTC+10, fadden wrote:
>> CONTENT="text/html; charset=windows-1252"
>
> But not on the home page.
>
>> If a browser chooses to mis-interpret '—' as Chinese, that's not on you. :-)
>
> Yeah, partially my fault. My browser had ja-JP too high up in my Accept-Language list.
>
>> Back to the Apple II, where lower case isn't a given. :-)
>
> Yeah, constraints make things simpler. All audio should be 1-bit!
>
> Cheers,
> Nick
On a rapidly increasing number of audio platforms, all audio already *is*
1-bit!
Phones, powered speakers, and TVs almost all use power-efficient class D
audio amplifiers, which is exactly 1-bit PWM with an ultrasonic pulse rate.
--
-michael - NadaNet 3.1 and AppleCrate II: http://michaeljmahon.com
|
|
|
Re: PWM 1-bit audio paper [message #394095 is a reply to message #394081] |
Wed, 06 May 2020 04:59 |
sicklittlemonkey
Messages: 570 Registered: October 2012
Karma: 0
|
Senior Member |
|
|
On Wednesday, 6 May 2020 16:38:52 UTC+10, Michael J. Mahon wrote:
> On a rapidly increasing number of audio platforms, all audio already *is*
> 1-bit!
>
> Phones, powered speakers, and TVs almost all use power-efficient class D
> audio amplifiers, which is exactly 1-bit PWM with an ultrasonic pulse rate.
Yeah, when I was researching this I found lots of references to class D amps, but people were saying volume adjustment should be done in analog.
BTW Michael, someone posted another answer which linked to an article you wrote:
https://retrocomputing.stackexchange.com/a/14679/71
http://www.goldwave.ca/forums/viewtopic.php?f=1&t=3586
Cheers,
Nick.
|
|
|
Re: PWM 1-bit audio paper [message #394237 is a reply to message #394079] |
Thu, 07 May 2020 02:54 |
|
Originally posted by: Scott Alfter
In article <Jq2dnSYmyuTpxi_DnZ2dnUU7-IHNnZ2d@giganews.com>,
Michael J. Mahon <mjmahon@aol.com> wrote:
> A DAC611 is doable for 11kHz samples, with pulse width varying by 64
> cycles, but the 11kHz screech is maddening without a really sharp low pass
> filter.
....which is exactly what I used back in the day: a speaker in a crude wooden
box, with an amplifier board I scrounged from somewhere and a low-pass
filter knocked together from a couple grab bags of inductors and capacitors
from Radio Shack, all driven from the cassette-output port on my IIe. It
was crude, but it worked, and most of the 11-kHz screech was filtered out.
It also had the benefit of being louder than the built-in speaker.
_/_
/ v \ Scott Alfter (remove the obvious to send mail)
(IIGS( https://alfter.us/ Top-posting!
\_^_/ >What's the most annoying thing on Usenet?
|
|
|