I am playing a PCM RAW format, and the first 5 seconds of the music it play right, but after that, it plays twice as fast
Here what I have done: I have a player class with a event handler, that when the program receives a byte from a location, it adds to a queue, and a thread to add from this queue to the buffer.
The music I am getting from is from spotify,using libspotifydotnet, the CSCore.Codecs.RAW.RawDataReader
plays correctly, BUT I cant keep adding more data to the stream while playing, OR CAN I???!!
Here is what I have done so far
//Main.cs
WasapiOut soundOut = new WasapiOut();
soundOut.Initialize(Player.source);
soundOut.Play();
...
//Player.cs
public static WriteableBufferingSource source;
private static Queue<byte[]> _q = new Queue<byte[]>();
source = new WriteableBufferingSource(new CSCore.WaveFormat(Session.format.sample_rate, 16, Session.format.channels, CSCore.AudioEncoding.Pcm));
source.FillWithZeros = false;
byte[] buffer = null;
while (!_interrupt && !_complete)
{
if (_q.Count > 0)
{
buffer = _q.Dequeue();
source.Write(buffer, 0, buffer.Length);
System.Console.WriteLine("Buffer written {0} bytes", buffer.Length);
Thread.Sleep(10);
}
}
//New data downloaded event
private static void Session_OnAudioDataArrived(byte[] buffer)
{
if (!_interrupt && !_complete)
{
_q.Enqueue(buffer);
}
}