2012-09-12 92 views
1

我現在如何在iOS中錄製聲音,但它會降低我的應用程序的性能。有可能將聲音錄製在新線程中?怎麼樣?iphone AVAudioRecorder,記錄線程中的音頻

+0

看看[這個](http://stackoverflow.com/questions/3848172/ios-multitasking-for-an-audio-recording-application) 可能重複btw – ilhnctn

+0

不是這樣。我不想記錄我的應用程序在後臺的時間!我需要將AVAudioRecorder放入一個線程中,因爲它會降低我的應用性能。我需要同時繪製和錄製音頻,並且如果放緩我的繪製視圖 – F79

+0

比使用[GCD]標記更慢(http://developer.apple.com/library/mac/#documentation/Performance/Reference/ GCD_libdispatch_Ref/Reference/reference.html),[NSOperation](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/NSOperation_class/Reference/Reference.html),[NSThread](https:/ /developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSThread_Class/Reference/Reference.html)..你也可以自己看看這些類 – ilhnctn

回答

2

音頻錄製由硬件編解碼器直接處理,因此不應影響基於CPU的活動。把它放在一個線程中將沒有區別

你是否已經對你的應用程序進行了簡介,找出導致放緩的原因。例如,您是否在使用複雜的麥克風輸入電平顯示器並阻止主線程。

看一看你的錄音選項,並找出如果這是影響性能的

這是我用我的應用程序同時拉伸和錄製的設置。它的工作原理罰款的IPAD1具有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; 

林懷疑本身放慢您的繪圖記錄的狗。