How are SFX played over music?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
tesserex
Posts: 6
Joined: Mon Feb 19, 2024 3:05 pm

How are SFX played over music?

Post by tesserex »

Now that I have a working nsf player, I realized my next problem. There are separate tracks for sound effects but I don't know how to play them.

One way I can think of is to prerender them into a buffer on load, and then on playback just overwrite the music buffer with the non-zero sfx channels. It seems reasonably simple, but it can't be "correct" can it? I'm guessing this problem is unique to NSFs. The hardware or an emulator just says what to send to the APU, and doesn't care about thing like song tracks being loaded, right?
User avatar
Dwedit
Posts: 4922
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: How are SFX played over music?

Post by Dwedit »

I haven't tried it yet, but what happens if you call Init (specifying sound effect number) without clearing the state first?
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
tesserex
Posts: 6
Joined: Mon Feb 19, 2024 3:05 pm

Re: How are SFX played over music?

Post by tesserex »

I don't think that would work - that's basically the entire process of changing tracks. The whole nsf data is loaded into memory up front so it would just play the sound effect alone.
User avatar
TakuikaNinja
Posts: 87
Joined: Mon Jan 09, 2023 6:42 pm
Location: New Zealand
Contact:

Re: How are SFX played over music?

Post by TakuikaNinja »

I'm not sure what you're trying to do here. The NSF format has no notion of SFX interrupting playback. Rips with SFX just assign them to unique tracks and expect that players will completely reset their internal state before playing them. If this is for playing music and SFX in NES software/games, then you'd want to use a game-ready sound engine implementation instead of an NSF player.
User avatar
Dwedit
Posts: 4922
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: How are SFX played over music?

Post by Dwedit »

Just tested out Megaman 4's NSF. Init is 8003 and play is 8000. If you call Init with a sound effect number while the music is playing, it will play a sound effect while continuing to play the music.

It works in some games, but not others.

Some NSFs use a track replacement lookup table at the beginning of Init, you'll have to remove that code from such NSFs.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
tesserex
Posts: 6
Joined: Mon Feb 19, 2024 3:05 pm

Re: How are SFX played over music?

Post by tesserex »

Dwedit wrote: Fri Feb 23, 2024 12:40 am Just tested out Megaman 4's NSF. Init is 8003 and play is 8000. If you call Init with a sound effect number while the music is playing, it will play a sound effect while continuing to play the music.

It works in some games, but not others.

Some NSFs use a track replacement lookup table at the beginning of Init, you'll have to remove that code from such NSFs.
Wow, that's... impressive. Just tried it for Mega Man 5, and it works. Thanks! Now I just need to figure out how to stop continuous effects (like charging the buster). Maybe re-initializing with a bad number? Or with the music track number?
User avatar
Dwedit
Posts: 4922
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: How are SFX played over music?

Post by Dwedit »

I assume you just play another sound effect to stop the charge sound?

Playing song F0 is used by Mega Man 5 to stop music.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
tesserex
Posts: 6
Joined: Mon Feb 19, 2024 3:05 pm

Re: How are SFX played over music?

Post by tesserex »

Thanks, I wondered if it might be that since I can't recall a sound effect ever just stopping on its own, but I wasn't sure because other players seem to have a "StopSfx" feature. Maybe that's all they do.
Post Reply