Open/close libao audio device

This commit is contained in:
Anton Yabchinskiy 2014-11-22 02:58:32 +03:00
parent 9fb49e56a4
commit 2f92e2a67a
2 changed files with 17 additions and 0 deletions

View file

@ -43,6 +43,17 @@ Error AudioDriverAO::init() {
output_format = OUTPUT_STEREO; output_format = OUTPUT_STEREO;
channels = 2; channels = 2;
ao_sample_format format;
format.bits = 16;
format.rate = mix_rate;
format.channels = channels;
format.byte_format = AO_FMT_LITTLE;
format.matrix = "L,R";
device = ao_open_live(ao_default_driver_id(), &format, 0);
ERR_FAIL_COND_V(device == 0, ERR_CANT_OPEN);
int latency = GLOBAL_DEF("audio/output_latency",25); int latency = GLOBAL_DEF("audio/output_latency",25);
buffer_size = nearest_power_of_2( latency * mix_rate / 1000 ); buffer_size = nearest_power_of_2( latency * mix_rate / 1000 );
@ -114,6 +125,10 @@ void AudioDriverAO::finish() {
memdelete(thread); memdelete(thread);
if (mutex) if (mutex)
memdelete(mutex); memdelete(mutex);
if (device)
ao_close(device);
thread = NULL; thread = NULL;
}; };

View file

@ -40,6 +40,8 @@ class AudioDriverAO : public AudioDriverSW {
Thread* thread; Thread* thread;
Mutex* mutex; Mutex* mutex;
ao_device* device;
int32_t* samples_in; int32_t* samples_in;
static void thread_func(void* p_udata); static void thread_func(void* p_udata);