Some NES audio questions
Moderator: Moderators
-
tomaitheous
- Posts: 592
- Joined: Thu Aug 28, 2008 1:17 am
- Contact:
Some NES audio questions
The length counter table on nesdevwiki is conflicting to Blargg's audio document. Which is correct?
Last edited by tomaitheous on Sat Aug 30, 2008 3:17 pm, edited 1 time in total.
I think they both match. The one on the wiki is in a more logical order:
Code: Select all
int table [32] = {
10,254, 20, 2, 40, 4, 80, 6, 160, 8, 60, 10, 14, 12, 26, 14,
12, 16, 24, 18, 48, 20, 96, 22, 192, 24, 72, 26, 16, 28, 32, 30
};
int length( int r4003 )
{
return table [r4003 >> 3 & 0x1F];
}-
tomaitheous
- Posts: 592
- Joined: Thu Aug 28, 2008 1:17 am
- Contact:
-
tomaitheous
- Posts: 592
- Joined: Thu Aug 28, 2008 1:17 am
- Contact:
That would make sense why some of the songs played fine but another parts would sound weird.tepples wrote:As I understand it, the length counter only determines when notes turn off. A lot of music engines don't even use the length counters, opting instead for pure software envelopes.tomaitheous wrote:I'm surprised that the music actually played correctly. Thank you
I changed the topic title instead of creating a new thread. It's been over a year since I did any code for the APU (or more specifically 'emulated' it) and I've seem to forgotten quite a bit. So I'll just post more audio specific questions in this thread.
Concerning the length counter halt flag, does enabling it mid count disable the channel sound(output) or just the counter and the sound keeps playing(infinitely)? I assume it's the latter, so does the volume envelope immediately kick in?
Also, if the counter is at 00 or the halt disable flag is set, and the game code clears the flag(or updates LLLLL) - when does the channel go active? On the next tick of the frame sequencer or immediately?
All the halt flag does is stop the length counter from decrementing when it's clocked. Whether or not the channel is silenced depends on the value of the counter itself (zero=silence, nonzero=active), the halt flag is irrelevent.tomaitheous wrote:Concerning the length counter halt flag, does enabling it mid count disable the channel sound(output) or just the counter and the sound keeps playing(infinitely)? I assume it's the latter
Clearing the halt flag (enabling length counting) just means the length counter will start counting down and silence the channel once it reaches zero.
The current output volume is always applied unless the length counter is zero (in which case output is forced to zero/silence)., so does the volume envelope immediately kick in?
The halt flag doesn't impact the counter's contents like this. It just prevents it from counting down. Whether or not the halt flag is set or clear... the channel becomes active and audible immediately after the next $4003/7 write (since that updates LLLLL, which reloads the length counter, making it nonzero)Also, if the counter is at 00 or the halt disable flag is set, and the game code clears the flag(or updates LLLLL) - when does the channel go active? On the next tick of the frame sequencer or immediately?
The only time the channel would remain silenced after a write to $4003/7 is if the channel is disabled via $4015 (or if the channel's output volume is 0)
-
tomaitheous
- Posts: 592
- Joined: Thu Aug 28, 2008 1:17 am
- Contact:
That clears up quite a bit. Many thanks 
In the document it mentioned that the length counter would be set to 00 if the halt flag was set. That was the part I was getting confused with. So it doesn't actually set the counter to 00 (and disabling sound), it just prevents the counter from decrementing. Got it
In the document it mentioned that the length counter would be set to 00 if the halt flag was set. That was the part I was getting confused with. So it doesn't actually set the counter to 00 (and disabling sound), it just prevents the counter from decrementing. Got it
Awesome. That simplifies some of the code then.the channel becomes active and audible immediately after the next $4003/7 write (since that updates LLLLL, which reloads the length counter, making it nonzero)