Hydr8gon/sodium64

SPC700 DSP implementation (sound)

Opened this issue · 6 comments

Hello, I just learned about this repository today and I must say this is pretty amazing. Never did I think SNES emulation would be possible on the N64. I was checking the repository and it seems that there's SPC700 CPU emulation code in place already, as someone who has worked with this chip before and I have a lot of knowledge on how the assembly for it works (and could provide test roms for it) how hard (if possible, considering the cpu isn't being already fully taxed by the emulation) would it be to implement the DSP chip for audio output?

I'd love to help with this but my knowledge of R4300 assembly is limited. I can give some information (and sample code in C for sound output and a testing ROM) on how the DSP works though if it can be implemented more easily.

The DSP uses a 128-byte ram buffer that can be written to utilizing the F2/F3 control registers on the SPC side, as such:
mov $f2, #$10 «- set DSPwrite to 0x10 (so DSPRam[0x10])
mov $f3, #$20 «- value to write, F3 can also be read from to get the value of that DSP. This would write 0x20 to DSPRam[0x10] which is Right Channel volume for channel 1.

Hi, thanks for your interest in the project! I've actually been implementing the APU over just the past couple weeks, so I haven't gotten to the DSP yet. I've emulated audio for a few different systems already, so I should be able to figure out this one too. My main concern is performance, since after recent additions the CPU emulation is now becoming more of a bottleneck than the graphics emulation. I have some ideas for optimization though, so hopefully I can still squeeze audio emulation in somewhere :P

Thanks for the response! Audio output should be fairly easy considering what you are doing. Is there a way to get audio running on the RSP instead of the normal CPU? as far as I know, audio can be done on the RSP too. I don't think every single DSP feature (echo, modulation, fir) needs to be exactly implemented as-is as games work exactly fine without it and it's just related to audio output. I would not mind the lower audio quality if it helps it run better.

For a DSP emulation you'll at worst be doing a loop for the 8 channels and their variables and mixing it together. The DSP is actually simpler than you think (I think the most complicated part is decoding the samples. They are stored in a weird 4-bit format that uses interpolation)

https://wiki.superfamicom.org/spc700-reference

I'm not sure if Libdragon has threading or interrupts yet (assuming that's what you are using) so I don't know if DSP could run alongside the CPU in a interrupt or something. I would love to get in contact with you to implement this feature.

The RSP is already handling graphics, and it's quite slow even with only basic features implemented. The vector operations would be useful for audio processing, but I'm actually leaning towards doing it on the CPU because I think there are easier optimizations that can be done there to squeeze it in. Either way, performance is the main issue.

I have a Discord server if you want to chat more casually: https://discord.gg/JbNz7y4

Thank you. I have joined the discord server. I got a test ROM with spc code booting but it appears to hang the moment the SNES tries to communicate with the SPC.