Convert AVAudioRecorder input to float buffer

Sorry in advance for the importance of this question, this is my first research on the sound side of iOS programming.

I use the AVAudioRecorder class to record microphone input using the following settings dictionary.

NSMutableDictionary *settings = [[NSMutableDictionary alloc] init]; [settings setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey]; [settings setValue:[NSNumber numberWithFloat:11025.0] forKey:AVSampleRateKey]; [settings setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey]; [settings setValue:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey]; [settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey]; [settings setValue:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey]; 

This works fine, the problem occurs when I try to use the echonest-codegen library to create a fingerprint to identify the music that was played.

Do not worry if you have never used it before, basically I have to run this function:

 Codegen * pCodegen = new Codegen(const float* pcm[], int number_of_samples, int samples_offset); 

Where const float * pcm [] is the sample buffer. I need to convert my input to a โ€œfloat bufferโ€. I pointed to the ExtAudioFile docs, but they don't make much sense. Can someone point me in the right direction? I am completely lost!

Many thanks!

+6
source share
1 answer

You can easily get a sound sample using the Audio Queue Service The biggest problem that I see here is that the sound buffers (I think) are of type char * (bytes), I don't know why you need float *

+1
source

Source: https://habr.com/ru/post/900769/


All Articles