Hi all,
Sorry if the question seems silly, I’m still quite a newbie with SDL :-
I’ve read that it is possible with sdl_mixer and smpeg to load mp3 files, so I
wanted to give it a try. Here is the code I use:
#include “SDL.h”
#include “SDL_mixer.h”
…
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers= 4096;
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
{
fprintf(stderr, “Unable to open audio: %s.\n”, Mix_GetError());
exit(1);
}
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
Mix_Music* music = Mix_LoadMUS(“track.mp3”);
…
Mix_PlayMusic(music, 0);
Mix_HaltMusic();
Mix_FreeMusic(music);
…
At runtime, I get the message “Warning: incorrect audio format”, and when I play
the track I just hear noise. Where am I doing wrong ?
Thanks in advance
Hi, why do you stop the music directly after you started it ?
Mix_PlayMusic(music, 0);
Mix_HaltMusic();
Try something like this instead:
Mix_PlayMusic(music, 0);
while( Mix_PlayingMusic() == 1)
{
// Do something
SDL_Delay(10);
}
Mix_FreeMusic(music);>Hi all,
Sorry if the question seems silly, I’m still quite a newbie with SDL :-
I’ve read that it is possible with sdl_mixer and smpeg to load mp3 files, so I
wanted to give it a try. Here is the code I use:
#include “SDL.h”
#include “SDL_mixer.h”
…
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers= 4096;
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
{
fprintf(stderr, “Unable to open audio: %s.\n”, Mix_GetError());
exit(1);
}
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
Mix_Music* music = Mix_LoadMUS(“track.mp3”);
…
Mix_PlayMusic(music, 0);
Mix_HaltMusic();
Mix_FreeMusic(music);
…
At runtime, I get the message “Warning: incorrect audio format”, and when I play
the track I just hear noise. Where am I doing wrong ?
Thanks in advance
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
Thanks a lot Ryan, your suggestion solved my problem 
Quentin
Selon “Ryan C. Gordon” :>
Uint16 audio_format = AUDIO_S16;
At runtime, I get the message “Warning: incorrect audio format”, and when I
play
the track I just hear noise. Where am I doing wrong ?
Try AUDIO_S16SYS.
–ryan.
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
Hi,
Sorry for the possibly very basic question. I use a code like the pasted
below but without the line Mix_QuerySpec to load mp3’s.
I wonder what is the effect of Mix_QuerySpec. I haven’t found it in
(Wiki)-documentation.
On the other hand, I have problems with the most of the mp3 files even
trying endlessly
every audio formats, buffers and rates. Inserting the line:
if(music==NULL) printf(“Something is wrong %s\n”, Mix_GetError());
after Mix_Music* music =… I get
Something is wrong Module format not recognized
Suprisingly, some mp3 files works without problems.
Thank you very much,
Fernando.>I’ve read that it is possible with sdl_mixer and smpeg to load mp3 files,
so I
wanted to give it a try. Here is the code I use:
#include “SDL.h”
#include “SDL_mixer.h”
…
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16;
int audio_channels = 2;
int audio_buffers= 4096;
if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers))
{
fprintf(stderr, “Unable to open audio: %s.\n”, Mix_GetError());
exit(1);
}
Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
Mix_Music* music = Mix_LoadMUS(“track.mp3”);
…
Mix_PlayMusic(music, 0);
…
Express yourself instantly with MSN Messenger! Download today it’s FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/