diff --git a/modules/juce_audio_devices/native/juce_android_OpenSL.cpp b/modules/juce_audio_devices/native/juce_android_OpenSL.cpp index 842b42e53a..29b01efa22 100644 --- a/modules/juce_audio_devices/native/juce_android_OpenSL.cpp +++ b/modules/juce_audio_devices/native/juce_android_OpenSL.cpp @@ -80,7 +80,7 @@ public: Array getAvailableSampleRates() override { - static const double rates[] = { 8000.0, 16000.0, 32000.0, 44100.0, 48000.0 }; + static const double rates[] = { 8000.0, 16000.0, 32000.0, 44100.0, 48000.0 }; return Array (rates, numElementsInArray (rates)); } diff --git a/modules/juce_audio_devices/native/juce_ios_Audio.cpp b/modules/juce_audio_devices/native/juce_ios_Audio.cpp index 6016a51420..4d06593758 100644 --- a/modules/juce_audio_devices/native/juce_ios_Audio.cpp +++ b/modules/juce_audio_devices/native/juce_ios_Audio.cpp @@ -67,7 +67,12 @@ public: return s; } - Array getAvailableSampleRates() override { return sampleRates; } + Array getAvailableSampleRates() override + { + // can't find a good way to actually ask the device for which of these it supports.. + static const double rates[] = { 8000.0, 16000.0, 22050.0, 32000.0, 44100.0, 48000.0 }; + return Array (rates, numElementsInArray (rates)); + } Array getAvailableBufferSizes() override { @@ -79,7 +84,7 @@ public: return r; } - int getDefaultBufferSize() override { return 1024; } + int getDefaultBufferSize() override { return 1024; } String open (const BigInteger& inputChannelsWanted, const BigInteger& outputChannelsWanted, @@ -117,10 +122,9 @@ public: AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, routingChangedStatic, this); fixAudioRouteIfSetToReceiver(); - updateDeviceInfo(); setSessionFloat64Property (kAudioSessionProperty_PreferredHardwareSampleRate, targetSampleRate); - updateSampleRates(); + updateDeviceInfo(); setSessionFloat32Property (kAudioSessionProperty_PreferredHardwareIOBufferDuration, preferredBufferSize / sampleRate); updateCurrentBufferSize(); @@ -162,8 +166,15 @@ public: BigInteger getActiveOutputChannels() const override { return activeOutputChans; } BigInteger getActiveInputChannels() const override { return activeInputChans; } - int getOutputLatencyInSamples() override { return 0; } //xxx - int getInputLatencyInSamples() override { return 0; } //xxx + int getOutputLatencyInSamples() override { return getLatency (kAudioSessionProperty_CurrentHardwareOutputLatency); } + int getInputLatencyInSamples() override { return getLatency (kAudioSessionProperty_CurrentHardwareInputLatency); } + + int getLatency (AudioSessionPropertyID propID) + { + Float32 latency = 0; + getSessionProperty (propID, latency); + return roundToInt (latency * getCurrentSampleRate()); + } void start (AudioIODeviceCallback* newCallback) override { @@ -201,7 +212,6 @@ private: //================================================================================================== CriticalSection callbackLock; Float64 sampleRate; - Array sampleRates; int numInputChannels, numOutputChannels; int preferredBufferSize, actualBufferSize; bool isRunning; @@ -322,38 +332,6 @@ private: getSessionProperty (kAudioSessionProperty_AudioInputAvailable, audioInputIsAvailable); } - void updateSampleRates() - { - getSessionProperty (kAudioSessionProperty_CurrentHardwareSampleRate, sampleRate); - - sampleRates.clear(); - sampleRates.add (sampleRate); - - const int commonSampleRates[] = { 8000, 16000, 22050, 32000, 44100, 48000 }; - - for (int i = 0; i < numElementsInArray (commonSampleRates); ++i) - { - Float64 rate = (Float64) commonSampleRates[i]; - - if (rate != sampleRate) - { - setSessionFloat64Property (kAudioSessionProperty_PreferredHardwareSampleRate, rate); - - Float64 actualSampleRate = 0.0; - getSessionProperty (kAudioSessionProperty_CurrentHardwareSampleRate, actualSampleRate); - - if (actualSampleRate == rate) - sampleRates.add (actualSampleRate); - } - } - - DefaultElementComparator comparator; - sampleRates.sort (comparator); - - setSessionFloat64Property (kAudioSessionProperty_PreferredHardwareSampleRate, sampleRate); - getSessionProperty (kAudioSessionProperty_CurrentHardwareSampleRate, sampleRate); - } - void updateCurrentBufferSize() { Float32 bufferDuration = sampleRate > 0 ? (Float32) (preferredBufferSize / sampleRate) : 0.0f;