Beispiel #1
0
        public void Initialize()
        {
            _endpoint = _naudioDeviceEnumerationService.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            _capture  = new WasapiLoopbackCapture(_endpoint);
            _capture.RecordingStopped += CaptureOnRecordingStopped;

            // Handle single-channel by passing the same data for left and right
            if (_capture.WaveFormat.Channels == 1)
            {
                _capture.DataAvailable += ProcessMonoData;
            }
            else if (_capture.WaveFormat.Channels == 4)
            {
                _capture.DataAvailable += ProcessQuadraphonicData;
            }
            // Handle 5.1 by averaging out the extra channels
            else if (_capture.WaveFormat.Channels == 6)
            {
                _capture.DataAvailable += Process51Data;
            }
            // Handle 7.1 by averaging out the extra channels
            else if (_capture.WaveFormat.Channels == 8)
            {
                _capture.DataAvailable += Process71Data;
            }
            // Anything else is limited to two channels
            else
            {
                _capture.DataAvailable += ProcessStereoData;
            }

            _capture.StartRecording();
        }
Beispiel #2
0
        public void Initialize()
        {
            _endpoint = _naudioDeviceEnumerationService.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);

            // Don't initialize if there is no available device.
            if (_endpoint == null)
            {
                return;
            }

            _capture = _useCustomWasapiCapture
                ? CustomWasapiLoopbackCapture.CreateCustomWasapiLoopbackCapture(_endpoint, false, _logger)
                : new WasapiLoopbackCapture();
            _capture.RecordingStopped += CaptureOnRecordingStopped;

            if (_capture.WaveFormat.Channels != _endpoint.AudioClient.MixFormat.Channels)
            {
                // I want to log this to see how it behave in other setups. Don't know if this can happen, and if it happens, may could lead to exceptions
                _logger?.Verbose($"AudioEndPoint Waveformat has {_endpoint.AudioClient.MixFormat.Channels} channels but WasapiCapture was created for {_capture.WaveFormat.Channels} channels");
            }

            // Handle single-channel by passing the same data for left and right
            if (_capture.WaveFormat.Channels == 1)
            {
                _capture.DataAvailable += ProcessMonoData;
            }
            else if (_capture.WaveFormat.Channels == 4)
            {
                _capture.DataAvailable += ProcessQuadraphonicData;
            }
            // Handle 5.1 by averaging out the extra channels
            else if (_capture.WaveFormat.Channels == 6)
            {
                _capture.DataAvailable += Process51Data;
            }
            // Handle 7.1 by averaging out the extra channels
            else if (_capture.WaveFormat.Channels == 8)
            {
                _capture.DataAvailable += Process71Data;
            }
            // Anything else is limited to two channels
            else
            {
                _capture.DataAvailable += ProcessStereoData;
            }
            _capture.StartRecording();
        }