Game sounds and game music question

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Crescendo2020
Posts: 8
Joined: Fri Jun 07, 2019 12:44 pm

Game sounds and game music question

Post by Crescendo2020 »

What are the limitations of the NES APU? For example, if you are using three channels for the music, will gameplay sounds take precedence over the music and temporarily silence one or more of the music channels? Also, do digitized sound effects like the ones in this video: https://m.youtube.com/watch?v=cpd87e2PJnE further limit music options? Thank you in advance.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: Game sounds and game music question

Post by Memblers »

Sound priority is determined by the sound engine, and there's a ton of ways to do that. Pently for example, I believe has instruments that work like sound effects (other than it being triggered by the music patterns obviously), so instruments can interrupt other instruments the same way a sound effect would.

Digitized audio does affect things, mostly memory layout and CPU time. That video has a mix of DPCM (Bayou Billy) and raw $4011 writes (Gauntlet, Skate or Die 2). $4011 is virtually unusable during gameplay, so I'll focus on DPCM.

DPCM is easy to do, it's a DMA thing so it automatically reads it from NES memory during playback, halting the CPU for some time. That matters if your CPU timing is critical, usually it's not. Unless you're running cycle-timed code. DPCM playback also affects the controller reading, it's pretty much a bug in the NES. There are work-arounds for it in the wiki, you have to use one or else you'll get phantom button presses.

But usually the biggest limitation is where to keep them in memory. You can bankswitch your CPU code/data all you want, but DPCM samples have to mapped into memory as long as the sample is playing. You can play more samples by bankswitching the sample memory as well, but I don't know if any of the exising sound engines are set up for that.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Game sounds and game music question

Post by koitsu »

It's entirely based on how the sound engine is programmed on a per-engine/per-game basis.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Game sounds and game music question

Post by tepples »

To expand on koitsu's "How long is a piece of string?"-esque answer, I'll give a cross-section of sound effect policies that an audio driver might implement.

Different drivers have different algorithms for one sound effect against another. I've seen these:
  1. Last wins: Sound effect played later always interrupts sound effect played earlier on same channel
  2. ID determines priority: Later sound effect wins if and only if it has a higher (or lower) number than the existing sound effect
  3. Length determines priority: Later sound effect wins if it is longer than the remaining portion of the earlier sound effect
Different drivers also differ in whether each sound effect is hardcoded to a particular channel. Triangle, noise, and DPCM are all qualitatively different, but for allocating sound effects to the two pulse channels, I've seen these:
  1. No pulse pool: Each sound effect is hardcoded to pulse 1 or pulse 2
  2. Pulse pool: A sound effect plays on pulse 1 unless pulse 1 is busy with a sound effect, in which case the sound effect may be moved to pulse 2
Different drivers have different algorithms for music against sound effects. I've seen these:
  1. Interrupt then wait for note: Sound effect always interrupts instrument, and once the sound effect ends, that music channel remains muted until the next note begins
  2. Interrupt: Sound effect always interrupts instrument, and that music channel resumes immediately once the sound effect ends, intending for illusory continuity of tones to mask the gap in the note
  3. Interrupt then fade in: Sound effect always interrupts instrument, and that music channel fades in over a few frames once the sound effect ends
  4. Volume priority: Each frame, the driver evaluates the sound effect and instrument on each channel and plays whatever is louder
I maintain a homebrew NES audio driver called Pently. It always uses "Length determines priority", but I know people have different opinions about some of these policies. So I added build-time configuration constants to switch between "Pulse pool" and not (PENTLY_USE_SQUARE_POOLING) and between "Volume priority" and "Interrupt" policies (PENTLY_USE_MUSIC_IF_LOUDER). Though the triangle channel doesn't have volume control, drivers using "Volume priority" can still use it to switch between, say, a kick drum and a bass note, keeping the kick drum enabled just a bit longer if a note isn't playing. (For more info on triangle kick drums, see video by explod2A03.)

Previous discussions about sound effect interruption:
Post Reply