Sdl_mixer: How to Mix Music To a Buffer Witho ut Playing?

Hi All

I’d like to load a bunch of mods and then convert them to Mix_Chunks to use them
as sound effects.

Is there any way to mix a Mix_Music to a buffer without actually playing it?

At present I’m manually converting the mods to samples and loading them in from
disk. It seems a shame to do this when they could instead be stored in their
original (tiny) format and mixed on loading.

Thanks!

-J

Hello !

I’d like to load a bunch of mods and then convert them to Mix_Chunks to
use them as sound effects.

Is there any way to mix a Mix_Music to a buffer without actually playing
it?

At present I’m manually converting the mods to samples and loading them
in from disk. It seems a shame to do this when they could instead be
stored in their original (tiny) format and mixed on loading.

At the moment this is not possible. Both SDL_mixer and MikMod do
not support converting the next nr. of milliseconds into a buffer.

CU

You may be able to get away with calling MikMod functions directly -
after loading the song, call VC_WriteBytes(buf, length) in a loop to
get the audio. You’d probably want to do that until the sngpos field
in the MODULE structure is equal to the numpos field (indicating the
end of the song, I think). This would be instead of calling
Mix_PlayMusic(). I think that would give you the raw audio. Anyway,
it’s worth a shot.

-MikeOn 8/10/06, Joseph White wrote:

I’d like to load a bunch of mods and then convert them to Mix_Chunks to use them
as sound effects.

Is there any way to mix a Mix_Music to a buffer without actually playing it?

Mike Shal <marfey gmail.com> writes:> On 8/10/06, Joseph White <joseph lexaloffle.com> wrote:

Is there any way to mix a Mix_Music to a buffer without actually playing it?

You may be able to get away with calling MikMod functions directly -
after loading the song, call VC_WriteBytes(buf, length) in a loop to
get the audio. You’d probably want to do that until the sngpos field
in the MODULE structure is equal to the numpos field (indicating the
end of the song, I think). This would be instead of calling
Mix_PlayMusic(). I think that would give you the raw audio. Anyway,
it’s worth a shot.

-Mike

Thanks Mike, that looks like exactly what I need. I can’t try it out just
yet because I’ve had trouble compiling from source with my current compiler
(Borland).

Perhaps this would be a useful feature to expose in future if it is within
the intended scope sdl_mixer. Something like:

Mix_Chunk *Mix_FromMUS(const Mix_Music *music);

-J