summaryrefslogtreecommitdiff
path: root/platform/osx/audio_driver_osx.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx/audio_driver_osx.cpp')
-rw-r--r--platform/osx/audio_driver_osx.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/platform/osx/audio_driver_osx.cpp b/platform/osx/audio_driver_osx.cpp
index 8c5a734f76..78c52af201 100644
--- a/platform/osx/audio_driver_osx.cpp
+++ b/platform/osx/audio_driver_osx.cpp
@@ -77,7 +77,7 @@ Error AudioDriverOSX::initDevice() {
break;
}*/
- mix_rate = GLOBAL_DEF("audio/mix_rate", 44100);
+ mix_rate = GLOBAL_DEF("audio/mix_rate", DEFAULT_MIX_RATE);
zeromem(&strdesc, sizeof(strdesc));
strdesc.mFormatID = kAudioFormatLinearPCM;
@@ -92,15 +92,19 @@ Error AudioDriverOSX::initDevice() {
result = AudioUnitSetProperty(audio_unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, kOutputBus, &strdesc, sizeof(strdesc));
ERR_FAIL_COND_V(result != noErr, FAILED);
- int latency = GLOBAL_DEF("audio/output_latency", 25);
- unsigned int buffer_size = closest_power_of_2(latency * mix_rate / 1000);
+ int latency = GLOBAL_DEF("audio/output_latency", DEFAULT_OUTPUT_LATENCY);
+ // Sample rate is independent of channels (ref: https://stackoverflow.com/questions/11048825/audio-sample-frequency-rely-on-channels)
+ buffer_frames = closest_power_of_2(latency * mix_rate / 1000);
- if (OS::get_singleton()->is_stdout_verbose()) {
- print_line("audio buffer size: " + itos(buffer_size) + " calculated latency: " + itos(buffer_size * 1000 / mix_rate));
- }
+ result = AudioUnitSetProperty(audio_unit, kAudioDevicePropertyBufferFrameSize, kAudioUnitScope_Global, kOutputBus, &buffer_frames, sizeof(UInt32));
+ ERR_FAIL_COND_V(result != noErr, FAILED);
+ buffer_size = buffer_frames * channels;
samples_in.resize(buffer_size);
- buffer_frames = buffer_size / channels;
+
+ if (OS::get_singleton()->is_stdout_verbose()) {
+ print_line("audio buffer frames: " + itos(buffer_frames) + " calculated latency: " + itos(buffer_frames * 1000 / mix_rate) + "ms");
+ }
AURenderCallbackStruct callback;
zeromem(&callback, sizeof(AURenderCallbackStruct));
@@ -234,7 +238,7 @@ void AudioDriverOSX::start() {
};
int AudioDriverOSX::get_mix_rate() const {
- return 44100;
+ return mix_rate;
};
AudioDriver::SpeakerMode AudioDriverOSX::get_speaker_mode() const {
@@ -282,8 +286,12 @@ AudioDriverOSX::AudioDriverOSX() {
active = false;
mutex = NULL;
- mix_rate = 44100;
+ mix_rate = 0;
channels = 2;
+
+ buffer_size = 0;
+ buffer_frames = 0;
+
samples_in.clear();
};