Source code checked in, #94dd83be9967
Source code checked in, #04dc12d92312
New Post: NAudio 1.6 - Wasapi Loopback COMException
when you call stoprecording, don't immediately dispose Wasapi and set it to nothing - that should be done in the RecordingStopped handler
New Post: NAudio 1.6 - Wasapi Loopback COMException
that's right, i made slight modifications, the final code for those who write in VB.Net is:
Imports naudio
Imports naudio.wave
Imports NAudio.CoreAudioApi
Public Class Form1
Dim WithEvents Wasapi As WasapiLoopbackCapture
Dim Writer As WaveFileWriter
Dim mmdev As MMDeviceEnumerator
Dim Audio As MMDevice
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
mmdev = New MMDeviceEnumerator
Audio = mmdev.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)
Wasapi = New WasapiLoopbackCapture(Audio)
Writer = New WaveFileWriter("E:\4.wav", Audio.AudioClient.MixFormat)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles ExitProgram.Click
'''''
If Writer IsNot Nothing Then
Writer.Flush()
Writer.Close()
Writer.Dispose()
Writer = Nothing
End If
''''
If Wasapi IsNot Nothing Then
Wasapi.StopRecording()
Wasapi.Dispose()
Wasapi = Nothing
End If
''''
Application.Exit()
End Sub
Private Sub Wasapi_DataAvailable(sender As Object, e As WaveInEventArgs) Handles Wasapi.DataAvailable
Writer.Write(e.Buffer, 0, e.BytesRecorded)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles StartRecording.Click
If Wasapi IsNot Nothing Then
Wasapi.StartRecording()
End If
''''
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles StopRecording.Click
If Wasapi IsNot Nothing Then
Wasapi.StopRecording()
End If
''
End Sub
Private Sub Wasapi_RecordingStopped(sender As Object, e As EventArgs) Handles Wasapi.RecordingStopped
'''''
If Writer IsNot Nothing Then
Writer.Flush()
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs)
If Wasapi IsNot Nothing Then
End If
''
End Sub
End Class
Source code checked in, #ec4cf3d7de55
Source code checked in, #9360651233a5
Source code checked in, #c08a312996ee
Source code checked in, #7697828a97ad
Source code checked in, #4136b5fba503
Source code checked in, #569799226a61
New Post: NAudio Audio Playback
set the DeviceNumber property of WaveOut.
New Post: Need help with exception thrown by NAudio
Ok, initial tests with the suggested change seem to indeed have solved the problem.
I'll keep testing, but it's very promising!
Thanks for the help and keep up with the good work!
Created Issue: MediaFoundation Output Format Float [16375]
Here is a modified version of MediaFounfationReader.
Modification for operation with WASAPI, ASIO, WaveOutEvent
I added an option :: The output format (WaveFormat) is PCM or IEEE
Compatible with the version NAudio 569799226a61
This version is still a prototype!
New Post: Multiple WaveIn MMException
Hi again,
I have changed the code and recorded from one input channel with WASAPI like RecordingPanel.cs. And then I have selected second microphone and recorded successfully with WASAPI. (changing deviceNumber on the second line below).
MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator(); //three devices listed MMDevice wspidevice = deviceEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active)[deviceNumber];//changed this line for every other device, respectively 0,1,2 waveIn = new WasapiCapture(wspidevice);
But again if I tried to record two inputs at the same time, same problem has been existed.
I think the problem is regardless of the method or objects used (traditional WaveIn, or WASAPI can't work without the soundcard drivers' ability).
The main problem is all about windows detection of souncards' channels. All input channels must be detected as a seperate device.
Am I thinking true? Or in any case(regardless of the driver), if I use WASAPI, it should work?
Thanks again.
New Post: Multiple WaveIn MMException
Windows won't present the channels as separate devices unless the soundcard driver has set it up that way. The best way is to capture all your soundcard inputs at once, and route the captured audio separately within your program.
New Post: Multiple WaveIn MMException
MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator(); MMDevice wspidevice = DeviceEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active) [deviceNumber]; waveIn = new WasapiCapture(wspidevice); waveIn.DataAvailable += OnDataAvailable; waveWriter = new WaveFileWriter(fileName, waveIn.WaveFormat);privatevoid OnDataAvailable(object sender, WaveInEventArgs e) {if (waveWriter == null) return; waveWriter.Write(e.Buffer, 0, e.BytesRecorded); waveWriter.Flush(); }
I think that routing will be done in OnDataAvailable event, by checking sender object? Am I true, or is there an another way to do that?
New Post: Multiple WaveIn MMException
yes, your samples will come in interleaved. (one sample for channel 1, one sample for channel 2, one sample for channel 3) etc
New Post: Multiple WaveIn MMException
Thanks a lot Mark. I will try.
New Post: Multiple WaveIn MMException
so you could write code like this if you had an array of waveFileWriters one for each channel:
privatevoid OnDataAvailable(object sender, WaveInEventArgs e) { int bytesPerSample = 2; //(for 16 bit, set to 4 forfloat) int offset = 0; while (offset < e.BytesRecorded) { for (int n = 0; n < channels; n++) { waveFileWriter[n].Write(e.Buffer,offset,bytesPerSample); offset += bytesPerSample; } } }