如何解决iPhone 6s / iPhone 6s中的音频失真问题

时间:2016-01-21 07:27:36

标签: ios objective-c iphone audio

我正在开发直播应用。我在iPhone 6s和6s Plus上都存在音频失真问题。我知道Apple已经改变了音频硬件采样率(达到48000Hz)。

我尝试过以下代码,但音频仍然失真:

 -(void) setupAudioSpeaker
  {

   NSError * audioSessionError = nil;
   [[AVAudioSession sharedInstance] setCategory:   
    AVAudioSessionCategoryPlayback error: &audioSessionError];
   if (audioSessionError) {
       DLog(@"AVAudioSession Error %ld, %@", 
       (long)audioSessionError.code,  
        audioSessionError.localizedDescription);
      }
    NSTimeInterval bufferDuration =0.01;
    [[AVAudioSession sharedInstance] 
    setPreferredIOBufferDuration:bufferDuration 
    error:&audioSessionError];
  if (audioSessionError) {
    DLog(@"Error %ld, %@", (long)audioSessionError.code, 
    audioSessionError.localizedDescription);
  }
  double sampleRate = 48000.0;
  [[AVAudioSession sharedInstance] setPreferredSampleRate:sampleRate 
  error:&audioSessionError];
 if (audioSessionError) {
      DLog(@"AVAudioSession Error %ld, %@", 
   (long)audioSessionError.code, 
    audioSessionError.localizedDescription);
  }

 [[AVAudioSession sharedInstance] setActive:YES 
 error:&audioSessionError];
 if (audioSessionError) {
    DLog(@"AVAudioSession Error %ld, %@", (long)audioSessionError.code, 
    audioSessionError.localizedDescription);
  }
  sampleRate = [AVAudioSession sharedInstance].sampleRate;
  bufferDuration = [AVAudioSession sharedInstance].IOBufferDuration;
  DLog(@"Sampe Rate:%0.0fHZ I/O Buffer Duration:%f", sampleRate, 
  bufferDuration);
  }

0 个答案:

没有答案