LIM, if you’re around, I wouldn’t mind some input (-unfy).
I’ve got a working SDL / ffmpeg combination working just swimmingly. Single
movie with sound, or multiple silent concurrent movie playback works and all
that good jazz. RGB output or YUV, all kinds of goodness.
My application will soon need the services of a sound mixer (playing
multiple sound effects, or possibly sound effects while an ffmpeg movie is
being played). I’ve written a dozen sound mixers in the past across several
platforms (ranging from bare metal to win32, etc)… but… figured I’d give
SDL_mixer a chance first before writing yet another mixer.
My problem comes in that there doesn’t appear to be a way to hook the "IRQ"
more or less via SDL_mixer (ie: the audio call back function that’s apart of
sdl_openaudio() is missing from mix_openaudio()).
Is there a clean way to get a Mix_Chunk callback for filling in the data
stream with my own audio generator (or decoder) constantly ?
I’ve looked through the last few years of SDL mailing list that I’ve managed
to accrue and don’t appear to have seen this question before.
Poking through the documentation, it looks like the Mix_RegisterEffect()
function might accomplish what I want ? Does the ‘effect’ function get
called before the Chunk stream gets mixed into the output ?
Something along the lines of (some really ugly pseudo code):
// my audio buffer, void * for simplicity here…
void * ffmpeg_audio_buffer;
// create a chunk out of it
ffmpeg_audio_buffer = malloc(howeverbigitis);
ffmpeg_chunk = Mix_QuickLoad_RAW(ffmpeg_audio_buffer, howeverbigitis);
// i’ll leave channel 0 as my hardcoded ffmpeg decode channel
// register an ‘effect’ so that i can play with the data stream constantly
Mix_RegisterEffect(0, callback_hack, done_function, userarg);
// start playing it constantly
MixPlayChannel(0, ffmpeg_chunk, -1);
// go about the rest of my proggy as usual
… with something along the lines of:
callback_hack(chan, stream, len, userdata)
{
// overwrite stream with my ffmpeg audio data or silence as appropriate
memcpy(stream, some_ffmpeg_decoded_audio, len);
// assume at exit of this function, the data contained/obliterated in
stream gets mixed into the final output
}