Saving the output of SDL_Mixer

Hi

I use SDL and SDL_Mixer in my game.

I have plans about making video captures of how the user user is
playing. Saving the graphics is of course easy. But is the a way to get
the mixed audio signal from SDL_Mixer? I mean, apart from SDL_Mixer
giving the mixed audio stream to SDL (to send it to the sound card), I
would like it to also give it to me, so I can save it in a .WAV file,
for example.

Thanks in advance,
cirix

It’s unclear whether you’re producing previews of your game for people
who don’t have your game to watch, or whether you want “demos” so that
existing players of your game can review theirs and others’ gameplay.
Assuming the former…

At typical sample rates used in most modern games, uncompressed PCM
audio is enormous. You don’t want .WAV files. A conservative
example: five minutes of uncompressed mono-channel audio data at
22050Hz and 16 bits per sample is 12.6MB. A less conservative example:
ten minutes stereo-channel 44100Hz 16-bits per sample is 100.9MB.

If you’re still crazy enough to want to do this, I see two routes: the
first is to redirect all audio to the disk by running your application
with the environment variable setting SDL_AUDIODRIVER=“direct-to-disk
audio” (the file which is used is determined by the environment
variable SDL_DISKAUDIOFILE, and the default filename is “sdlaudio.raw”

The second idea is hack that might work: Recompile SDL_Mixer to export
the mix_channels() symbol, then immediately after Mix_OpenAudio() call
SDL_CloseAudio() then SDL_OpenAudio() with your own callback. Your
callback can in turn call mix_channels(), and write the data to disk.

Most likely however, a more sane option is for you to find some kind
of game recording software that will duplicate the multimedia streams
and encode them so they don’t take up a ridiculous amount of space (10
minutes * 30 frames/second * 640*480 * 24-bit color = 25.1GB) you
could of course do the encoding yourself, but if this is just a means
to an end, I wouldn’t recommend it.

If you just want to create game recordings for existing players, why
not just record the stream of events that influence your game? (You’ll
also need to watch your random number generator if your game uses
random data.)On Tue, Jan 20, 2009 at 6:07 AM, Czirkos Zoltan <czirkos.zoltan at gmail.com> wrote:

Hi

I use SDL and SDL_Mixer in my game.

I have plans about making video captures of how the user user is playing.
Saving the graphics is of course easy. But is the a way to get the mixed
audio signal from SDL_Mixer? I mean, apart from SDL_Mixer giving the mixed
audio stream to SDL (to send it to the sound card), I would like it to also
give it to me, so I can save it in a .WAV file, for example.

Thanks in advance,
cirix


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


http://codebad.com/

Donny Viszneki ?rta:

It’s unclear whether you’re producing previews of your game for people
who don’t have your game to watch, or whether you want “demos” so that
previews (for example in an .avi file.)
“demos”, which are called “replays” in the game, already exist.

At typical sample rates used in most modern games, uncompressed PCM
audio is enormous. You don’t want .WAV files.
Of course I do not want wav files. I asked it this way as it is not the
responsibility of SDL to compress it. For example, I might use ffmpeg
for compressing audio/video/whatever, but the stream is needed - to see
what to compress.

I think I will try that environment variable thing! Thanks.

bye
cirix

Hello !

with the environment variable setting SDL_AUDIODRIVER=“direct-to-disk
audio” (the file which is used is determined by the environment

It is called SDL_AUDIODRIVER=“disk” not
SDL_AUDIODRIVER=“direct-to-disk-audio” i think.

CU

Maybe you can use Mix_GetChunk to get a Mix_Chunk structure where abuf
contains the data of the sample.
Because this is a RAW audio data you could send it to some compressor.

It’s just an idea.

Greets
Christoph

Torsten Giebl schrieb:> Hello !

with the environment variable setting SDL_AUDIODRIVER=“direct-to-disk
audio” (the file which is used is determined by the environment

It is called SDL_AUDIODRIVER=“disk” not
SDL_AUDIODRIVER=“direct-to-disk-audio” i think.

CU


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Now I have found some interressting thing:

Mix_RegisterEffect or Mix_SetPostMix (from SDL_mixer):

Hook a processor function f into a channel for post processing effects.
You may just be reading the data and displaying it, or you may be
altering the stream to add an echo.

Maybe this is what you want.

Greets
Christoph

P.S.:
Sry for multiple mails ^^

Christoph Friedrich schrieb:> Maybe you can use Mix_GetChunk to get a Mix_Chunk structure where abuf

contains the data of the sample.
Because this is a RAW audio data you could send it to some compressor.

It’s just an idea.

Greets
Christoph

Torsten Giebl schrieb:

Hello !

with the environment variable setting SDL_AUDIODRIVER=“direct-to-disk
audio” (the file which is used is determined by the environment

It is called SDL_AUDIODRIVER=“disk” not
SDL_AUDIODRIVER=“direct-to-disk-audio” i think.

CU


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Christoph Friedrich wrote:

Now I have found some interressting thing:

Mix_RegisterEffect or Mix_SetPostMix (from SDL_mixer):

this works as i intended! thanks!

bye
cirix