LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 01-21-2005, 10:18 AM   #1
Ictus
Member
 
Registered: Jan 2005
Location: Germany
Distribution: Fedora Core 4
Posts: 32

Rep: Reputation: 15
SDL_mixer sound delay


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!)
 
Old 04-21-2010, 02:59 AM   #2
Shum
LQ Newbie
 
Registered: Oct 2007
Posts: 23

Rep: Reputation: 0
You're using a low audio rate with a high buffer size, that'll give you a lot of latency.

increase the audio rate to 44100
decrease the buffer size to 2048 or 1024, 1024 will give you the least latency but is more likely the cause the sound to crackle on slower computers.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
frozen bubble: sound problem ... SDL_mixer laurentwahl Linux - Games 2 11-06-2005 12:47 PM
SDL_mixer: sound is delayed nexus6 Linux - Software 1 09-03-2005 09:05 AM
Sound delay. xbennyboy Linux - Newbie 1 07-25-2004 01:36 AM
Problem with sound in games - SDL_mixer? MadCactus Linux - Software 0 06-28-2004 03:23 PM
delay in the sound maldito Fedora 0 04-19-2004 06:43 AM


All times are GMT -5. The time now is 12:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration