We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1013

Summary: Mix_CloseAudio() takes 2 seconds to run
Product: SDL_mixer Reporter: Jacques Le Normand <rathereasy>
Component: miscAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 1.2.8   
Hardware: x86   
OS: Linux   

Description Jacques Le Normand 2010-06-30 08:33:59 UTC
// This code takes 2 seconds to run; it will output "2 seconds to close"
//	g++ -Wall -I/usr/include/SDL test.cpp -o test.o -lSDL_mixer

#include <iostream>
#include <ctime>
#include <SDL/SDL_mixer.h>

int main(){
  int audio_rate = 44100;
  int audio_buffers = 1024;
  Uint16 audio_format = AUDIO_S16SYS;
  int audio_channels = 1;
  Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers);      
  time_t a = time(NULL);
  Mix_CloseAudio();
  time_t b = time(NULL);
  std::cout << difftime(b,a) << " seconds to close" << std::endl;
  return 0;
}
Comment 1 Ryan C. Gordon 2011-08-24 23:41:54 UTC
I assume this is on Linux, right?

This isn't SDL_Mixer, it's SDL's pulseaudio (and maybe ALSA) target. We wait for all audio we wanted to play to finish (so it doesn't cut off the end), but the Pulse API is blocking too long in its drain operation.

--ryan.
Comment 2 Ryan C. Gordon 2012-01-01 01:53:31 UTC
Having looked into this a bit more, it's actually not our bug, it's PulseAudio's:

   http://pulseaudio.org/ticket/866

(Using "ALSA" on modern versions of Ubuntu just reroutes your audio through PulseAudio, so you can't even get below the PulseAudio layer by default anymore...)

--ryan.