DirectSoundOut doesn't work but WaveOut does
Sending the microphone out to a DirectSoundOut doesn't work with this code:
// directsound - doesn't work
var mic = new WaveInEvent() { DeviceNumber = 0 };
WaveInProvider waveInProvider = new WaveInProvider(mic);
var dso = new DirectSoundOut(DirectSoundOut.DSDEVID_DefaultPlayback, 300);
dso.Init(waveInProvider);
mic.StartRecording();
dso.Play();
But nearly the same things works with WaveOut:
var mic = new WaveInEvent() { DeviceNumber = 0 };
WaveInProvider waveInProvider = new WaveInProvider(mic);
mic.StartRecording();
var waveOut = new WaveOutEvent();
waveOut.DeviceNumber = -1;
waveOut.DesiredLatency = 300;
waveOut.Init(waveInProvider);
waveOut.Play();
NAudio: version 1.8.4 OS: Win 10 64bit
Any ideas?
I'm experiencing the same/a similar issue, but can't identifie the source of the problem either. What might help to give more insight into the problem is that when testing around (using the code below), displaying the PlayBackState in the Unity console I get a seemingly random amount of iterations for the while loop. The amount of Logs varies between 110 and 170, so whatever stops the outputDevice from playing takes this many iterations instead of instantly stopping the playback. And yes the amount of iterations varies even for the same WaveProvider.
outputDevice.Init(audioFile);
Debug.Log(outputDevice.PlaybackState);
outputDevice.Play();
while (outputDevice.PlaybackState == PlaybackState.Playing)
{
Debug.Log(outputDevice.PlaybackState);
}
Debug.Log(outputDevice.PlaybackState);