mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
iOS audio: avoided slow check for sample rate support and implemented latency getters.
This commit is contained in:
parent
b372860e23
commit
a17aa2f1a4
2 changed files with 18 additions and 40 deletions
|
|
@ -80,7 +80,7 @@ public:
|
|||
|
||||
Array<double> 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<double> (rates, numElementsInArray (rates));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,12 @@ public:
|
|||
return s;
|
||||
}
|
||||
|
||||
Array<double> getAvailableSampleRates() override { return sampleRates; }
|
||||
Array<double> 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<double> (rates, numElementsInArray (rates));
|
||||
}
|
||||
|
||||
Array<int> 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<Float64> 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<Float64> comparator;
|
||||
sampleRates.sort (comparator);
|
||||
|
||||
setSessionFloat64Property (kAudioSessionProperty_PreferredHardwareSampleRate, sampleRate);
|
||||
getSessionProperty (kAudioSessionProperty_CurrentHardwareSampleRate, sampleRate);
|
||||
}
|
||||
|
||||
void updateCurrentBufferSize()
|
||||
{
|
||||
Float32 bufferDuration = sampleRate > 0 ? (Float32) (preferredBufferSize / sampleRate) : 0.0f;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue