Max Woolf
Max Woolf

Reputation: 4058

Converting AVAudioRecorder input to buffer of floats

Apologies in advance for the noobiness of this question, this is my first exploration of the audio side of iOS programming.

I'm using the AVAudioRecorder class to record input through the microphone, 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];

It works absolutely fine, the problem comes however when I attempt to use the echonest-codegen library to generate a fingerprint to identify the music played in.

Don't worry, if you've 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 a buffer of samples. I need to convert my input to a "buffer of floats". I've been pointed towards the ExtAudioFile docs, but they're not making an awful lot of sense. Could anybody point me in the right direction? I'm utterly lost!

Many Thanks!

Upvotes: 6

Views: 1871

Answers (1)

HaneTV
HaneTV

Reputation: 926

You can easily get audio sample with Audio Queue Services The biggest issue I see here is that audio buffers are (I believe) of type char* (byte), I don't know why you need float*

Upvotes: 1

Related Questions