For pitch detection, I use the Novocaine framework in order to process my data captured by the microphone.
Initially - I overwrote the original Novocaine class in order to set my own (reduced) sample rate:
_inputFormat.mSampleRate = PREFERRED_SAMPLING_RATE;// my own value _outputFormat.mSampleRate = PREFERRED_SAMPLING_RATE; // my own value
I reduced the sample rate to 44100.0 / 4.0 in order to capture also the low frequencies (s.th. between 20 Hz and 100 Hz). This works very fine!
When I try to get the higher frequencies (s.th. starting from 500 Hz), I get deviations due to the low sample rate. Thus I need to increase the sample rate to 44100.0 in order to achieve more precision.
My question: as Novocaine is a singleton, is there a way to change the sample rate DYNAMICALLY within the output block?
As Novocaine relies on AVAudioSession, I've tried in vain to do the following:
[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels) {
self->ringBuffer->FetchInterleavedData(data, numFrames, numChannels);
[[AVAudioSession sharedInstance] setPreferredSampleRate:NEW_SAMPLING_RATE error:nil];
… }
But this doesn't have no effect on the sample rate of the Novocaine framework.
Is there a possibility to change the sample rate without creating a new Audio session? The problem is, that the output block belongs to the current running session.