Loading music data from files or buffers

Hello list.

I need to load MP3, WAV and Ogg Vorbis data that is embedded in an
(uncompressed) file. Mix_LoadMUS() only takes a filename as parameter
without a way to specify a file offset and size. Also, there doesn’t
seem to be a version of that routine that would load the sound from a
buffer.

How can I solve this?

Please ignore; I was under the impression that MP3 files only work with
Mixer_Music and are not supported with Mix_Chunk:

http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_frame.html

Seems the docs are a bit outdated on this.On 04/15/2010 04:49 AM, Nikos Chantziaras wrote:

Hello list.

I need to load MP3, WAV and Ogg Vorbis data that is embedded in an
(uncompressed) file. Mix_LoadMUS() only takes a filename as parameter
without a way to specify a file offset and size. Also, there doesn’t
seem to be a version of that routine that would load the sound from a
buffer.

How can I solve this?

I was wrong :stuck_out_tongue: I’m not able to load MP3 files using Mix_Chunk:

“Tried to play a NULL chunk”

It only works with WAV and Ogg files. I’m left with no way to load MP3s
into buffers, and (maybe much worse) I can only play 1 MP3 sound at a
time; SDL-mixer won’t mix Mix_Music, it cuts the sound of the currently
playing one if I play a new one :frowning:

What do I do?On 04/15/2010 05:48 AM, Nikos Chantziaras wrote:

On 04/15/2010 04:49 AM, Nikos Chantziaras wrote:

Hello list.

I need to load MP3, WAV and Ogg Vorbis data that is embedded in an
(uncompressed) file. Mix_LoadMUS() only takes a filename as parameter
without a way to specify a file offset and size. Also, there doesn’t
seem to be a version of that routine that would load the sound from a
buffer.

How can I solve this?

Please ignore; I was under the impression that MP3 files only work with
Mixer_Music and are not supported with Mix_Chunk:

http://www.libsdl.org/projects/SDL_mixer/docs/SDL_mixer_frame.html

Seems the docs are a bit outdated on this.

It only works with WAV and Ogg files. I’m left with no way to load MP3s
into buffers, and (maybe much worse) I can only play 1 MP3 sound at a
time; SDL-mixer won’t mix Mix_Music, it cuts the sound of the currently
playing one if I play a new one :frowning:

What do I do?

Lobby for a better SDL_Mixer implementation. :P>----- Original Message ----

From: Nikos Chantziaras
Subject: Re: [SDL] Loading music data from files or buffers

It only works with WAV and Ogg files. I’m left with no way to load MP3s
into buffers, and (maybe much worse) I can only play 1 MP3 sound at a
time; SDL-mixer won’t mix Mix_Music, it cuts the sound of the currently
playing one if I play a new one :frowning:

What do I do?

Lobby for a better SDL_Mixer implementation. :stuck_out_tongue:

So there’s no way to at least play multiple MP3s at the same time? Even
if SDL_Mixer got improved next week, that would take ages to propagate
to the Linux distros.

I guess I’m now looking for cross-platform alternatives to SDL, since it
doesn’t cut it. Any suggestions? :POn 04/15/2010 07:27 AM, Mason Wheeler wrote:

----- Original Message ----
From: Nikos Chantziaras
Subject: Re: [SDL] Loading music data from files or buffers

Is your sdlmixer built with mp3 support? (patent issues, blah blah)
Or I guess these days it loads libs dyn’ly. You have
smpeg lib installed & in the right place?On Thu, Apr 15, 2010 at 07:48:21AM +0300, Nikos Chantziaras wrote:

So there’s no way to at least play multiple MP3s
at the same time? Even if SDL_Mixer got
improved next week, that would take ages to
propagate to the Linux distros.

I guess I’m now looking for cross-platform
alternatives to SDL, since it doesn’t cut it.
Any suggestions? :stuck_out_tongue:


-bill!

It’s built with mp3 support, using MAD (but I also tried without.) MP3
works OK when loaded as Mix_Music. It doesn’t work when loaded as
Mix_Chunk. For MAD, it’s configured with:

/configure --disable-music-mod-shared --disable-music-ogg-shared
–disable-music-flac-shared --disable-music-mp3-shared
–enable-music-wave --enable-music-midi --disable-music-timidity-midi
–enable-music-mod --enable-music-ogg --enable-music-flac
–disable-music-mp3 --enable-music-mp3-mad-gpl

For smpeg, the last two options are different:

–enable-music-mp3 --disable-music-mp3-mad-gpl

In any event, Mix_GetChunkDecoder() for all available decoders says:

WAVE AIFF VOC OGG FLAC

while Mix_GetMusicDecoder() says:

WAVE MIKMOD OGG FLAC MP3

And I’m left wondering why it can decode both Ogg Vorbis and MP3 for
music, but only Ogg Vorbis for chunks…On 04/15/2010 08:22 AM, Bill Kendrick wrote:

On Thu, Apr 15, 2010 at 07:48:21AM +0300, Nikos Chantziaras wrote:

So there’s no way to at least play multiple MP3s
at the same time? Even if SDL_Mixer got
improved next week, that would take ages to
propagate to the Linux distros.

I guess I’m now looking for cross-platform
alternatives to SDL, since it doesn’t cut it.
Any suggestions? :stuck_out_tongue:

Is your sdlmixer built with mp3 support? (patent issues, blah blah)
Or I guess these days it loads libs dyn’ly. You have
smpeg lib installed& in the right place?

[…]

So there’s no way to at least play multiple MP3s at the same time?
[…]

This will turn pretty much anything into an audio stream:

http://icculus.org/SDL_sound/

IIRC, SDL_mixer doesn’t have streaming support, so you’d have to roll your
own, or hack it into an effect processor and loop a dummy sample or
something…On Thursday 15 April 2010, at 06.48.21, Nikos Chantziaras wrote:


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

The problem isn’t streaming; it’s mixing.On 04/15/2010 09:19 AM, David Olofson wrote:

On Thursday 15 April 2010, at 06.48.21, Nikos Chantziaras wrote:
[…]

So there’s no way to at least play multiple MP3s at the same time?
[…]

This will turn pretty much anything into an audio stream:

http://icculus.org/SDL_sound/

IIRC, SDL_mixer doesn’t have streaming support, so you’d have to roll your
own, or hack it into an effect processor and loop a dummy sample or
something…

What do you need, apart from the basic “mixing streams into the output
buffer”? Volume control is trivial, whereas pitch control is a bit harder to
do properly.On Thursday 15 April 2010, at 08.22.52, Nikos Chantziaras wrote:

On 04/15/2010 09:19 AM, David Olofson wrote:

On Thursday 15 April 2010, at 06.48.21, Nikos Chantziaras wrote:
[…]

So there’s no way to at least play multiple MP3s at the same time?

[…]

This will turn pretty much anything into an audio stream:
http://icculus.org/SDL_sound/

IIRC, SDL_mixer doesn’t have streaming support, so you’d have to roll
your own, or hack it into an effect processor and loop a dummy sample or
something…

The problem isn’t streaming; it’s mixing.


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

Whoops, I must apologize: I wasn’t aware that SDL_sound can do mixing.

However, I’ve hit another obstacle that will probably force me to drop
SDL altogether: My application is written in Qt, and it seems SDL
results in some very weird behavior (for example Qt menus and buttons
will stop working at random points). Googling this, I discovered that
SDL uses some form of internal event loop and can’t be integrated easily
with GUI applications that provide their own event loop, which is a
shame since I only need SDL for sound, not graphics (I used Phonon
before, but it sucks hard.)On 04/15/2010 10:01 AM, David Olofson wrote:

On Thursday 15 April 2010, at 08.22.52, Nikos Chantziaras wrote:

On 04/15/2010 09:19 AM, David Olofson wrote:

On Thursday 15 April 2010, at 06.48.21, Nikos Chantziaras wrote:
[…]

So there’s no way to at least play multiple MP3s at the same time?

[…]

This will turn pretty much anything into an audio stream:
http://icculus.org/SDL_sound/

IIRC, SDL_mixer doesn’t have streaming support, so you’d have to roll
your own, or hack it into an effect processor and loop a dummy sample or
something…

The problem isn’t streaming; it’s mixing.

What do you need, apart from the basic “mixing streams into the output
buffer”? Volume control is trivial, whereas pitch control is a bit harder to
do properly.

[…]

Whoops, I must apologize: I wasn’t aware that SDL_sound can do mixing.

I’m not sure it can (that really belongs in other libs, to avoid bloating
SDL_sound with code that can’t realistically work for everyone anyway) - but
it can handle sample rate conversion, so you might still get away with some
trivial mixing code in the SDL audio callback.

However, I’ve hit another obstacle that will probably force me to drop
SDL altogether: My application is written in Qt, and it seems SDL
results in some very weird behavior (for example Qt menus and buttons
will stop working at random points). Googling this, I discovered that
SDL uses some form of internal event loop and can’t be integrated easily
with GUI applications that provide their own event loop, which is a
shame since I only need SDL for sound, not graphics (I used Phonon
before, but it sucks hard.)

This is the standard problem whenever you want to mix two GUI toolkits, or
even things remotely similar to GUI toolkits… Most of them want take over
the application’s main loop and handle input and “dispatching” themselves.

However, you should be able to use SDL audio without firing up the SDL event
system. SDL_Init(SDL_INIT_VIDEO) only, and you should be fine, I think…On Thursday 15 April 2010, at 20.39.21, Nikos Chantziaras wrote:


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

You probably meant “SDL_Init(SDL_INIT_AUDIO) only”. Which is what I’m
doing, but there are still problems, especially on Mac OS X where SDL
wants to bring Cocoa into the application which is actually Carbon based.

Anyway, it seems SDL isn’t what I require in the first place: a
cross-platform audio decoding, mixing and playing library. Not that SDL
isn’t awesome in its own right; it’s just that it isn’t suitable it
seems for this use case. I only wish FMOD wasn’t closed source and a
pain in the bum to distribute. :POn 04/15/2010 09:55 PM, David Olofson wrote:

[…]

My application is written in Qt, and it seems SDL
results in some very weird behavior (for example Qt menus and buttons
will stop working at random points). Googling this, I discovered that
SDL uses some form of internal event loop and can’t be integrated easily
with GUI applications that provide their own event loop, which is a
shame since I only need SDL for sound, not graphics (I used Phonon
before, but it sucks hard.)

This is the standard problem whenever you want to mix two GUI toolkits, or
even things remotely similar to GUI toolkits… Most of them want take over
the application’s main loop and handle input and “dispatching” themselves.

However, you should be able to use SDL audio without firing up the SDL event
system. SDL_Init(SDL_INIT_VIDEO) only, and you should be fine, I think…

[…]

My application is written in Qt, and it seems SDL
results in some very weird behavior (for example Qt menus and buttons
will stop working at random points). Googling this, I discovered that
SDL uses some form of internal event loop and can’t be integrated easily
with GUI applications that provide their own event loop, which is a
shame since I only need SDL for sound, not graphics (I used Phonon
before, but it sucks hard.)

This is the standard problem whenever you want to mix two GUI toolkits,
or even things remotely similar to GUI toolkits… Most of them want
take over the application’s main loop and handle input and "dispatching"
themselves.

However, you should be able to use SDL audio without firing up the SDL
event system. SDL_Init(SDL_INIT_VIDEO) only, and you should be fine, I
think…

You probably meant “SDL_Init(SDL_INIT_AUDIO) only”.

Yes, of course! Cut’n’paste error… :smiley:

Which is what I’m
doing, but there are still problems, especially on Mac OS X where SDL
wants to bring Cocoa into the application which is actually Carbon based.

Uh oh… Yeah, I figure that’s another conflict similar to the usual GUI
toolkit one. (I’m working on Linux, and have very limited experience with OS
X.)

Anyway, it seems SDL isn’t what I require in the first place: a
cross-platform audio decoding, mixing and playing library. Not that SDL
isn’t awesome in its own right; it’s just that it isn’t suitable it
seems for this use case. I only wish FMOD wasn’t closed source and a
pain in the bum to distribute. :stuck_out_tongue:

How about PortAudio, or if you’re more into professional low latency audio,
RtAudio? Same kind of API as SDL audio, so no built-in mixer or anything, but
they shouldn’t pull in any dependencies beyond the pure audio stuff.On Thursday 15 April 2010, at 21.01.59, Nikos Chantziaras wrote:

On 04/15/2010 09:55 PM, David Olofson wrote:


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

Which is what I’m
doing, but there are still problems, especially on Mac OS X where SDL
wants to bring Cocoa into the application which is actually Carbon based.

Uh oh… Yeah, I figure that’s another conflict similar to the usual GUI
toolkit one. (I’m working on Linux, and have very limited experience with OS
X.)

I suppose there’s no hack/kludge to work around this? The main problem
is the SDLMain.m Objective C file that needs to be compiled into the
application on OS X. Note: I’m not asking you since you’re not
familiar with OS X. Just mentioning in case someone else knows. (But
maybe this belongs in another thread.)

Anyway, it seems SDL isn’t what I require in the first place: a
cross-platform audio decoding, mixing and playing library. Not that SDL
isn’t awesome in its own right; it’s just that it isn’t suitable it
seems for this use case. I only wish FMOD wasn’t closed source and a
pain in the bum to distribute. :stuck_out_tongue:

How about PortAudio, or if you’re more into professional low latency audio,
RtAudio? Same kind of API as SDL audio, so no built-in mixer or anything, but
they shouldn’t pull in any dependencies beyond the pure audio stuff.

Well, the app I’m writing has nothing to do with “professional” audio,
really. Pretty much the only audio stuff it needs is to be able to play
MIDI, WAV, OGG and MP3 audio, possibly at the same time (music and
effects). Latency doesn’t matter. The crucial thing here is that the
supplied audio is not mine (in that case I would have used Ogg for
everything); the app is a tool that runs text-based games in a GUI
(therefore I used Qt) with audio, and those can contain all the above
mentioned formats.

Also, it’s the first time I deal with audio. I don’t know the first
thing about audio mixing, which is why I’m looking for an easy to use
cross platform API to do just that. I thought SDL would be “it”, but it
seems I opened a can of worms instead :POn 04/15/2010 11:39 PM, David Olofson wrote:

It just occurred to me that maybe I won’t need application-level mixing
at all. Previously to trying SDL, I was using Phonon. Phonon does
not do mixing of any kind. However, I was able to play multiple
sounds at the same time. This was possible since the mixing in that
case was performed by the back-end; on OS X, QuickTime would do the
mixing. On Linux, OSSv4’s “vmix”, ALSA’s “dmix”, or GStreamer would do
it. On Windows, kmix did it.

Can I do something similar with SDL then? I gues that would mean
opening the audio device multiple times, each for every sound that is
currently playing (that’s what Phonon did.)On 04/15/2010 11:39 PM, David Olofson wrote:

[…] Same kind of API as SDL audio, so no built-in mixer or anything, but
they shouldn’t pull in any dependencies beyond the pure audio stuff.

OK, I’ve given this a try finally. However, when I try to decode MP3s,
I get:

MPGLIB: Free format not supported.

Not with all of them, but with about 90% of those I tried.

That’s not my idea of “turn pretty much anything into an audio stream” :POn 04/15/2010 09:19 AM, David Olofson wrote:

On Thursday 15 April 2010, at 06.48.21, Nikos Chantziaras wrote:
[…]

So there’s no way to at least play multiple MP3s at the same time?
[…]

This will turn pretty much anything into an audio stream:

http://icculus.org/SDL_sound/

[…]

This will turn pretty much anything into an audio stream:
http://icculus.org/SDL_sound/

OK, I’ve given this a try finally. However, when I try to decode MP3s,
I get:

MPGLIB: Free format not supported.

Not with all of them, but with about 90% of those I tried.

That’s not my idea of “turn pretty much anything into an audio stream” :stuck_out_tongue:

http://icculus.org/pipermail/sdlsound/2007-January/000655.html

I don’t know if there is anything that can “reliably” decode all different
versions, corrupt data and whatnot…

Some proper, open standard format (like Ogg) would be a safer bet, but
obviously, that’s beyond your control unless you’re just playing files that
come with the application.On Saturday 17 April 2010, at 22.10.03, Nikos Chantziaras wrote:

On 04/15/2010 09:19 AM, David Olofson wrote:


//David Olofson - Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
’---------------------------------------------------------------------’

Would it be possible to clean up any ID3 tags during reading the MP3
file into a buffer, prior to passing that buffer to Sound_NewSample()?On 04/17/2010 11:22 PM, David Olofson wrote:

On Saturday 17 April 2010, at 22.10.03, Nikos Chantziaras wrote:

On 04/15/2010 09:19 AM, David Olofson wrote:
[…]

This will turn pretty much anything into an audio stream:
http://icculus.org/SDL_sound/

OK, I’ve given this a try finally. However, when I try to decode MP3s,
I get:

MPGLIB: Free format not supported.

Not with all of them, but with about 90% of those I tried.

That’s not my idea of “turn pretty much anything into an audio stream” :stuck_out_tongue:

http://icculus.org/pipermail/sdlsound/2007-January/000655.html

I don’t know if there is anything that can “reliably” decode all different
versions, corrupt data and whatnot…

No, forget it. On files that are corrupted, Sound_Decode() segfaults.
That is not an option for any application.

I’m amazed how many breakage there is in the sound parts of SDL. I
guess no one’s using SDL for sound?On 04/18/2010 01:17 AM, Nikos Chantziaras wrote:

On 04/17/2010 11:22 PM, David Olofson wrote:

On Saturday 17 April 2010, at 22.10.03, Nikos Chantziaras wrote:

On 04/15/2010 09:19 AM, David Olofson wrote:
[…]

This will turn pretty much anything into an audio stream:
http://icculus.org/SDL_sound/

OK, I’ve given this a try finally. However, when I try to decode MP3s,
I get:

MPGLIB: Free format not supported.

Not with all of them, but with about 90% of those I tried.

That’s not my idea of “turn pretty much anything into an audio
stream” :stuck_out_tongue:

http://icculus.org/pipermail/sdlsound/2007-January/000655.html

I don’t know if there is anything that can “reliably” decode all
different
versions, corrupt data and whatnot…

Would it be possible to clean up any ID3 tags during reading the MP3
file into a buffer, prior to passing that buffer to Sound_NewSample()?