Using SPC for music and sound effects in non-SNES game

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
metasprite
Posts: 3
Joined: Thu Apr 29, 2021 7:45 am

Using SPC for music and sound effects in non-SNES game

Post by metasprite »

I'm re-implementing the Mega Man X engine in C++ and focusing on accuracy. I want to use SPC for music and sound effects, because it provides automatic looping, the ability for the player to customize sound interpolation, keeps filesize low, and most importantly it sounds 100% accurate to the original game.

I've ripped some sound effects from Mega Man X as SPC files. I want to do it exactly how the game would do it - override a specific channel for a bit while a sound effect SPC plays, then give that channel back to the music once it's done. The problem is that Blargg's SPC library only lets me load and play a single SPC at once. The library's API doesn't provide a way to "blend" SPC files together (for example by sending different data to individual channels) - but that's what the game itself does, no? So it must be possible.

Basically all I want to do is take two SPCs, send data from one SPC to channels X and Y, and the other SPC's data to the rest of the channels. How would I accomplish this?

Would the ideal method be to try to interact with the Blargg emulated APU (DSP?) byte-by-byte from my program as if I were an SNES game, or to try and edit Blargg's source code and add a blending feature (probably incredibly difficult)?
93143
Posts: 1717
Joined: Fri Jul 04, 2014 9:31 pm

Re: Using SPC for music and sound effects in non-SNES game

Post by 93143 »

An SPC isn't a sound file. It's a machine state snapshot of the SNES APU, which includes its own CPU and runs code written by the developer. Normally (there are exceptions), games use the I/O ports to communicate events, like sound effects, and then the audio engine in the APU handles the details. There is no one standard set of control codes and no single standard for how to handle them; all that was up to the programmer. (This is why loading an SPC on real hardware requires crazy trickery involving running code directly on the I/O ports; there's no guarantee the fully booted audio engine even has a method for loading data, never mind one that respects a particular standard, and you have to load every byte of RAM in order to guarantee the image will work.)

If you've got a black box SNES APU emulation up and running, it should be a simple matter to emulate the I/O ports and send the instructions expected by Capcom's sound engine. Judging by how bad Street Fighter Alpha 2 is at loading data on the fly, I suspect previous Capcom games didn't do much of it, so the sound effect samples are probably already in any given SPC dump. If not, well... have fun.
metasprite
Posts: 3
Joined: Thu Apr 29, 2021 7:45 am

Re: Using SPC for music and sound effects in non-SNES game

Post by metasprite »

93143 wrote: Thu Apr 29, 2021 7:57 pm If you've got a black box SNES APU emulation up and running, it should be a simple matter to emulate the I/O ports and send the instructions expected by Capcom's sound engine.
I'll probably end up trying to do that, then. Now my only question is how would I go about finding those control codes I need to send to the I/O ports? What debugging tool or method to use? I found only one APU debugger through Google, and it's just a channels view and interpolation settings.
93143
Posts: 1717
Joined: Fri Jul 04, 2014 9:31 pm

Re: Using SPC for music and sound effects in non-SNES game

Post by 93143 »

A SNES emulator with debugging features should allow you to see what it does to the I/O ports, and may also allow you to debug APU-side code.

Also note that I cannot advise you on legal issues; the fact that I have engaged with your questions is not intended to imply that your project is safe from lawyers.
metasprite
Posts: 3
Joined: Thu Apr 29, 2021 7:45 am

Re: Using SPC for music and sound effects in non-SNES game

Post by metasprite »

93143 wrote: Thu Apr 29, 2021 9:47 pm A SNES emulator with debugging features should allow you to see what it does to the I/O ports, and may also allow you to debug APU-side code.

Also note that I cannot advise you on legal issues; the fact that I have engaged with your questions is not intended to imply that your project is safe from lawyers.
My internet went out last night so I couldn't thank you... so thank you for the help. I used the bsnes-plus debugger to monitor the I/O ports, and now I've got it working perfectly. All the game does to play a sound effect is send the ID to APU port 0, super easy to do the same thing with Blargg's API.
Post Reply