1

我现在如何在 iOS 中录制声音,但这会降低我的应用程序的性能。可以在新线程中录制声音吗?如何?

4

1 回答 1

2

音频录制由硬件编解码器直接处理,因此不应影响基于 CPU 的活动。把它放在一个线程中不会有任何区别

您是否对您的应用程序进行了分析以找出导致减速的原因。例如,您是否使用复杂的 Mic 输入电平显示并在那里阻塞主线程。

查看您的录制选项并确定这是否会影响性能

这是我在我的应用程序中用于同时绘图和录制的设置。它在具有 CPU 狗的 iPad1 上运行良好

[[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;

我怀疑录音本身会减慢你的绘画速度。

于 2012-09-13T07:43:52.473 回答