I have a audio player, made from AudioTrack, that gets and write byte[] packs of audio data (not the entire this at a time, but smaller pieces). The data is constantly playing, but sometimes - random, I get whie noise over that audio, and if I wait a little it will then play normal. This happens randomly. Is it because the buffer may be to small? I am playing wav files. This is my code:
public void Read()
{
System.Threading.Tasks.Task.Run(() =>
{
int _bufferSize;
AudioTrack _output;
_bufferSize = AudioTrack.GetMinBufferSize(44100, ChannelOut.Stereo, Android.Media.Encoding.Pcm16bit);
_output = new AudioTrack(Android.Media.Stream.Music, 44100, ChannelOut.Stereo, Android.Media.Encoding.Pcm16bit, _bufferSize, AudioTrackMode.Stream);
_output.Play();
while (mmInStream.CanRead)
{
try
{
byte[] myReadBuffer = new byte[10000];
mmInStream.Read(myReadBuffer, 0, myReadBuffer.Length);
_output.Write(myReadBuffer, 0, myReadBuffer.Length);
}
catch (System.IO.IOException ex)
{
_output.Stop();
System.Diagnostics.Debug.WriteLine("Input stream was disconnected", ex);
}
}
_output.Stop();
}).ConfigureAwait(false);
}