Quantcast
Channel: NAudio
Viewing all 5831 articles
Browse latest View live

Commented Unassigned: Dictation recorder hangs on waveInClose [16501]

$
0
0
Our dictation software hangs on NAudio call as described below. This has been tried to get fixed for ages but no luck. Hope you can help!


Hang happens in WaveIn.cs in CloseWaveInDevice() function, line 336 WaveInterop.waveInClose(waveInHandle), that row is in bold below.

private void CloseWaveInDevice()
{

if (waveInHandle == IntPtr.Zero) return;
_logger.Log(LogLevel.Debug, () => "close wavein");

MmException.Try(WaveInterop.waveInStop(waveInHandle), "waveInStop");

MmException.Try(WaveInterop.waveInReset(waveInHandle), "waveInReset");

if (buffers != null)
{
_logger.Log(LogLevel.Debug, () => "close wavein, buffers=" + buffers.Length.ToString());
for (int n = 0; n < buffers.Length; n++)
{
_logger.Log(LogLevel.Debug, () => "buffers[" + n + "] dispose call");
buffers[n].Dispose();
_logger.Log(LogLevel.Debug, () => "buffers[" + n + "] disposed");
}
buffers = null;
}
_logger.Log(LogLevel.Debug, () => "buffers disposed, try to close waveIn");
var result = WaveInterop.waveInClose(waveInHandle);
_logger.Log(LogLevel.Debug, () => "waveInClose result: " + result.ToString());

waveInHandle = IntPtr.Zero;
// _logger.Log(LogLevel.Debug, () => "close wavein method end");
}


WaveInClose is called every time recording is paused to control recording led on Olympus DR-2X00 mic.

waveInClose is from winmm library ->
[DllImport("winmm.dll")]
public static extern MmResult waveInClose(IntPtr hWaveIn);

msdn -> https://msdn.microsoft.com/en-us/library/dd743840(v=vs.85).aspx

Problem is that it doesn't return error code -> it just never returns from this function in this case.

attached is a debug log from the software. It hangs on the last row.

-Juha

Comments: I mean, when are you calling CloseWaveInDevice? Is it when the user clicks a button? Or on a timer? Or after recording a certain amount of audio? etc Normally you would call StopRecording, and then wait for the RecordingStopped event to fire before disposing your WaveIn

Commented Unassigned: Dictation recorder hangs on waveInClose [16501]

$
0
0
Our dictation software hangs on NAudio call as described below. This has been tried to get fixed for ages but no luck. Hope you can help!


Hang happens in WaveIn.cs in CloseWaveInDevice() function, line 336 WaveInterop.waveInClose(waveInHandle), that row is in bold below.

private void CloseWaveInDevice()
{

if (waveInHandle == IntPtr.Zero) return;
_logger.Log(LogLevel.Debug, () => "close wavein");

MmException.Try(WaveInterop.waveInStop(waveInHandle), "waveInStop");

MmException.Try(WaveInterop.waveInReset(waveInHandle), "waveInReset");

if (buffers != null)
{
_logger.Log(LogLevel.Debug, () => "close wavein, buffers=" + buffers.Length.ToString());
for (int n = 0; n < buffers.Length; n++)
{
_logger.Log(LogLevel.Debug, () => "buffers[" + n + "] dispose call");
buffers[n].Dispose();
_logger.Log(LogLevel.Debug, () => "buffers[" + n + "] disposed");
}
buffers = null;
}
_logger.Log(LogLevel.Debug, () => "buffers disposed, try to close waveIn");
var result = WaveInterop.waveInClose(waveInHandle);
_logger.Log(LogLevel.Debug, () => "waveInClose result: " + result.ToString());

waveInHandle = IntPtr.Zero;
// _logger.Log(LogLevel.Debug, () => "close wavein method end");
}


WaveInClose is called every time recording is paused to control recording led on Olympus DR-2X00 mic.

waveInClose is from winmm library ->
[DllImport("winmm.dll")]
public static extern MmResult waveInClose(IntPtr hWaveIn);

msdn -> https://msdn.microsoft.com/en-us/library/dd743840(v=vs.85).aspx

Problem is that it doesn't return error code -> it just never returns from this function in this case.

attached is a debug log from the software. It hangs on the last row.

-Juha

Comments: Ok, it is called when user clicks (actually slides) a button of professional dictation usb-recorder, Olympus or Philips. There are these situations when hanging does not happen even with desktop which usually have the issue: 1. using generic audio for recording 2. running the app in similar Windows image but in top of Virtualbox (just a test case). Do you still think there could be issue with disposing before recording stop?

New Post: Audio file shorter than should be. Any Ideas?

$
0
0
Hey.
Maybe I didn't explane program correctly. Goal of program is to record incoming adudio from multiple line ins 24/7 and save files every round hour (8:00, 9:00) thats why I needed DateTime.Now. In some files I was missing about 15 seconds from recording.
But now all is ok. Turns out it was my USB Audio Adapters fault.

New Post: Audio file shorter than should be. Any Ideas?

$
0
0
great, glad you found a solution

Commented Unassigned: Dictation recorder hangs on waveInClose [16501]

$
0
0
Our dictation software hangs on NAudio call as described below. This has been tried to get fixed for ages but no luck. Hope you can help!


Hang happens in WaveIn.cs in CloseWaveInDevice() function, line 336 WaveInterop.waveInClose(waveInHandle), that row is in bold below.

private void CloseWaveInDevice()
{

if (waveInHandle == IntPtr.Zero) return;
_logger.Log(LogLevel.Debug, () => "close wavein");

MmException.Try(WaveInterop.waveInStop(waveInHandle), "waveInStop");

MmException.Try(WaveInterop.waveInReset(waveInHandle), "waveInReset");

if (buffers != null)
{
_logger.Log(LogLevel.Debug, () => "close wavein, buffers=" + buffers.Length.ToString());
for (int n = 0; n < buffers.Length; n++)
{
_logger.Log(LogLevel.Debug, () => "buffers[" + n + "] dispose call");
buffers[n].Dispose();
_logger.Log(LogLevel.Debug, () => "buffers[" + n + "] disposed");
}
buffers = null;
}
_logger.Log(LogLevel.Debug, () => "buffers disposed, try to close waveIn");
var result = WaveInterop.waveInClose(waveInHandle);
_logger.Log(LogLevel.Debug, () => "waveInClose result: " + result.ToString());

waveInHandle = IntPtr.Zero;
// _logger.Log(LogLevel.Debug, () => "close wavein method end");
}


WaveInClose is called every time recording is paused to control recording led on Olympus DR-2X00 mic.

waveInClose is from winmm library ->
[DllImport("winmm.dll")]
public static extern MmResult waveInClose(IntPtr hWaveIn);

msdn -> https://msdn.microsoft.com/en-us/library/dd743840(v=vs.85).aspx

Problem is that it doesn't return error code -> it just never returns from this function in this case.

attached is a debug log from the software. It hangs on the last row.

-Juha

Comments: well hanging almost always comes from two calls into the driver from different threads, or from a callback within a callback. If you're getting it with WaveOutEvent though I can't see how that would happen. Is there a really simple repro you can set up?

New Post: Beginners questions, please be kind....

$
0
0
Hi,

Doing my first steps in Audio prog and using NAudio, I'm trying to have a simple app that grabs a WAV file and getting 20ms of audio data each time till EOF. However I'm getting a bit confused with the buffer arrays and probably conversions.
Is there a simple way someone can post in here?

Moreover I got confused with the following:
When using AudioFileReader readertest = new AudioFileReader(fileName) I'm getting different metadata like bitrate of 32 and length of ~700000.
However, when using the NAudio - WaveFileReader file1 = new WaveFileReader(fileName) I'm getting half values for the same audio file (bitrate = 16, length = ~350000).
Can someone please explain the reason?

Thanks v much!

New Post: How to dispose MMDeviceEnumerator / MMDevice

$
0
0
I would like to keep getting the default audio endpoint but to prevent a memory leak I need to dispose of these objects.
Dim de As New MMDeviceEnumerator
Dim device As MMDevice = de.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)
Can anyone suggest a solution?

New Post: Beginners questions, please be kind....

$
0
0
The explanation is simple:

AudioFileReader works with 32 bit float audio, WaveFileReader works with the original format.

As floats (= single datatype in VB) need 32 bit of space instead of 16 bit (= short datatype) the length is exactly doubled.

AudioFileReader does this because it implements ISampleProvider, which must work with floats, and also volume scaling is easier there.

You can achieve the same with WaveFileReader using the extension: "file1.ToSampleProvider()".

New Post: Beginners questions, please be kind....

$
0
0
Thanks for the explanation, I'll stick with the WaveFileReader as it seems to fit my needs the best.
What is the simple way to convert a WAV file to 8Khz and run on 20ms buffers?

Thanks

New Post: NAudio - RMS amplitude of a wav file.

$
0
0
Hello,

I want to find RMS amplitude of a wav file using NAudio but my values seem to be way off. Can someone help me how to do this. The code I have is

static void CheckAmplitude(string srcPath)
    {

        using (WaveFileReader audiowave = new NAudio.Wave.WaveFileReader(srcPath))
        {
            byte[] fileBuffer = new byte[audiowave.Length];
            int read = audiowave.Read(fileBuffer, 0, fileBuffer.Length);
            short[] sampleBuffer = new short[read / 2];
            Buffer.BlockCopy(fileBuffer, 0, sampleBuffer, 0, read);
            double rms = rootMeanSquare(sampleBuffer);
        }
}
 private static double rootMeanSquare(short[] x)
    {
        double sum = 0;
        for (int i = 0; i < x.Length; i++)
        {
            sum += (x[i] * x[i]);

        }
        return Math.Sqrt(sum / x.Length);
    }

New Post: Beginners questions, please be kind....

$
0
0
You can resample to 8kHz with WdlResamlingSampleProvider, MediaFoundationResampler or WaveformatconversionStream.

I´d prefer WDL as it is independent from components installed on you system.

For 20 ms buffer playback set latency of your waveout device accordingly.

New Post: NAudio - RMS amplitude of a wav file.

$
0
0
Reading from a samplePovider is easier than converting the data yourself... use extension WaveFileReader.ToSampleProvider()

The formula in the function itself seems correct.

New Post: Beginners questions, please be kind....

$
0
0
Thanks. is there a sample code of setting the latency to get the 20ms?

Assuming I'm using a 8khz, 1 channel, 16bit audio file, I have the below code:
WaveFileReader wHeader = new WaveFileReader(fullFileName);

byte[] data = new byte[wHeader.Length];
int read = wHeader.Read(data, 0, data.Length);
short[] sampleBuffer = new short[read / 2];
short[] InpBuf;

for (int i = 0; i < read; i += 2)
{
InpBuf = new short[159]; //20ms?

Buffer.BlockCopy(data, 0, sampleBuffer, 0, read);
InpBuf = sampleBuffer;

Process20(InpBuf); //Send 20ms of audio data which inside InpBuf 

}
I can see that the complete audio data is inside sampleBuffer now (generated wave sine) but I cannot divide these 20ms into InpBuf and I see that InpBuf contains the whole audio data.

New Post: Beginners questions, please be kind....

$
0
0
What you want is not a 20ms playback latency, but reading in 20ms chunks. To do that I´d create a NotifyingSampleProvider and read from it. It raises an event on each sample (pair) and you can simply aggregate 20ms by counting SampleRate/50 values.

New Post: midi instruments

$
0
0
I have been able to play a piano midi note using the command:
 midiOut.Send(MidiMessage.StartNote(60, 127, 1).RawData)
but when I try to do the same using some other instruments changing the "1" in "22" (accordion) like this:
   midiOut.Send(MidiMessage.StartNote(60, 127, 22).RawData) 
it doesn't play any note. Where is the mistake?????
Thank you, g.

New Post: WASAPI recording basics

Created Unassigned: Audiodg.exe crash [16504]

$
0
0
I wrote an app with Naudio (I use WaveIn and waveout). Sometimes, for some reason, Audiodg.exe crashes. Is there a relationship? Someone would have a solution?

New Post: How to dispose MMDeviceEnumerator / MMDevice

$
0
0
you can call de.Dispose() for the enumerator
in theory setting device to null should allow the memory to be freed once the garbage collector runs.

Commented Unassigned: Audiodg.exe crash [16504]

$
0
0
I wrote an app with Naudio (I use WaveIn and waveout). Sometimes, for some reason, Audiodg.exe crashes. Is there a relationship? Someone would have a solution?
Comments: not seen that happen before. anything unusual about your application or soundcard?

New Post: WASAPI recording basics

$
0
0
You've got a good answer to your first question on StackOverflow
For the second question, WaveFileWriter is intended to create new WAV files, so there is no need to seek.
Viewing all 5831 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>