Skip to content

Instantly share code, notes, and snippets.

@mysteryjeans
Created March 10, 2017 19:53
Show Gist options
  • Select an option

  • Save mysteryjeans/a9430b1b44c503124be4d094d5ca9fd5 to your computer and use it in GitHub Desktop.

Select an option

Save mysteryjeans/a9430b1b44c503124be4d094d5ca9fd5 to your computer and use it in GitHub Desktop.
var bits = 16;
var channels = 1;
var sampleRate = 8000;
var sampleSize = bits / 8 * channels;
var frameSamples = sampleRate / 100; // RTC accepts only 10ms frames so sample rate/1000ms * 10
var duration = 100; // Jitter buffer cache, it should be multiple of 10s
var processDelay = 0;
var renderedTime = 0L;
var syncTime = Stopwatch.StartNew();
using (AudioRTPProcessor processor = new AudioRTPProcessor("", 0, "", ""))
do
{
var data = processor.GetStreamDataAsync(duration).Result;
unsafe
{
fixed (byte* dataPtr = data)
{
for (int i = 0; i < data.Length; i += (frameSamples * sampleSize))
rtcSession.PushAudioFrame(dataPtr + i, bits, sampleRate, channels, frameSamples);
}
}
renderedTime += duration;
processDelay = duration - (int)(syncTime.ElapsedMilliseconds - renderedTime);
if (processDelay < 0) processDelay = 0;
} while (!processor.AudioDataCompleted && socket.State == WebSocketState.Open && rtcSession.ProcessMessages(processDelay) && continueProcessing);
@EbramTawfik

Copy link
Copy Markdown

What is AudioRTPProcessor ?! Is it NuGet Package?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment