Exemplo n.º 1
0
        public override void RequestProcessing(int samples)
        {
            if (currentCapture == null)
            {
                var emptySamples = new float[samples];

                SoundOutputL.Write(emptySamples, 0, emptySamples.Length);
                SoundOutputR.Write(emptySamples, 0, emptySamples.Length);
                return;
            }
            SpinWait.SpinUntil(() =>
                               (!SoundOutputL.IsConnected || SoundOutputL.DataStream.Available >= samples) &&
                               (!SoundOutputR.IsConnected || SoundOutputR.DataStream.Available >= samples));
        }
Exemplo n.º 2
0
        public void DeviceChanged(MMDevice device)
        {
            lock (this)
            {
                currentCapture?.StopRecording();
                currentCapture = new WasapiCapture(device, true);
                currentCapture.DataAvailable += (s, e) =>
                {
                    var buffer   = new WaveBuffer(e.Buffer);
                    var samplesL = new float[e.BytesRecorded / 8];
                    var samplesR = new float[e.BytesRecorded / 8];

                    for (var i = 0; i < e.BytesRecorded / 8; i++)
                    {
                        samplesL[i] = buffer.FloatBuffer[i * 2];
                        samplesR[i] = buffer.FloatBuffer[i * 2 + 1];
                    }

                    SoundOutputL.Write(samplesL, 0, samplesL.Length);
                    SoundOutputR.Write(samplesR, 0, samplesR.Length);
                };
                currentCapture.StartRecording();
            }
        }