Good day!
Can NAudio detect silence with some simple Api way?
Or, may be some peace of code.
Thank you!
Can NAudio detect silence with some simple Api way?
Or, may be some peace of code.
Thank you!
AudioFileReader
instances?AudioFileReader
are getting disposed of after they finish reading. I used the memory profiler to verify that there is only one AudioFileReader
live instance when my application is playing audio. When no audio is playing there are no live instances of AudioFileReader
.AudioFileReader
I switched to MediaFoundationReader
and memory usage does not seem to be growing after two days. I do loose XP support, but that's not a huge issue. I will keep testing MediaFoundationReader
and see if the memory usage grows. public void record()
{
if (recorder == null)
{
recorder = new WasapiCaptureRT();
recorder.DataAvailable += RecorderOnDataAvailable;
}
if (reader != null)
{
reader.Dispose();
reader = null;
}
recorder.StartRecording();
}
private async void RecorderOnDataAvailable(object sender, WaveInEventArgs waveInEventArgs)
{
if (reader == null)
{
recordStream = new MemoryStream();
reader = new RawSourceWaveStream(recordStream, recorder.WaveFormat);
}
writer.WriteBytes(waveInEventArgs.Buffer);
await writer.StoreAsync();
}
And on the C# app: public void test()
{
udpListener = new UdpClient(listenPort);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
var _format = WaveFormat.CreateIeeeFloatWaveFormat(44100,1);
waveOut = new WaveOut();
waveProvider = new BufferedWaveProvider(_format);
waveProvider.BufferDuration = new TimeSpan(1,0,0);
waveOut.Init(waveProvider);
waveOut.Play();
connected = true;
var state = new ListenerThreadState { EndPoint = groupEP };
ThreadPool.QueueUserWorkItem(ListenerThread, state);
}
private void ListenerThread(object state)
{
var listenerThreadState = (ListenerThreadState)state;
var endPoint = listenerThreadState.EndPoint;
try
{
while (connected)
{
byte[] b = udpListener.Receive(ref endPoint);
waveProvider.AddSamples(b, 0, b.Length);
}
}
catch (SocketException)
{
// usually not a problem - just means we have disconnected
}
}
Any help would be appreciated!