Reputation:
I now how to record a sound in iOS, but it decreases the performance of my app. It's possible to record the sound in a new thread? how?
Upvotes: 1
Views: 1235
Reputation: 17378
Audio Recording is handled directly by the hardware codec so should not impact CPU based activities. Putting it in a thread will make no difference
Have you profiled your App to figure out what is causing the slowdown. For example are you using a complex Mic input level display and blocking the main thread there.
Have a look at your recording options and figure out if this is affecting the performance
This is the setup I use for simultaneous drawing and recording in my app. It works fine on an iPad1 which has a dog of a CPU
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error: &setCategoryError];
if (setCategoryError){
NSLog(@"Error setting category! %@", [setCategoryError localizedDescription]);
return NO;
}
NSError *error = NULL;
NSMutableDictionary *options = [NSMutableDictionary dictionaryWithCapacity:5];
[options setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey]; //format
[options setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; //sample rate
[options setValue:[NSNumber numberWithInt:1] forKey:AVNumberOfChannelsKey]; //channels
//encoder
[options setValue:[NSNumber numberWithInt:AVAudioQualityHigh] forKey:AVEncoderAudioQualityKey]; //channels
[options setValue:[NSNumber numberWithInt:16] forKey:AVEncoderBitDepthHintKey]; //channels
self.audiorecorder = [[AVAudioRecorder alloc] initWithURL:mediaURL settings:options error:&error];
self.audiorecorder.meteringEnabled = YES;
Im sceptical about the recording in itself slowing down your drawing.
Upvotes: 2