Sampled sound on the sn76489 -- tests

discuss bbc micro and electron emulators (including mame) here!
User avatar
simonm
Posts: 316
Joined: Mon May 09, 2016 3:40 pm
Contact:

Re: Sampled sound on the sn76489 -- tests

Post by simonm » Tue Jul 30, 2019 12:27 am

That's great work Tom. Seems as long as the WE bit is in a known state, data can be pumped to the SN chip as fast as it can handle it. =D>

User avatar
scarybeasts
Posts: 559
Joined: Tue Feb 06, 2018 7:44 am
Contact:

Re: Sampled sound on the sn76489 -- tests

Post by scarybeasts » Tue Jul 30, 2019 10:54 am

simonm wrote:
Tue Jul 30, 2019 12:27 am
That's great work Tom. Seems as long as the WE bit is in a known state, data can be pumped to the SN chip as fast as it can handle it. =D>
Yeah, I'm pretty excited by this. That's a decent CPU cycle budget to throw different samples (or different rates) to all 3 tone channels. Or synthesize SID-like sounds (triangle waves, modulated width square waves). Pretty sure you could play some high quality monster tunes that sound better than anything previously attempted :)


Cheers
Chris

tom_seddon
Posts: 426
Joined: Tue Aug 30, 2005 12:42 am
Contact:

Re: Sampled sound on the sn76489 -- tests

Post by tom_seddon » Tue Jul 30, 2019 10:46 pm

Rich Talbot-Watkins wrote:
Mon Jul 29, 2019 1:08 pm
  • Attenuation happens as a final stage, clocked at the final pitch frequency, so I would assume that volume changes only take place at the start of a new tone cycle rather than immediately.
I was wondering about how to test this one. My attempt is attached. It sets tone 0 to play the lowest note possible (~122 Hz), and then goes into a loop toggling tone 0 volume between 0/15 at ~4 KHz. My thinking is that the result would only appear to be higher pitched-sounding if volume changes take place immediately - and a higher pitched sound is indeed audible, suggesting they do take place immediately.

(I also hear a lower pitched sound, which I assume is due to the 122 Hz repeating pattern of 4KHz/silence.)

I'm not super confident that my reasoning here is correct though...

--Tom

Code: Select all

10REM>WE0-VOLUME
20IFPAGE<&E00:PRINT"I/O PROCESSOR ONLY":STOP
30MODE7:CODE%=&4000:HIMEM=CODE%
40*KEY10OLD|M
50pitch%=1024
60FORPASS%=0TO3STEP3:P%=CODE%:[OPTPASS%
70.start
80sei
90lda#255
100sta&FE43\ddra
110sta&FE42\ddrb
120lda#FNvol(0,15):jsrwrite
130lda#FNvol(1,0):jsrwrite
140lda#FNvol(2,0):jsrwrite
150lda#FNvol(3,0):jsrwrite
160lda#FNfreql(0,pitch%):jsrwrite
170lda#FNfreqh(pitch%):jsrwrite
180:
190lda#0:sta&FE40\~WE=0
200:
210.loop
220lda#FNvol(0,0):sta&FE4F:jsrwait256
230bit&70
240lda#FNvol(0,15):sta&FE4F:jsrwait256
250jmploop
260:
270.wait256:jsrwait128
280.wait128:jsrwait64
290.wait64:jsrwait32
300.wait32:jsrwait16
310.wait16:nop:nop:jsrwait12
320.wait12:rts
330:
340.write
350sta&FE4F
360lda#0:sta&FE40\~WE=0
370nop:nop:nop:nop
380nop:nop:nop:nop
390lda#8:sta&FE40\~WE=1
400rts
410:
420]NEXT
430CALLstart
440END
450:
460DEFPROCCHECKCHANNEL(C%)
470IFC%<0ORC%>3:STOP
480ENDPROC
490:
500DEFPROCCHECKPITCH(V%)
510IFV%<1ORV%>1024:STOP
520ENDPROC
530:
540DEFFNvol(C%,V%)
550PROCCHECKCHANNEL(C%)
560IFV%<0ORV%>15:STOP
570=&80OR(C%*32)OR&10OR(V%EOR15)
580:
590DEFFNfreql(C%,V%)
600PROCCHECKCHANNEL(C%)
610PROCCHECKPITCH(V%)
620=&80OR(C%*32)OR(V%AND15)
630:
640DEFFNfreqh(V%)
650PROCCHECKPITCH(V%)
660=(V%AND1023)DIV16

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

Re: Sampled sound on the sn76489 -- tests

Post by Rich Talbot-Watkins » Wed Jul 31, 2019 8:33 am

Yes, that seems like a good test.

Compare: 100Hz square wave:
sw.PNG
sw.PNG (10.71 KiB) Viewed 705 times
https://vocaroo.com/i/s1i1suYc5YVS

100Hz square wave modulated with 600Hz square wave:
swmod.PNG
swmod.PNG (11.92 KiB) Viewed 705 times
https://vocaroo.com/i/s1fAQmpWsWCc

In the modulated tone, I can hear two dominant pitches, although these aren't necessarily the same as what you'd get by simply adding two harmonics.

cmorley
Posts: 1319
Joined: Sat Jul 30, 2016 8:11 pm
Location: Oxford
Contact:

Re: Sampled sound on the sn76489 -- tests

Post by cmorley » Thu Aug 01, 2019 9:32 am

tom_seddon wrote:
Tue Jul 30, 2019 10:46 pm
I was wondering about how to test this one. My attempt is attached. It sets tone 0 to play the lowest note possible (~122 Hz), and then goes into a loop toggling tone 0 volume between 0/15 at ~4 KHz. My thinking is that the result would only appear to be higher pitched-sounding if volume changes take place immediately - and a higher pitched sound is indeed audible, suggesting they do take place immediately.

(I also hear a lower pitched sound, which I assume is due to the 122 Hz repeating pattern of 4KHz/silence.)

I'm not super confident that my reasoning here is correct though...
If you mod your example to use a freq of 1 then you do get a nice tone.

However I tried leaving the WE open with my Bad Apple version and it doesn't work if you use more than one tone channel it seems. I use 2 to get slightly better bit resolution and volume out of it and all I could get with 2 channels leaving WE open was horrid crunching and/or tone artefacts. (One channel plays as expected)

I am not sure what happens and didn't investigate further. You could add a second tone at half the frequency simply enough in your test program and see what happens.

Chris

User avatar
tricky
Posts: 4675
Joined: Tue Jun 21, 2011 9:25 am
Contact:

Re: Sampled sound on the sn76489 -- tests

Post by tricky » Sun Aug 25, 2019 7:59 am

I was tweaking the sound code in the version of beebem that I use and realised that I don't know much about the noise channel counter.
I suspect that the least gates option is probably what they did!

A. have a 6 bit counter for noise, and when linked to the tone channel, clock the LFSR when the tone counter resets.

B. have a 10 bit counter for noise, like the tone channels and when it resets, use the value latched in the tone channel.

I also don't know if the tone channel counter resets when its frequency is set, not just the LFSR, but probably not if it is the 6 bit counter.

I doubt that the difference could be heard, but these things annoy me ;)

Post Reply

Return to “8-bit acorn emulators”