diff options
Diffstat (limited to 'drivers/rtaudio/audio_driver_rtaudio.cpp')
-rw-r--r-- | drivers/rtaudio/audio_driver_rtaudio.cpp | 95 |
1 files changed, 43 insertions, 52 deletions
diff --git a/drivers/rtaudio/audio_driver_rtaudio.cpp b/drivers/rtaudio/audio_driver_rtaudio.cpp index cc715545bd..5ecd4cbaec 100644 --- a/drivers/rtaudio/audio_driver_rtaudio.cpp +++ b/drivers/rtaudio/audio_driver_rtaudio.cpp @@ -33,7 +33,7 @@ #ifdef RTAUDIO_ENABLED -const char* AudioDriverRtAudio::get_name() const { +const char *AudioDriverRtAudio::get_name() const { #ifdef OSX_ENABLED return "RtAudio-OSX"; @@ -44,10 +44,9 @@ const char* AudioDriverRtAudio::get_name() const { #else return "RtAudio-None"; #endif - } -int AudioDriverRtAudio::callback( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData ) { +int AudioDriverRtAudio::callback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, double streamTime, RtAudioStreamStatus status, void *userData) { if (status) { if (status & RTAUDIO_INPUT_OVERFLOW) { @@ -57,19 +56,19 @@ int AudioDriverRtAudio::callback( void *outputBuffer, void *inputBuffer, unsigne WARN_PRINT("RtAudio output underflow!"); } } - int32_t *buffer = (int32_t *) outputBuffer; + int32_t *buffer = (int32_t *)outputBuffer; - AudioDriverRtAudio *self = (AudioDriverRtAudio*)userData; + AudioDriverRtAudio *self = (AudioDriverRtAudio *)userData; - if (self->mutex->try_lock()!=OK) { + if (self->mutex->try_lock() != OK) { // what should i do.. - for(unsigned int i=0;i<nBufferFrames;i++) - buffer[i]=0; + for (unsigned int i = 0; i < nBufferFrames; i++) + buffer[i] = 0; return 0; } - self->audio_server_process(nBufferFrames,buffer); + self->audio_server_process(nBufferFrames, buffer); self->mutex->unlock(); @@ -78,12 +77,12 @@ int AudioDriverRtAudio::callback( void *outputBuffer, void *inputBuffer, unsigne Error AudioDriverRtAudio::init() { - active=false; - mutex=NULL; - dac = memnew( RtAudio ); + active = false; + mutex = NULL; + dac = memnew(RtAudio); ERR_EXPLAIN("Cannot initialize RtAudio audio driver: No devices present.") - ERR_FAIL_COND_V( dac->getDeviceCount() < 1, ERR_UNAVAILABLE ); + ERR_FAIL_COND_V(dac->getDeviceCount() < 1, ERR_UNAVAILABLE); // FIXME: Adapt to the OutputFormat -> SpeakerMode change /* @@ -114,60 +113,60 @@ Error AudioDriverRtAudio::init() { //int priority; /*!< Scheduling priority of callback thread (only used with flag RTAUDIO_SCHEDULE_REALTIME). */ parameters.firstChannel = 0; - mix_rate = GLOBAL_DEF("audio/mix_rate",44100); + mix_rate = GLOBAL_DEF("audio/mix_rate", 44100); - int latency = GLOBAL_DEF("audio/output_latency",25); + int latency = GLOBAL_DEF("audio/output_latency", 25); // calculate desired buffer_size, taking the desired numberOfBuffers into account (latency depends on numberOfBuffers*buffer_size) - unsigned int buffer_size = nearest_power_of_2( latency * mix_rate / 1000 / target_number_of_buffers); + unsigned int buffer_size = nearest_power_of_2(latency * mix_rate / 1000 / target_number_of_buffers); if (OS::get_singleton()->is_stdout_verbose()) { - print_line("audio buffer size: "+itos(buffer_size)); + print_line("audio buffer size: " + itos(buffer_size)); } short int tries = 2; - while(true) { - while( true) { - switch(speaker_mode) { + while (true) { + while (true) { + switch (speaker_mode) { case SPEAKER_MODE_STEREO: parameters.nChannels = 2; break; case SPEAKER_SURROUND_51: parameters.nChannels = 6; break; case SPEAKER_SURROUND_71: parameters.nChannels = 8; break; }; try { - dac->openStream( ¶meters, NULL, RTAUDIO_SINT32, mix_rate, &buffer_size, &callback, this,&options ); + dac->openStream(¶meters, NULL, RTAUDIO_SINT32, mix_rate, &buffer_size, &callback, this, &options); mutex = Mutex::create(true); - active=true; + active = true; break; - } catch ( RtAudioError& e ) { + } catch (RtAudioError &e) { // try with less channels ERR_PRINT("Unable to open audio, retrying with fewer channels.."); - switch(speaker_mode) { - case SPEAKER_MODE_STEREO: speaker_mode=SPEAKER_MODE_STEREO; break; - case SPEAKER_SURROUND_51: speaker_mode=SPEAKER_SURROUND_51; break; - case SPEAKER_SURROUND_71: speaker_mode=SPEAKER_SURROUND_71; break; + switch (speaker_mode) { + case SPEAKER_MODE_STEREO: speaker_mode = SPEAKER_MODE_STEREO; break; + case SPEAKER_SURROUND_51: speaker_mode = SPEAKER_SURROUND_51; break; + case SPEAKER_SURROUND_71: speaker_mode = SPEAKER_SURROUND_71; break; }; } } // compare actual numberOfBuffers with the desired one. If not equal, close and reopen the stream with adjusted buffer size, so the desired output_latency is still correct - if(target_number_of_buffers != options.numberOfBuffers) { - if(tries <= 0) { + if (target_number_of_buffers != options.numberOfBuffers) { + if (tries <= 0) { ERR_EXPLAIN("RtAudio: Unable to set correct number of buffers."); - ERR_FAIL_V( ERR_UNAVAILABLE ); + ERR_FAIL_V(ERR_UNAVAILABLE); break; } - + try { dac->closeStream(); - } catch ( RtAudioError& e ) { + } catch (RtAudioError &e) { ERR_PRINT(e.what()); - ERR_FAIL_V( ERR_UNAVAILABLE ); + ERR_FAIL_V(ERR_UNAVAILABLE); break; } - if (OS::get_singleton()->is_stdout_verbose()) + if (OS::get_singleton()->is_stdout_verbose()) print_line("RtAudio: Desired number of buffers (" + itos(target_number_of_buffers) + ") not available. Using " + itos(options.numberOfBuffers) + " instead. Reopening stream with adjusted buffer_size."); // new buffer size dependent on the ratio between set and actual numberOfBuffers @@ -177,14 +176,11 @@ Error AudioDriverRtAudio::init() { } else { break; } - - } return OK; } - int AudioDriverRtAudio::get_mix_rate() const { return mix_rate; @@ -215,24 +211,19 @@ void AudioDriverRtAudio::unlock() { void AudioDriverRtAudio::finish() { - if ( active && dac->isStreamOpen() ) - dac->closeStream(); - if (mutex) - memdelete(mutex); - if (dac) - memdelete(dac); + if (active && dac->isStreamOpen()) + dac->closeStream(); + if (mutex) + memdelete(mutex); + if (dac) + memdelete(dac); } +AudioDriverRtAudio::AudioDriverRtAudio() { - -AudioDriverRtAudio::AudioDriverRtAudio() -{ - - mutex=NULL; - mix_rate=44100; - speaker_mode=SPEAKER_MODE_STEREO; + mutex = NULL; + mix_rate = 44100; + speaker_mode = SPEAKER_MODE_STEREO; } - - #endif |