Sounds weird...

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
User avatar
hicks
Posts: 47
Joined: Fri Sep 29, 2017 10:39 am
Location: UK
Contact:

Sounds weird...

Postby hicks » Mon Nov 06, 2017 2:53 pm

Playing around with my Electron FPGA implementation a little and noticed some strangeness with the sound output.

The AUG says "FE06" is an 8 bit register that determines the output sound frequency, from 244Hz through to 62.5kHz. Formula used is 1MHz/(16*(S+1)) where S is 0 through 255. Testing this with values of S=0 and S=255:-

Code: Select all

  ?&FE07=&B0+2  ; sound mode
  ?&FE06=0


I get a 62.5kHz square wave output for 0 and a 244Hz square wave for S=255. That's just as the AUG suggests. However, whilst going through the user manual and trying out various test programs, I had a go at the sound section

Code: Select all

  SOUND 1,-15,52,100


52 according to the AUG should be middle c which is 261.63Hz. However the output is 529.80Hz. Trying with a value of 0 gives 247.10Hz and 255 gives 10.42kHz. This (pardon the pun :lol: ) sounds wrong.

I assume the AUG formula is correct. It seems so based on the schematics use of an 8 bit counter to toggle sndsrc flipflop and clocked @125kHz.

I expect I have a bug somewhere, but as poking the registers directly produces the exact frequency output the AUG suggests, it makes me wonder what is the BASIC "SOUND" command doing before a value is loaded into the register that would cause this change in frequency?
Last edited by hicks on Mon Nov 06, 2017 4:33 pm, edited 1 time in total.

User avatar
hoglet
Posts: 6634
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol

Re: Sounds weird...

Postby hoglet » Mon Nov 06, 2017 3:21 pm

I found to get the right tone (e.g. for ^G) you had to use the counter wrapping to toggle the sound output bit.

It would be interesting to see if the schematics show this or not.

Dave

User avatar
hicks
Posts: 47
Joined: Fri Sep 29, 2017 10:39 am
Location: UK
Contact:

Re: Sounds weird...

Postby hicks » Mon Nov 06, 2017 3:38 pm

That's what sheet 4 shows I believe. Counter wraps from 0 and the wrap cascades through causing a toggle of SNDSRC and also causing an async reset (in effect loading the counter with the reg'd value, which due to nor gate & reset use looks to only work correctly when the counter has wrapped to all 1's).

If I've read the schematics correctly and you load FE06 with 0. It should in effect get a tick @ 125kHz which will cause it to wrap to 255, toggle the SNDSRC and immediately cause a reset of the counter back to 0, which occurs before the next tick, so every tick causes a SNDSRC toggle, producing in effect the 62.5kHz maximum frequency the AUG notes.

That's also how my implementation works too. However, using SOUND with values in the 0..255 range produce wildly different results to poking at the register itself and I'm at a bit of a loss as to explain why.

Do you hear similar sound tones using SOUND with 0 and 255 as you would loading the register directly with 0 and 255 (the two might be reversed)?

On another _note_ (pun intended :lol: ) if you look at the frequencies for middle C on this page The B below middle C is 246Hz which is close to the lower limit the AUG notes the electron can produce, 244Hz. Yet Page 118 of the user guide has a whole octave of notes below what they highlight as middle C "52". That doesn't make sense does it?

If "4" is actually middle C, then I guess that would tally up with what I'm seeing in my implementation, but then my audio sounds quite different to the youtube videos I've listened to. As though it's nearly an octave too high.
Last edited by hicks on Mon Nov 06, 2017 3:46 pm, edited 1 time in total.

crj
Posts: 329
Joined: Thu May 02, 2013 4:58 pm

Re: Sounds weird...

Postby crj » Mon Nov 06, 2017 3:44 pm

hicks wrote:it makes me wonder what is the BASIC "SOUND" command doing before a value is loaded into the register that would cause this change in frequency?

Well, SOUND (OSWORD 7) takes a pitch in semitones. The sound generator IC takes a frequency divisor. The fact that this entails a logarithmic scaling is a clue that SOUND must be doing something. (-8

Sure enough, a quick foray into the OS1.20 ROM reveals translation code at &ED16. It seems to be doing a complicated trick where it strips the bottom two bits (rounds to nearest semitone), divides by 12, looks up the remaineder to determine the correct frequency coefficient for semitone-within-octave, then scales it by octave number. I'm not quite sure why it's doing that when at first sight a simple 64-entry lookup table would be compact and way more efficient, but hey.

User avatar
hicks
Posts: 47
Joined: Fri Sep 29, 2017 10:39 am
Location: UK
Contact:

Re: Sounds weird...

Postby hicks » Mon Nov 06, 2017 3:49 pm

crj wrote:Well, SOUND (OSWORD 7) takes a pitch in semitones. The sound generator IC takes a frequency divisor. The fact that this entails a logarithmic scaling is a clue that SOUND must be doing something. (-8


Isn't that for the BBC though? The Electron appears to work different? Although I assume SOUND is doing something on the Electron too.

crj
Posts: 329
Joined: Thu May 02, 2013 4:58 pm

Re: Sounds weird...

Postby crj » Mon Nov 06, 2017 3:51 pm

hicks wrote:Isn't that for the BBC though? The Electron appears to work different?


Well, yes.

In my defence, you didn't actually say you were asking about the Electron! :-p

User avatar
hicks
Posts: 47
Joined: Fri Sep 29, 2017 10:39 am
Location: UK
Contact:

Re: Sounds weird...

Postby hicks » Mon Nov 06, 2017 4:32 pm

crj wrote:
hicks wrote:Isn't that for the BBC though? The Electron appears to work different?


Well, yes.

In my defence, you didn't actually say you were asking about the Electron! :-p


I expect mind reading :D

Edited original post to mention Electron.

User avatar
hicks
Posts: 47
Joined: Fri Sep 29, 2017 10:39 am
Location: UK
Contact:

Re: Sounds weird...

Postby hicks » Thu Nov 16, 2017 11:50 am

I've finally managed to buy an Electron off ebay and hooked it up to the scope to see what a real Electron produces for sound vs my FPGA to get to the bottom of this and, well, the results are unexpected.

Based on schematics and reading of the AUG I expected a 244Hz to 62.5kHz range which is what my core is currently producing. However, using

Code: Select all

?&FE07=&B0+2
?&FE06=255


My FPGA outputs 244Hz whilst the Electron outputs 122Hz. Likewise using SOUND the Electron is 1/2 that of the FPGA.

That explains why my pitch sounds like it was higher. So, it looks like the AUG is incorrect as regards the output range of the Electron which is 123Hz through 31.25kHz and not 244Hz through 62.5kHz and it also means either the schematics are wrong or I've misread them. I'm leaning towards perhaps they're out of date :mrgreen: as there is a flipflop CNTB[9] and the one near SNDSRC that both appear to toggle together on the schematics, perhaps CNT9 is really meant to be an extra div by 2 stage?

Anyhow, lots of text so here's a image to show off my not so new Electron. Yellow trace is the Electron speaker output and Blue is my FPGA. Ignore the excess noise on the Electrons I've used some jumper cables to save holding the probe where as the FPGA is using a tiny coil to gnd.

elk-vs-fpga-sound.jpg

User avatar
1024MAK
Posts: 6799
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...

Re: Sounds weird...

Postby 1024MAK » Thu Nov 16, 2017 4:19 pm

I thought that was a weird audio range. Given that human hearing tops out at around 20kHz to 22kHz (assuming you are young), why would they have a system that went as high as 62.5kHz?

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

User avatar
1024MAK
Posts: 6799
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...

Re: Sounds weird...

Postby 1024MAK » Thu Nov 16, 2017 4:23 pm

As an aside, the test file on this web site allows you to check your upper hearing limit. Well, assuming your playback device has a good audio system...

I could just about hear the 15kHz on an iPad mini.

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

Kazzie
Posts: 21
Joined: Sun Oct 15, 2017 7:10 pm
Location: North Wales

Re: Sounds weird...

Postby Kazzie » Fri Nov 17, 2017 9:00 am

1024MAK wrote:I thought that was a weird audio range. Given that human hearing tops out at around 20kHz to 22kHz (assuming you are young), why would they have a system that went as high as 62.5kHz?

Mark


In order to make an electron-based dog whistle, perhaps?
Pudsey - BBC Model B 32k issue 7, Sidewise ROM board with 16K RAM


Return to “hardware”

Who is online

Users browsing this forum: nama and 12 guests