Created
March 10, 2017 19:53
-
-
Save mysteryjeans/a9430b1b44c503124be4d094d5ca9fd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is AudioRTPProcessor ?! Is it NuGet Package?