Beeb SOUND weirdness

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
User avatar
ctr
Posts: 163
Joined: Wed Jul 16, 2014 2:53 pm
Contact:

Beeb SOUND weirdness

Post by ctr » Sun Aug 05, 2018 5:02 pm

When I play the same note on two different channels I get two different pitches.

I've tried this on beebem, b-em and b2 with consistent results but not a real beeb. Can anyone reproduce it? It's surprising that these emulators all do this, but I'd also be surprised if a real beeb worked like this.

The following code switches between two notes that should be the same pitch, but they are not:

Code: Select all

   10REPEAT
   20SOUND&11,-15,150,11
   30K%=INKEY(50)  
   40SOUND&12,-15,150,11
   50K%=INKEY(50)
   60UNTILFALSE
If you change line 40 to use a pitch of 151 instead of 150 then they do sound the same.

Edited to add ssd.
Attachments
pitch.ssd
(1 KiB) Downloaded 4 times
Last edited by ctr on Sun Aug 05, 2018 5:12 pm, edited 1 time in total.

User avatar
BigEd
Posts: 2056
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Beeb SOUND weirdness

Post by BigEd » Sun Aug 05, 2018 6:14 pm

I think I read recently in another thread that the MOS detunes one note if you play the same pitch on different channels, so you get a fatter sound. JSBeeb is doing the same thing as the others, I think.

User avatar
ctr
Posts: 163
Joined: Wed Jul 16, 2014 2:53 pm
Contact:

Re: Beeb SOUND weirdness

Post by ctr » Sun Aug 05, 2018 10:30 pm

Cheers, with this clue I went looking in the MOS.

Having calculated the 10-bit frequency period value to write to the chip (in &83D and &83E) the code at &ED6F adds in a constant channel fudge factor from a lookup table at &C441. (Confusingly, the channel number is represented by a value in X between 4 and 7.) This is 0 for channels 0 and 1, 1 for channel 2 and 2 for channel 3.

In the region of middle C an offset of 1 is about 1/26 of a semitone. At higher frequencies it's closer to a quarter of a semitone (which is the unit of pitch in the SOUND statement), so 150 on channel 1 does produce the same output as 151 on channel 2.
Last edited by ctr on Tue Aug 07, 2018 10:37 pm, edited 1 time in total.

User avatar
BigEd
Posts: 2056
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Beeb SOUND weirdness

Post by BigEd » Mon Aug 06, 2018 6:42 am

Good digging! (I tried to find where I'd got the info from, and failed.)

I think this finding reinforces the idea that this kind of sound chip isn't especially musical, and hints at why Bob Yannes was able to do better, with the SID.

User avatar
Rich Talbot-Watkins
Posts: 1334
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Beeb SOUND weirdness

Post by Rich Talbot-Watkins » Mon Aug 06, 2018 10:30 am

What a peculiar feature! And, as you say, pretty terrible too, if it doesn't scale with the frequency, so that higher notes are detuned more than lower ones. I think that's an OS 1.20 misfire (and they could've saved themselves some space by not doing that as well!).

User avatar
Rich Talbot-Watkins
Posts: 1334
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Beeb SOUND weirdness

Post by Rich Talbot-Watkins » Mon Aug 06, 2018 11:05 am

BigEd wrote:
Mon Aug 06, 2018 6:42 am
Good digging! (I tried to find where I'd got the info from, and failed.)
I'd be interested to know where this observation was first made. It is documented in that famous OS 1.20 disassembly, in as much as the lookup table's purpose is correctly described, although the code which uses it makes no comments as to what it's doing.
BigEd wrote:
Mon Aug 06, 2018 6:42 am
I think this finding reinforces the idea that this kind of sound chip isn't especially musical, and hints at why Bob Yannes was able to do better, with the SID.
I think the SN76489 is a fairly capable chip (for its time), and was certainly able to hold a tune well - the Sega Master System used this exact chip, for example. However, on the Beeb, it's clocked too high, which means that it's not able to reproduce low pitches well and ends up sounding a bit like a musical box half the time. If it had been clocked at half the speed it would've sounded better (although it would also have been twice as slow to access).

There were certainly worse sound chips in that era, e.g. the AY 8910 that the Oric, Spectrum 128, CPC and others used, which only had 3 channels. But the SID blew them both out of the water of course. And my very favourite sound chips of the era were the Yamaha FM chips, particularly the later ones which were programmable rather than just playing back presets, like in the Sega Megadrive. I actually even prefer the sound of FM synthesis to more contemporary PCM based techniques.

User avatar
Richard Russell
Posts: 443
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Beeb SOUND weirdness

Post by Richard Russell » Mon Aug 06, 2018 2:09 pm

Rich Talbot-Watkins wrote:
Mon Aug 06, 2018 11:05 am
There were certainly worse sound chips in that era, e.g. the AY 8910 that the Oric, Spectrum 128, CPC and others used, which only had 3 channels.
In BBC BASIC for Windows and BBC BASIC for SDL 2.0 I've incorporated the option of reconfiguring SOUND channel 0 as a fourth 'tone' channel rather than a noise channel. I find that very helpful, especially as there's a lot of four-voice music around but not so much three-voice, and working out which one to drop requires musical experience! Here's a four-voice example supplied with BBCSDL (it runs equally well in Windows, Linux, Mac OS, Raspberry Pi, Android and iOS). Blatant off-topic plug! :evil:

Richard.

User avatar
Rich Talbot-Watkins
Posts: 1334
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca
Contact:

Re: Beeb SOUND weirdness

Post by Rich Talbot-Watkins » Mon Aug 06, 2018 4:18 pm

Sounds good. I'd probably have extended it all the way to support 16 channels - I mean, why not, right? I'd also extend ENVELOPE to allow for different waveforms and so on. When you're synthesising the sound yourself, there are no limits really!

hexwab
Posts: 32
Joined: Wed Jul 08, 2015 8:27 pm
Contact:

Re: Beeb SOUND weirdness

Post by hexwab » Tue Sep 18, 2018 4:14 am

Rich Talbot-Watkins wrote:
Mon Aug 06, 2018 10:30 am
What a peculiar feature! And, as you say, pretty terrible too, if it doesn't scale with the frequency, so that higher notes are detuned more than lower ones. I think that's an OS 1.20 misfire (and they could've saved themselves some space by not doing that as well!).
It is terrible, but there is some reasoning behind it. If you set two or more channels on the '76489 to the same frequency, the phase between them is entirely undefined, so you may end up with a loud note or complete silence or anywhere in between. I believe Acorn were keen to avoid this unexpected and counterintuitive behaviour, and keeping track of whether two channels were the same pitch was altogether too complicated and/or expensive when you consider corner cases such as starting a note on channel A, then starting the same note on channel B, stopping A, starting the same note on C etc.

AFAIK this behaviour is common to all OS versions (and is why you should always play your highest notes using channel 3 when using the OS's sound routines, as channel 3 has no detune).

User avatar
Richard Russell
Posts: 443
Joined: Sun Feb 27, 2011 10:35 am
Location: Downham Market, Norfolk
Contact:

Re: Beeb SOUND weirdness

Post by Richard Russell » Tue Sep 18, 2018 8:35 am

Rich Talbot-Watkins wrote:
Mon Aug 06, 2018 4:18 pm
Sounds good. I'd probably have extended it all the way to support 16 channels - I mean, why not, right?
Why not? Because it's synthesising a PCM waveform in real-time, which when 'BBC BASIC for Windows' was released (2001) was pushing what was possible with CPUs of the era. With four channels I just about managed to fit everything in the CPU's registers - a good example of hand-assembled code outperforming what any compiler can achieve - and even today the BB4W specification states that you need a processor clock speed of at least 133 MHz for SOUND to work!

For the geeks, here's an extract from the source code describing how each register was used (more modern versions, i.e. BBCSDL and BB4W's HQSOUND library, use SIMD instructions):

Code: Select all

;       (LOWORD) ecx = periodicity for channel 0 (&8018=white noise)
;       (HIWORD) ecx = pitch for channel 1 (0 or 745-29167)
;       (LOWORD) edx = pitch for channel 2 (0 or 745-29167)
;       (HIWORD) edx = pitch for channel 3 (0 or 745-29167)
;       (LOWORD) ebx = amplitude for channel 0 (0xNN00 0-127) 
;       (HIWORD) ebx = amplitude for channel 1 (0xNN00 0-127) 
;       (LOWORD) ebp = amplitude for channel 2 (0xNN00 0-127) 
;       (HIWORD) ebp = amplitude for channel 3 (0xNN00 0-127)
;       esi = waveforms for all channels
;       edi = address of PCM output buffer (>= 1764 bytes)

Post Reply