multichannel rendering

Issue #6 new
Tom M. created an issue

I would like to be able to render each voice to a distinct stereo buffer. Currently this doesnt seems to be easily possible?

As far as I understand, one would have to implement a custom Multi_Buffer class holding an array of channel_t[Music_Emu::voice_count()] and then set this custom buffer via Music_Emu::set_buffer(). Am I missing something?

Comments (10)

  1. Michael Pyne repo owner

    What you suggest seems to be correct. channel_t is an analog for a specific voice in the Multi_Buffer.

    This would only work for music emulators that are derived from Classic_Emu at this point (e.g. the GB emulator, but not the SNES SPC).

    Looking at the code I'm not sure that this would work until Music_Emu::mute_voices(0) has been called manually, since the Classic_Emu appears not to use the custom buffer that is passed in except for in mute_voices_, and I've not seen anywhere else where that function might be called as part of initialization.

  2. Tom M. reporter

    Ok, I'll try to work on this. In case anybody wants to follow: https://github.com/derselbst/game-music-emu/tree/multichannel

    But instead implementing another custom class that does pretty much the same as Stereo_Buffer, I'll try to enhance Stereo_Buffer for holding multiple channel_t. By having some

    gme_enable_multichannel(Music_Emu* emu, int isEnabled);
    

    Classic_Emu can decide whether to give each voice a separate channel_t or not.

    Do you see any chance to get Spc_Emu for multi channel rendering?

  3. Michael Pyne repo owner

    Spc_Emu looks like it would need a bit of surgery within Spc_Dsp to support multi-channel rendering (along with addressing how Echo and FIR would work broken up across independent channels). I don't think it would be horribly complicated though.

  4. Tom M. reporter

    Ok, so instead of modifying Stereo_Buffer, I fiddled around with Effects_Buffer. It basically works quite well. If multichannel support is requested through gme_new_emu(), gme will allocate an Effects_Buffer that can hold 8 voices (maximum possible). Ofc this has to be supported by the underlying Emu type, and atm only Classic_Emu does. Every other Emu should generate sound as before. The user can test via gme_multi_channel() whether the output retrieved will have each voice rendered to their own stereo channel.

    Please review my changes and let me know if I messed smth. up. There is one issue I could not solve, which is that strange stereo mask handling in Effects_Buffer::end_frame().

    https://github.com/derselbst/game-music-emu/tree/multichannel

  5. Michael Pyne repo owner

    I'll pulled up the Github page and will try to review it sometime this week. Not blowing you off, it's more a function of (lack of) free time. But I'll try to keep you from waiting too long one way or the other.

  6. Michael Pyne repo owner

    I opened a pull request with your changes and started on reviewing. Not done yet by any means but if you want to take a look I've at least noted something things you could start on.

  7. Tom M. reporter

    There seems to be a bug when trying to multichannel play vgm files (specifically Sonic 3 & Knuckles). Audio seems to be 4 times faster as usual. I'll look into that, but it may take some time until I do that. Fortunately everything sounds fine without multichannel rendering.

  8. Tom M. reporter

    Finally had time looking into this. Sonic 3 instantiates Vgm_Emu class which internally uses requires the YM2*** FM sound chip emulators. Those have hardcoded stereo support. There are just so many sample buffers and resample buffers floating around that I completely lost overview. Unfortunately the only option I saw was to disable multichannel support for Vgm_Emu class, see the commit I pushed to my github fork.

  9. Michael Pyne repo owner

    OK, I've applied your commit, hopefully when we get it figured out we can re-enable for YM2*.

  10. Log in to comment