0

I am using AudioUnit class for recording and playback. During recording i can listen sound. Problem is that when i use sample rate 44100 then it working fine but if i use sample rate 8000 then it generating noise. After recording with 8000 sample rate when i play then there is no noise, there is actual sound. Means only the time of recording it generate noise with actual sound.

My AudioStreamBasicDescription setting is-

audioStreamDescription.Format = AudioFormatType.LinearPCM;
audioStreamDescription.FormatFlags = AudioFormatFlags.LinearPCMIsSignedInteger |
                                                      AudioFormatFlags.LinearPCMIsPacked;
audioStreamDescription.SampleRate = 8000; // 44100;
audioStreamDescription.BitsPerChannel = 16;
audioStreamDescription.ChannelsPerFrame = 1;
audioStreamDescription.BytesPerFrame = (16 / 8);
audioStreamDescription.FramesPerPacket = 1;
audioStreamDescription.BytesPerPacket = audioStreamDescription.BytesPerFrame * audioStreamDescription.FramesPerPacket;
audioStreamDescription.Reserved = 0;

AudioUnit setting is-

public void prepareAudioUnit()
{
    // Getting AudioComponent Remote output 
    _audioComponent = AudioComponent.FindComponent(AudioTypeOutput.Remote);

    // creating an audio unit instance
    audioUnit = new AudioUnit.AudioUnit(_audioComponent);

    // turning on microphone
    audioUnit.SetEnableIO(true, AudioUnitScopeType.Input, 1 );

    audioUnit.SetEnableIO(true, AudioUnitScopeType.Output, 0 );

    // setting audio format        
    var austat = audioUnit.SetFormat(audioStreamDescription, AudioUnitScopeType.Output, 1);

   var austatInput = audioUnit.SetFormat(audioStreamDescription, AudioUnitScopeType.Input, 0);

   //audioUnit.SetSampleRate(8000.0f, AudioUnitScopeType.Output, 0);
   //audioUnit.SetSampleRate(8000.0f, AudioUnitScopeType.Input, 1);

  // setting callback method
  audioUnit.SetRenderCallback(render_CallBack, AudioUnitScopeType.Input, 0);

  audioUnit.Initialize();
}

Now, my main question is how i can remove that noise which is comming with actual sound? If i am not able to explain properly then please let me know.

Ashish Kumar
  • 113
  • 2
  • 4
  • 11
  • I have only limited AU experience, but my guess is you aren't actually recording at 8kHz, but rather at 44.1kHz. Did you set the preferred sample rate on the AVAudioSession correctly? – Tim Apr 07 '16 at 18:26
  • Hello Tim, I did. Here is my session code- bool preferredSampleRateResult = avAudioSessionObj.SetPreferredSampleRate(8000.0f, out errorRes); – Ashish Kumar Apr 14 '16 at 05:45

0 Answers0