Commit 71a4e8ed1348293efc867c40b321ab040500fced

Sam Lantinga 2017-02-23T12:10:02

Stop CoreAudio from doing expensive audio rate conversion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m
index 515df99..485d86d 100644
--- a/src/audio/coreaudio/SDL_coreaudio.m
+++ b/src/audio/coreaudio/SDL_coreaudio.m
@@ -734,6 +734,13 @@ COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
     if (!update_audio_session(this, SDL_TRUE)) {
         return -1;
     }
+
+    /* Stop CoreAudio from doing expensive audio rate conversion */
+    @autoreleasepool {
+        AVAudioSession* session = [AVAudioSession sharedInstance];
+        [session setPreferredSampleRate:this->spec.freq error:nil];
+        this->spec.freq = (int)session.sampleRate;
+    }
 #endif
 
     /* Setup a AudioStreamBasicDescription with the requested format */