SDL_mixer 2.0: loading raw PCM data from memory

Hi!

I’m reimplementing some classic DOS game and I need the following:

  • load raw PCM sound (with some weird bitrate) from memory
  • play it with mixing and stereo effects

As I understand, for latter I need SDL_mixer, as core SDL has no
mixing capabilities (e.g. I need to do mixing by hand in audio
callback).

SDL_mixer, however, judging from docs, it only capable of loading
WAV files from either disk or memory (Mix_LoadWAV*), or raw PCM
from memory only in output format (Mix_QuickLoad_RAW). There’s also
a way to determine output format (Mix_QuerySpec), however no way
to convert between audio formats. Core SDL, though, has the conversion
capabilities (SDL_ConvertAudio).

So, is there a simpler way to do what I want than the following:

  • use SDL_mixer to determine output format
  • use core SDL to convert my sound to that format
  • use Mix_QuickLoad_RAW to load the sound and then use SDL_mixer to play
    it

?–
Dmitry Marakasov . 55B5 0596 FF1E 8D84 5F56 9510 D35A 80DD F9D2 F77D
@Dmitry_Marakasov …: jabber: amdmi3 at jabber.ru http://www.amdmi3.ru

The MixChunk struct is in the headers, create your own MixChunk to describe your memory data, then SDL_mixer can utilize your existing sound data.

The Mix_LoadWAV function is a convenience tool for loading .wav files, it is not the sole way to create a MixChunk.

You can also do your own mixing as a post callback on SDL_mixer, I did this for ffmpeg video playback in one project (where I do my own conversion and resampling for video streams only, because I
can’t easily describe them as a MixChunk).On 02/26/2014 08:48 AM, Dmitry Marakasov wrote:

Hi!

I’m reimplementing some classic DOS game and I need the following:

  • load raw PCM sound (with some weird bitrate) from memory
  • play it with mixing and stereo effects

As I understand, for latter I need SDL_mixer, as core SDL has no
mixing capabilities (e.g. I need to do mixing by hand in audio
callback).

SDL_mixer, however, judging from docs, it only capable of loading
WAV files from either disk or memory (Mix_LoadWAV*), or raw PCM
from memory only in output format (Mix_QuickLoad_RAW). There’s also
a way to determine output format (Mix_QuerySpec), however no way
to convert between audio formats. Core SDL, though, has the conversion
capabilities (SDL_ConvertAudio).

So, is there a simpler way to do what I want than the following:

  • use SDL_mixer to determine output format
  • use core SDL to convert my sound to that format
  • use Mix_QuickLoad_RAW to load the sound and then use SDL_mixer to play
    it

?


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

The MixChunk struct is in the headers, create your own MixChunk
to describe your memory data, then SDL_mixer can utilize your
existing sound data.

It doesn’t store any info on format, so I assume it stores audio
data in output format and I still need to

  • use SDL_mixer to determine output format
  • use core SDL to convert my sound to that format

Just avoiding Mix_QuickLoad_RAW is not really a huge gain.–
Dmitry Marakasov . 55B5 0596 FF1E 8D84 5F56 9510 D35A 80DD F9D2 F77D
@Dmitry_Marakasov …: jabber: amdmi3 at jabber.ru http://www.amdmi3.ru