Obscure bug in speaker implementation
I discovered a bug which is almost certainly not worth fixing, but it is fun to know about.
An undocumented fact about the Apple's speaker is that it doesn't click every time you reference an address in [$C030..$C03F], but every other time. The distance in time between the clicks determines the frequency of the note produced, but the distance in time between the references determines the volume. This is because each reference toggles the cone, pushing it either in or out. The volume of air moved is greatest when the references are spaced an equal time apart. If, instead, the silent reference is shifted closer in time to the previous or next audible reference, the volume diminishes.
I wrote an article about this in the Nov. 1984 NIBBLE magazine. I used it, and it was used in Ultima IV, but I don't know if anyone else ever used it.
Here's a piece of my code that demonstrates this. On a hardware Apple 2, the volume is quiet at first, ramps up to loud, them ramps down to quiet again.
*************************
* TONE
* JULY 1984
TONE LDA SOUND
BEQ T6 NO SOUND
LDA #1
STA T4+1
T1 LDX #4
SEC
LDA #0
SBC T4+1
STA T2+1
T2 LDY #1
T3 DEY
BNE T3
LDA $C030
T4 LDY #0
T5 DEY
BNE T5
LDA $C030
DEX
BNE T2
INC T4+1
BNE T1
T6 RTS
Thanks for sharing this info here. I'll try to find the Nibble article - it must be online somewhere.
btw. how do you know that Ultima IV used this technique?
I used this in some educational titles in the 90's.
Probably borrowed your code Phil, so thanks! ; - )
The article won't tell you any more than that.
The sound made by playing one tone soft to loud to soft with linear ramping is very distinctive and recognizable. I was boot-code tracing one of the Ultimas to deprotect it, and came across the code that makes that sound when you boot the disk. It did the same thing as my code. It might have been Ultima 2 or 3, tho. I don't remember anymore.
On Sun, Sep 2, 2018 at 4:30 PM TomCh [email protected] wrote:
Thanks for sharing this info here. I'll try to find the Nibble article - it must be online somewhere.
btw. how do you know that Ultima IV used this technique?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/AppleWin/AppleWin/issues/579#issuecomment-417957712, or mute the thread https://github.com/notifications/unsubscribe-auth/ACpPhDYgzDw7jvy8lQr9iDoqXiv5MWxdks5uXD_qgaJpZM4WWPf1 .
The distance in time between the clicks determines the frequency of the note produced, but the distance in time between the references determines the volume.
Interesting. https://archive.org/details/sim_nibble_1984-11_5_11
From a wave point of view, I always thought that the clicks just generate a square wave, but it is clearly more complicated than this.
I was trying to read, but failed to get a clear picture. Have you thought how you would turn an array of times where the speaker is accessed into a wave?
Given an amplitude between 0 and 1, could we say the next amplitude as a function of the last 2 time intervals to be:
ampl = min(dt_0, dt_1) / max(dt_0, dt_1)
?
but this would not cause higher volumes at lower frequencies, just lower volume when frequency changes...
I've read that each reference toggles the speaker between an "in" and "out" state. The volume of the sound is proportional to the energy in the sound wave, which is proportional (I think) to the amount of air moved. So if either there was a previous toggle just a few microseconds ago, or another one comes in a few microseconds, not much air is moved. But I think trying to model this would require delaying the sound by up to a millisecond, which would be more of a nuisance than it's worth, because people very seldom manipulated the volume intentionally.
Really, I wasn't serious about calling this a "bug"; I don't expect a simulator to reproduce it. It would be too much work for too few noticeable results. I'd much rather see some other new feature, like a scalable window size.
On Wed, Mar 23, 2022 at 7:08 AM Andrea @.***> wrote:
The distance in time between the clicks determines the frequency of the note produced, but the distance in time between the references determines the volume.
Interesting. https://archive.org/details/sim_nibble_1984-11_5_11
From a wave point of view, I always thought that the clicks just generate a square wave, but it is clearly more complicated than this.
I was trying to read, but failed to get a clear picture. Have you thought how you would turn an array of times where the speaker is accessed into a wave?
Given an amplitude between 0 and 1, could we say the next amplitude as a function of the last 2 time intervals to be:
ampl = min(dt_0, df_1) / max(dt_0, dt_1)
?
— Reply to this email directly, view it on GitHub https://github.com/AppleWin/AppleWin/issues/579#issuecomment-1076241337, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVE7BHJIEGHZFDQ5UN5UPDVBL3TPANCNFSM4FSY672Q . You are receiving this because you authored the thread.Message ID: @.***>