How do games like Zelda, Metroid, Final Fantasy and Crystalis play "background" music while your character wanders around?
Do they do so with the square, triangle and noise channels or with DMC?
Is DMC typically used for one-off sounds, like getting hit by an enemy, or discharging an energy bolt from your sword?
Or is it better to avoid DMC entirely?
How much CPU time is typically required to keep a back-ground music track running (ie, keep the "buffer" if you will, saturated)?
Strategies for sound management.
Moderator: Moderators
Typically the sound engine is called once per frame, and will play the music that is supposed to play by writing to $4000-$400F APU registers.
Most games use all channels for sound FX and music (when there is a SFX the music is temporaly silented on that channel), but some games doesn't use all chanels to simplify code (typically Dragon Quest/Warrior only uses one square and triangle for music and one square and noise for SFX, it also uses the second square for title screen and ending. The same applies to Gradius).
Most games use all channels for sound FX and music (when there is a SFX the music is temporaly silented on that channel), but some games doesn't use all chanels to simplify code (typically Dragon Quest/Warrior only uses one square and triangle for music and one square and noise for SFX, it also uses the second square for title screen and ending. The same applies to Gradius).
Useless, lumbering half-wits don't scare us.
Re: Strategies for sound management.
There is no buffer. The APU plays waveforms without any CPU help; the CPU just needs to tell it to change parameters (frequency, volume, etc.). Most (all?) music drivers run at a regular rate, usually every frame. During that time, the playback code advance in the music sequence data as necessary and updates waveform parameters.clueless wrote:How much CPU time is typically required to keep a back-ground music track running (ie, keep the "buffer" if you will, saturated)?
Re: Strategies for sound management.
For you, the player, it may seem like it's all happening at the same time, but the program actually alternates between updating the game's state (read input, move characters, etc) and updating the music channels. The NES keeps outputting even when you are not doing anything related to sound, based on the last settings written to the sound registers.clueless wrote:How do games like Zelda, Metroid, Final Fantasy and Crystalis play "background" music while your character wanders around?
As Bregalad said, sound updates are usually performed once per frame, since there are 60 frames per second (NTSC) the sound channels are updated that many times. Between sound updates (when all other updates are performed), the NES just keeps outputting sound based on the last parameters you sent it.
Also, a sound effect isn't initialized at the exact moment the event that generated it happened (e.g. a monster starts blowing up). At that moment, the code will probably tell the music engine which sound effect must be played, but that won't happen until the music engine is executed again. A speed as high as 60 frames per second results in very short intervals between updates, short enough for us humans not to notice these small delays, and think it's all happening at once.
That is up to the programmer. Some will reserve channels exclusively for sound effects, but that might make the music sound too poor with just standard NES audio (no mappers). Because of that, sound effects usually steal some sound channels temporally from the music, and gives them back when they end. Pay attention and you will notice that in many games some instruments of the music simply stop when there are sound effects. We usually don't notice that because the sound effect seems more important, as it is related to something that's happening on the screen, while the music is just background.Is DMC typically used for one-off sounds, like getting hit by an enemy, or discharging an energy bolt from your sword?
Well, there are some problems with it, such as the corrupted controller reads discovered recently. It also seems to affect the timing of other operations, such as sprite DMA. I don't remember many games that used it during the main game. It's mostly used for drums, but so is the noise channel.Or is it better to avoid DMC entirely?
Like blargg said, there is no buffer. It will keep generating sound based on the last parameters written to it. Music only exists because the sound engines change those parameters in a timely fashion.How much CPU time is typically required to keep a back-ground music track running (ie, keep the "buffer" if you will, saturated)?
How much CPU time a sound engine uses varies a lot from one to another. It's the same as asking "how much time does the logic of a platformer take?", that's too vague. It greatly depends on how many features there are and how well optimized the code is.
Thanks for the 50,000 foot view, guys. 
One question: Tokumaru and Blargg both mentioned using DMC to play "drums". Do you guys literally mean the sound of the percussion instrument, or is "drums" an entire category of sounds?
In either case, why is DMC required? Is it that the regular sound channels can't modulate as fast as some drum beats (I'm guessing here)?
One question: Tokumaru and Blargg both mentioned using DMC to play "drums". Do you guys literally mean the sound of the percussion instrument, or is "drums" an entire category of sounds?
In either case, why is DMC required? Is it that the regular sound channels can't modulate as fast as some drum beats (I'm guessing here)?
DMC will play any digitized sound you throw at it. Give it a recording of a drum and it will play it. It's how those baseball games on the NES yell out "Strike!" and "Ball!".
Of course, first the sound gets converted to 1-bit, and gets sampled at a much lower rate.
Of course, first the sound gets converted to 1-bit, and gets sampled at a much lower rate.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Percussion, yes.clueless wrote:Do you guys literally mean the sound of the percussion instrument
It's not a matter of speed, it's just that using the noise channel may not sound as realistic as actual drums. The noise channel produces basically a hissing sound, but if it starts suddenly with a high volume and then slowly fades away, it sounds close to a drum beat.In either case, why is DMC required? Is it that the regular sound channels can't modulate as fast as some drum beats (I'm guessing here)?
Thanks.Dwedit wrote:DMC will play any digitized sound you throw at it. Give it a recording of a drum and it will play it. It's how those baseball games on the NES yell out "Strike!" and "Ball!".
Of course, first the sound gets converted to 1-bit, and gets sampled at a much lower rate.
Did you write this? (Who is David de Regt. ?)
http://nesdev.com/wav2nes.zip
or this one? http://nesdev.com/81v2.zip
Or you can use a combination of the triangle and noise channels to create a fairly realistic drum sound. I'm not sure exactly how it's done, but the Kiwi Kraze soundtrack provides pretty good examples of the technique.tokumaru wrote:It's not a matter of speed, it's just that using the noise channel may not sound as realistic as actual drums. The noise channel produces basically a hissing sound, but if it starts suddenly with a high volume and then slowly fades away, it sounds close to a drum beat.
- BMF
RuSteD LOgIc
RuSteD LOgIc