diff options
author | Marcelo Fernandez <marcelofg55@gmail.com> | 2017-07-30 16:35:08 -0300 |
---|---|---|
committer | Marcelo Fernandez <marcelofg55@gmail.com> | 2017-07-30 16:35:08 -0300 |
commit | 76821bbb47d8d2dc4b9e7cec3c0b9ce178bc92d5 (patch) | |
tree | 98626d7bcf8d6ee46b2e297954f6236b07ec33f7 /platform | |
parent | 93c226f7a38fc4976e93a5fb693ff22edede0738 (diff) |
Fix mutex initialisation in OS X Audio Driver
Diffstat (limited to 'platform')
-rw-r--r-- | platform/osx/audio_driver_osx.cpp | 53 | ||||
-rw-r--r-- | platform/osx/audio_driver_osx.h | 1 |
2 files changed, 28 insertions, 26 deletions
diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp index dabc7989c0..05d23a9398 100644 --- a/platform/osx/audio_driver_osx.cpp +++ b/platform/osx/audio_driver_osx.cpp @@ -103,6 +103,7 @@ Error AudioDriverOSX::finishDevice() { Error AudioDriverOSX::init() { OSStatus result; + mutex = Mutex::create(); active = false; channels = 2; @@ -159,43 +160,30 @@ OSStatus AudioDriverOSX::output_callback(void *inRefCon, UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList *ioData) { - AudioBuffer *abuf; AudioDriverOSX *ad = (AudioDriverOSX *)inRefCon; - bool mix = true; - - if (!ad->active) - mix = false; - else if (ad->mutex) { - mix = ad->mutex->try_lock() == OK; - }; - - if (!mix) { + if (!ad->active || !ad->try_lock()) { for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) { - abuf = &ioData->mBuffers[i]; + AudioBuffer *abuf = &ioData->mBuffers[i]; zeromem(abuf->mData, abuf->mDataByteSize); }; return 0; }; - int frames_left; - for (unsigned int i = 0; i < ioData->mNumberBuffers; i++) { - abuf = &ioData->mBuffers[i]; - frames_left = inNumberFrames; + AudioBuffer *abuf = &ioData->mBuffers[i]; + int frames_left = inNumberFrames; int16_t *out = (int16_t *)abuf->mData; while (frames_left) { int frames = MIN(frames_left, ad->buffer_frames); - //ad->lock(); ad->audio_server_process(frames, ad->samples_in); - //ad->unlock(); - for (int i = 0; i < frames * ad->channels; i++) { + for (int j = 0; j < frames * ad->channels; j++) { - out[i] = ad->samples_in[i] >> 16; + out[j] = ad->samples_in[j] >> 16; } frames_left -= frames; @@ -203,8 +191,7 @@ OSStatus AudioDriverOSX::output_callback(void *inRefCon, }; }; - if (ad->mutex) - ad->mutex->unlock(); + ad->unlock(); return 0; }; @@ -232,11 +219,18 @@ void AudioDriverOSX::lock() { if (mutex) mutex->lock(); }; + void AudioDriverOSX::unlock() { if (mutex) mutex->unlock(); }; +bool AudioDriverOSX::try_lock() { + if (mutex) + return mutex->try_lock() == OK; + return true; +} + void AudioDriverOSX::finish() { OSStatus result; @@ -247,16 +241,23 @@ void AudioDriverOSX::finish() { ERR_PRINT("AudioObjectRemovePropertyListener failed"); } - memdelete_arr(samples_in); + if (mutex) { + memdelete(mutex); + mutex = NULL; + } + + if (samples_in) { + memdelete_arr(samples_in); + samples_in = NULL; + } }; AudioDriverOSX::AudioDriverOSX() { - - mutex = Mutex::create(); //NULL; + mutex = NULL; + samples_in = NULL; }; -AudioDriverOSX::~AudioDriverOSX(){ - +AudioDriverOSX::~AudioDriverOSX() { }; #endif diff --git a/platform/osx/audio_driver_osx.h b/platform/osx/audio_driver_osx.h index d6d00b7970..287c9d6cbf 100644 --- a/platform/osx/audio_driver_osx.h +++ b/platform/osx/audio_driver_osx.h @@ -70,6 +70,7 @@ public: virtual void unlock(); virtual void finish(); + bool try_lock(); Error reopen(); AudioDriverOSX(); |