core audio - IOS, AVAudioSession and Novocaine: how to set the sample rate dynamically? -


for pitch detection, use novocaine framework in order process data captured microphone.

initially - overwrote original novocaine class in order set own (reduced) sample rate:

_inputformat.msamplerate = preferred_sampling_rate;// own value _outputformat.msamplerate = preferred_sampling_rate; // own value 

i reduced sample rate 44100.0 / 4.0 in order capture low frequencies (s.th. between 20 hz , 100 hz). works fine!

when try higher frequencies (s.th. starting 500 hz), deviations due low sample rate. need increase sample rate 44100.0 in order achieve more precision.

my question: novocaine singleton, there way change sample rate dynamically within output block?

as novocaine relies on avaudiosession, i've tried in vain following:

[audiomanager setoutputblock:^(float *data, uint32 numframes, uint32 numchannels) {      self->ringbuffer->fetchinterleaveddata(data, numframes, numchannels);     [[avaudiosession sharedinstance] setpreferredsamplerate:new_sampling_rate error:nil]; …  } 

but doesn't have no effect on sample rate of novocaine framework.

is there possibility change sample rate without creating new audio session? problem is, output block belongs current running session.

when call setpreferredsamplerate:error:, system may not respond sample rate change (or ever). docs:

your requested changes might not take effect immediately. example, can use setpreferreddatasource:error: method on built-in microphone port select front microphone while headset plugged in—this preference not take effect until headset unplugged , audio route changes.

there's guidance on changing parameters in technical q&a qa1631 avaudiosession - requesting audio session preferences:

in cases setting preferred value causes sort of audio system reconfiguration active audio session, audio data i/o stopped , restarted. therefore, if application plans set multiple preferred values, advisable deactivate session first, set preferences, reactivate session , check actual values.

and per this post in apple developer forum, iphone 6s , 6s+ support 48khz through built-in speaker. should never assume preferred sample rate request sample rate used hardware.


separately, i'm not sure why seeing 'deviations' @ 500hz sample rate of 11025hz -- should able accurately capture that. should able capture 20-100hz sample rate of 44100hz - you'll need increase buffer size factor of 4.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -