Hi there!
I got some problems with SDL_mixer. I use to write a small game engine (for me).
As base i've chosen SDL, and everything works great. The engine can play sound (music und sound samples, effects). There's only one problem. Every sound action is delayed.
I mean, the music starts playing and it sounds normally. But when i want to pause or stop the music and so on, it takes at least 1 second after calling the function until the music really stops playing. The same here with Sound Samples. On pressing space a phaser sound shall be played, and it does play...not immediately, but after ca. one second!
I tried several things, for example to change the chunk_size (from 4096 standart). But nothing changed, there was absolutely no difference.
Here the code (listed as it will be executed, because the engine is actually made of classes):
Code:
// Audio-Subsystem intitialisieren
if(SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
{
fprintf(stderr,"XAudio: Failed to init sub system: %s\n",SDL_GetError());
return false;
}
// MIXER starten
if(Mix_OpenAudio(22050,AUDIO_MIX_DEFAULT_FORMAT,2,4096) < 0)
{
fprintf(stderr,"XAudio: Open Audio failed: %s\n",SDL_GetError());
return false;
}
/// ...
if(m_pMusic[m_iSelectedMusic] != NULL) return false;
m_pMusic[m_iSelectedMusic] = Mix_LoadMUS(path);
if(NULL == m_pMusic[m_iSelectedMusic])
{
fprintf(stderr,"XAudio: Failed to load music (%s): %s\n",path,SDL_GetError());
return false;
}
/// ...
Mix_AllocateChannels(16);
/// ...
if(m_pSounds[snd_id] != NULL) return false;
m_pSounds[snd_id] = Mix_LoadWAV(file);
if(m_pSounds[snd_id] == NULL)
{
fprintf(stderr, "XAudio: Unable to load Sound: %s\n", SDL_GetError());
return false;
}
// ...
if(Mix_PlayMusic(m_pMusic[m_iSelectedMusic],loops) < 0)
{
fprintf(stderr,"XAudio: Playing music failed: %s\n",SDL_GetError());
return false;
}
To stop / pause music and play the sample i use the SDL_mixer functions too, of course.
As i said everything works well, excepting the sound delay!
Where is the problem? How could i fix that?
Info:
The documentation of the engine (including source code) is on:
http://www.rgbnet.de/doc/xge_docu/index.html
(code is written in English, but comments and documentation in German!)