It is currently Fri Nov 17, 2017 2:09 pm

All times are UTC - 7 hours



Forum rules


Related:



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Jul 14, 2015 6:58 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19220
Location: NE Indiana, USA (NTSC)
I'm porting my NES music engine to the Super NES, and I'm trying to determine whether to delay all key-on events for one "frame" of the music engine. Fullsnes states that keying off a channel causes its envelope volume to decrease at 8 units per sample. Full scale is 2047 units, so a fade from full scale would take 256 samples, or 256 / 32 = 8 ms, or 256 * 32 = 8192 CPU cycles. Can undefined or undesirable behavior happen if I prepare the channel for the next note (volume, frequency, sample ID, and envelope) before this fade completes? Do any commercial games' music engines suffer from artifacts related to this, or is there some common workaround that they use?


Top
 Profile  
 
PostPosted: Tue Jul 14, 2015 2:14 pm 
Offline

Joined: Mon Sep 27, 2004 2:57 pm
Posts: 1248
It seems like it's a really quick fade-out (like, so quick as to be imperceivable) as a means of preventing clicking or popping when you want to silence the note, which would happen sometimes if the note were just clamped off (similar to what happens if you silence the NES's triangle channel by setting the period to 0 instead of properly halting it).

I don't think anything bad would happen if you didn't have a delay between key-off and key-on, but you'd risk the aforementioned popping as one waveform suddenly ends and jumps to another waveform. I think that's why so many music engines add a small space between each note.


Top
 Profile  
 
PostPosted: Wed Jul 15, 2015 7:47 am 
Offline

Joined: Wed Jul 09, 2008 8:46 pm
Posts: 238
Here's my understanding from here:

http://problemkaputt.de/fullsnes.htm#sn ... lregisters

The interesting thing is that you're most likely not going to get any artifacts because the envelopes go to zero regardless of ADSR and gain settings.

The SPC700 is more prone to your usual clicks and pops than usual because of a 5 sample delay between when a sample gets cut (and thus zeroed out) and when a sample starts playing again after calling KON. If you forget to turn off your KOFF and write to KON, you have 63 cycles to get rid of the KOFF for that channel.

An alternative to KOFF is to use gain to zero out the sample. When ADSR is set to use gain and the gain is set to linear decrease and its setting is maxed out at 31, you get a 64 sample fade-out (that's 2048 CPU cycles, in comparison to 8192 CPU cycles with key off).

I know SNESMod takes advantage of a 5 sample headstart after KON (that's 160 cycles) to set up volume and gain and doesn't set KOFF beforehand.

Actually, maybe you should try some other kind of magic for your NES to SNES engine. Those lovely square waveforms and triangle waves should only simply need their pitch values (and gain if you're manipulating volume) changed (unless you're emulating phase reset). When changing pulse widths, with the right kind of BRR magic, you can simply change the sample ID without keying on and off and with a small delay (mainly because the loop point has to actually trigger), you'll change the waveform without bothering with key on and off (unless your waveform was never keyed on in the first place). This works well thanks to the fact you're using chip waveforms.


Top
 Profile  
 
PostPosted: Wed Jul 15, 2015 8:06 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19220
Location: NE Indiana, USA (NTSC)
KungFuFurby wrote:
When changing pulse widths, with the right kind of BRR magic, you can simply change the sample ID without keying on and off and with a small delay (mainly because the loop point has to actually trigger), you'll change the waveform without bothering with key on and off (unless your waveform was never keyed on in the first place). This works well thanks to the fact you're using chip waveforms.

Interesting idea. I have already 32-sample 1/8, 1/4, and 1/2 duty pulse and 64-sample triangle wave loops as default samples usable by instruments and sound effects. But to make it sound less like a TurboGrafx or Virtual Boy and more like a Super NES, I'm also planning to support actual sampled (or pre-synthesized) BRRs, for which the 8 ms fadeout will be far more critical. So I guess the way to do it is to run the music engine, trigger KOFF immediately for any channel needing it, and wait until the next time I run the music engine before poking in the new values and triggering KON.

Does stopping a wave by setting its playback rate to 0 Hz ($x2 = 0 and $x3 = 0) work? If so, that'd be the direct S-DSP equivalent to shutting off an NES APU triangle wave.


Top
 Profile  
 
PostPosted: Wed Jul 15, 2015 8:10 am 
Offline

Joined: Wed Jul 09, 2008 8:46 pm
Posts: 238
Alright, that will do the trick then.

Yeah, I think that would work for the triangle wave by setting the pitch to zero.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot], ThunderZ and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group