Date : Sat, 22 May 2004 12:56:54 +0100
From : Richard Gellman <splodge@...>
Subject: Re: [Electron] sound wave
gARetH baBB wrote:
>On Fri, 21 May 2004, Thomas Harte wrote:
>
>
>
>>to accurately reproduce things like the Exile loading speech for ages,
>>this isn't really what I want to focus on.
>>
>>
>
>? No Electron game did speech.
>
>Superior investigated doing Speech ! for the Electron but abandoned it
>because it wasn't possible.
>
>
Actually, it is possible to do digital audio with an "on-off" type
speaker. It has been done with a PC speaker, which is nothing more than
an amplitifed output of a buffered IRQ line. An onboard timer generates
an IRQ at a programmed interval, that IRQ is fed into a 1-bit counter,
which is then amplified and sent to the speaker.
The trick there, since you have no control over amplitude, is to
understand how the waveform works. When you set it to a really high
frequency, you have it moving so fast between off and on at equal time
periods that it "sounds" to be exactly halfway between. To get that
"hafl point" to move, you need to spend more time in one state than the
other. For example, for three-quarters volume, out of you need to be
spending three times more time in the on state than the off state. The
equation works inversely and has a subtle offset. Since 3 quarters is 3
times as much as one quarter, then the time period multiplier is three.
when the two are added together it makes a whole cycle.
With the PC Speaker this is done using some very accurate IRQ handling
timing that can adjust the time period mid-cycle to get it to be more on
than off, or more off than on. Again, because the ear doesn't hear the
"carrier", only the demodulated waveform, you get digitised audio. In
some cases, it can actually be higher resolution than the BBC Micro
method, depending on what the resolution of the hardware around the
speaker is.
I would imagine this is how the Electron manages it, with an interrupt
handler swapping frequencies at the precise moment to change the
relative on/off periods. Given the timing requirements, I would suggest
the frequency has been lowered to make the sound easier to accomplish in
a normal 6502 timeframe.
-- Richard