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

Created Unassigned: Create WAV stream in memory [16503]

$
0
0
I have a URL to MP4 audio file that I need to send to Speech-To-Text API. The API accepts only WAV stream. I am using NAudio 1.7.3 and the following code to download the file and to get the appropriate stream to be sent to API:

```
string filePath = "C:\Windows\Temp\file.wav";
using (MediaFoundationReader reader = new MediaFoundationReader(audioFileURL))
{
WaveFileWriter.CreateWaveFile(filePath, reader);
}
System.IO.FileStream fs = new FileStream(filePath, FileMode.Open);
```

Then I send the fs stream to API and everything works correctly, although very slowly because of I/O to/from disk.

I decided to rewrite this code and execute all required in memory. For this purpose I wrote the following code (that does not provide me a correct stream):

```
using (MediaFoundationReader reader = new MediaFoundationReader(audioLocation)){
MemoryStream ms = new MemoryStream();
IgnoreDisposeStream ids = new IgnoreDisposeStream(ms);
WaveFileWriter writer = new WaveFileWriter(ids, reader.WaveFormat);

//Doing one of the following (both provide the same outcome):
//1. reader.CopyTo(ids);
//or
//2. this code from NAudio source:
var buffer = new byte[reader.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = reader.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
// end of source provider
break;
}
// Write will throw exception if WAV file becomes too large
writer.Write(buffer, 0, bytesRead);
}

writer.Dispose();
Stream streamToSendToAPI = ids.SourceStream;

//Send streamToSendToAPI to Speech-To-Text API

}
```
My expectation is that using second code example, where I create stream with WAV header and then add the data to the stream, would provide me a valid WAV stream. However, when I send it to speech-to-text API, the API gives error that indicates that stream cannot be processed (meaning that stream is invalid).

Please advise how to fix the in-memory code example to create a valid WAV stream

Commented Unassigned: Create WAV stream in memory [16503]

$
0
0
I have a URL to MP4 audio file that I need to send to Speech-To-Text API. The API accepts only WAV stream. I am using NAudio 1.7.3 and the following code to download the file and to get the appropriate stream to be sent to API:

```
string filePath = "C:\Windows\Temp\file.wav";
using (MediaFoundationReader reader = new MediaFoundationReader(audioFileURL))
{
WaveFileWriter.CreateWaveFile(filePath, reader);
}
System.IO.FileStream fs = new FileStream(filePath, FileMode.Open);
```

Then I send the fs stream to API and everything works correctly, although very slowly because of I/O to/from disk.

I decided to rewrite this code and execute all required in memory. For this purpose I wrote the following code (that does not provide me a correct stream):

```
using (MediaFoundationReader reader = new MediaFoundationReader(audioLocation)){
MemoryStream ms = new MemoryStream();
IgnoreDisposeStream ids = new IgnoreDisposeStream(ms);
WaveFileWriter writer = new WaveFileWriter(ids, reader.WaveFormat);

//Doing one of the following (both provide the same outcome):
//1. reader.CopyTo(ids);
//or
//2. this code from NAudio source:
var buffer = new byte[reader.WaveFormat.AverageBytesPerSecond * 4];
while (true)
{
int bytesRead = reader.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
// end of source provider
break;
}
// Write will throw exception if WAV file becomes too large
writer.Write(buffer, 0, bytesRead);
}

writer.Dispose();
Stream streamToSendToAPI = ids.SourceStream;

//Send streamToSendToAPI to Speech-To-Text API

}
```
My expectation is that using second code example, where I create stream with WAV header and then add the data to the stream, would provide me a valid WAV stream. However, when I send it to speech-to-text API, the API gives error that indicates that stream cannot be processed (meaning that stream is invalid).

Please advise how to fix the in-memory code example to create a valid WAV stream
Comments: as I said on stack overflow, you need to reset the position of your memorystream to 0

New Post: Playing dynamically generated floats.

$
0
0
it's really not that hard. The Read method has a float buffer and tells you how many samples it wants. Just generate that number of samples and copy them in.

Then you can play your custom sample provider directly

New Post: Mac and Linux support

$
0
0
Hey, your library is great. My question is you are planning to have mono version for Mac or Linux?
Thanks.

New Post: Naudio Play Multiple file continuously

$
0
0
Hi,
I have using Naudio waveoutevent. In that i want to play multiple file continuously without cap. When current file before going to stop next file start to played.

Current song and next songs play without cap play continuously Please help me to do thsi.
Its very urgent requirements.

New Post: Mac and Linux support

$
0
0
hi there, a very large part of NAudio is wrappers for Windows APIs, so most of it unfortunately won't work on Mac or Linux. You could perhaps pull out the platform agnostic bits into a .NET core package

New Post: Generate waveform from WAV

New Post: How can i save the captured sound into an array

$
0
0
You can use WaveIn to record audio. In the DataAvailable event handler you'd get the captured audio in a byte array. I'd recommend writing audio to a MemoryStream as you get it and then later you can read out of that memory stream, converting each pair of bytes into a short (assuming you recorded at 16 bit)

Updated Wiki: Home

$
0
0

NAudio Overview

IMPORTANT The latest NAudio source code can now be found on GitHub. For now, CodePlex remains the place to access documentation, discussions and downloads.

NAudio is an open source .NET audio and MIDI library, containing dozens of useful audio related classes intended to speed development of audio related utilities in .NET. It has been in development since 2002 and has grown to include a wide variety of features. While some parts of the library are relatively new and incomplete, the more mature features have undergone extensive testing and can be quickly used to add audio capabilities to an existing .NET application. NAudio can be quickly added to your .NET application using NuGet.

NAudio demo project showing an MP3 file playing:
naudiodemo.png

NAudio WPF Project showing waveform visualisation and spectrum analyser:
NAudioWPF.png

Latest News

For the latest news and more documentation on NAudio, visit Mark Heath's blog.
  • 24 Nov 2014 NAudio 1.7.2 Released with lots of minor enhancements and bugfixes
  • 4 Nov 2013Programming Audio with NAudio training course released on Pluralsight
  • 29 Oct 2013 NAudio 1.7 Released. Read the release notes
  • 26 Oct 2012 NAudio 1.6 Released. Read the release notes
  • 9 Sep 2012 ASIO Recording Support added
  • 19 Dec 2011 NAudio 1.5 Released. Read the release notes
  • 20 Apr 2011 NAudio 1.4 Released. Read the release notes
  • 15 Apr 2011 NAudio demo now shows how to select output devices (for WaveOut, DirectSound, WASAPI and ASIO), and can play 8 bit, 16 bit, 24 bit, and 32 bit float WAV files. Fixed a longstanding ASIO issue.
  • 7 Nov 2010 Major improvements to Mp3FileReader
  • 10 Oct 2009 Version 1.3 Released. Read the release notes
  • 20 Sep 2009 We are getting close to feature complete for 1.3. Last chance to get in any feedback on the API
  • 26 Aug 2009 WPF Waveform drawing demo project including FFT added
  • 28 Feb 2009 Lots of new stuff is being added and planned, so do check out the Source Code tab to have a sneak peak at what's coming in 1.3
  • 26 June 2008 Version 1.2 Released. Read the release notes

NAudio Features

  • Play back audio using a variety of APIs
    • WaveOut
    • DirectSound
    • ASIO
    • WASAPI (Windows Vista and above)
  • Decompress audio from different Wave Formats
    • MP3 decode using ACM or DMO codec
    • AIFF
    • G.711 mu-law and a-law
    • ADPCM
    • G.722
    • Speex (using NSpeex)
    • SF2 files
    • Decode using any ACM codec installed on your computer
  • Record audio using WaveIn, WASAPI or ASIO
  • Read and Write standard .WAV files
  • Mix and manipulate audio streams using a 32 bit floating mixing engine
  • Extensive support for reading and writing MIDI files
  • Full MIDI event model
  • Basic support for Windows Mixer APIs
  • A collection of useful Windows Forms Controls
  • Some basic audio effects, including a compressor

Projects Using NAudio

NAudio currently is used to support a number of audio related utilities, some of which may be moved to be hosted on CodePlex in the future. If you have used NAudio for a project, please get in touch so we can post it here.
  • Skype Voice Changer - Modify your voice with audio effects while talking on Skype
  • .NET Voice Recorder - Record your voice, save to MP3, and visualise the waveform using WPF. Now includes autotune
  • Pree - Record spoken word without the need for editing.
  • MIDI File Mapper - Utility for mapping MIDI drum files for use on other samplers
  • MIDI File Splitter - Split MIDI files up at their markers
  • SharpMod - managed port of MikMod, can play mod files in both WinForms and Silverlight
  • NVorbis - Fully managed Vorbis decoder, with support for NAudio
  • Practice# - Windows tool for practicing playing an instrument with playback music. Includes FLAC playback support and an equaliser for NAudio.
  • WPF Sound Visualization Library - beautiful waveform and spectrum analyzer code written for WPF, comes with NAudio sample
  • Q2Cue - application for running audio cues in a theatrical or other performance related settings
  • TuneBlade - Stream Windows' audio to AirPlay receivers
  • Teachey Teach - utility to help English language conversation teachers generate feedback for students
  • Sound Mill - an audio player, list organizer and automation manager
  • Bravura Studio - a modular, extensible application and platform for creating and experimenting with music and audio.
  • musiX
  • SIPSorcery - .NET softphone framework
  • Squiggle - A free open source LAN Messenger
  • Helix 3D toolkit - Multi-format audio player
  • airphone-tv - A revival of axStream to implement control through the iPhone
  • JamNet - a Silverlight drum sample player
  • Jingle Jim - Jingle Software (German language)
  • All My Music
  • iSpy - Open Source Camera Security Software
  • RadioTuna - Online internet radio player
  • Fire Talk New - chat program
  • AVR Audio Guard - utility to fix a HDMI related issue
  • Locutor da Hora - Educational app simulating a radio studio
  • uAudio - Audio player component for Unity3D
  • Radio Pro - Unity 3D Radio Asset

More Info

For more information, please visit the NAudio Documentation Wiki

Donate

NAudio is a free open source project that is developed in personal time. You can show your appreciation for NAudio and support future development by donating.
Donate

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: Hi, sorry for late reply! Application is wpf type and all calls are made in main thread. We tried WaveInEvent and it did change the behavior according to the logs but doesn’t look like an improvement though. Hang happens just same way. Now logs look like this when hang happens: 2016-09-22 15:14:33.9678 - RUN TEST 83 2016-09-22 15:14:33.9678 - slider stop 2016-09-22 15:14:33.9678 - pause called, recording False, statusStop 2016-09-22 15:14:33.9678 - slider stop method end 2016-09-22 15:14:34.4688 - slide REC 2016-09-22 15:14:34.4688 - RecButtonPushed, e.IsPushed: True _controller.IsRecording: False 2016-09-22 15:14:34.4688 - RecButtonPushed, e.IsPushed = true, so start recording 2016-09-22 15:14:34.4728 - pause called, recording False, statusStop 2016-09-22 15:14:34.4728 - Process recording 2016-09-22 15:14:34.4728 - Start rec 2016-09-22 15:14:34.4728 - record called, status Stop 2016-09-22 15:14:34.4728 - record called. status = Stop 2016-09-22 15:14:34.4728 - capture start 2016-09-22 15:14:34.4988 - capture method end 2016-09-22 15:14:34.4988 - record capture called, status = Record 2016-09-22 15:14:34.4988 - slide REC method end 2016-09-22 15:14:34.6598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:34.6608 Reuse WaveInBuffer 2016-09-22 15:14:34.6608 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:34.6608 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:34.6608 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:34.7598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:34.7598 Reuse WaveInBuffer 2016-09-22 15:14:34.7598 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:34.7598 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:34.7598 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:34.8598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:34.8598 Reuse WaveInBuffer 2016-09-22 15:14:34.8598 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:34.8598 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:34.8628 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:34.9598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:34.9598 Reuse WaveInBuffer 2016-09-22 15:14:34.9598 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:34.9598 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:34.9598 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:35.0598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:35.0598 Reuse WaveInBuffer 2016-09-22 15:14:35.0598 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:35.0598 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:35.0598 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:35.1598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:35.1598 Reuse WaveInBuffer 2016-09-22 15:14:35.1598 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:35.1598 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:35.1598 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:35.2598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:35.2598 Reuse WaveInBuffer 2016-09-22 15:14:35.2598 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:35.2598 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:35.2598 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:35.3598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:35.3598 Reuse WaveInBuffer 2016-09-22 15:14:35.3628 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:35.3628 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:35.3628 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:35.4598 - OnDataAvailable start method, IsCapturing: True _insertMode: False 2016-09-22 15:14:35.4598 Reuse WaveInBuffer 2016-09-22 15:14:35.4598 Reuse WaveInBuffer : waveInUnprepareHeader 2016-09-22 15:14:35.4598 Reuse WaveInBuffer : waveInPrepareHeader 2016-09-22 15:14:35.4598 Reuse WaveInBuffer : waveInAddBuffer 2016-09-22 15:14:35.4598 - slide REC 2016-09-22 15:14:35.4598 - RecButtonPushed, e.IsPushed: False _controller.IsRecording: True 2016-09-22 15:14:35.4598 v.2.7.0.0 - RecButtonPushed, e.IsPushed = false, so rec slider released, stop recording 2016-09-22 15:14:35.4718 - Stopping recording 2016-09-22 15:14:35.4718 - status StoppingRecord 2016-09-22 15:14:35.4718 - slide REC method end 2016-09-22 15:14:35.4718 - callback rec stop 2016-09-22 15:14:35.4718 - wave_in start disposing BR, -Juha

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: Actually the change in logs with WaveInEvent was just about logging. Now that logging is similar for that event it looks just as it did with WaveInClose. What else could be checked?

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: When are you calling this? Are you making sure you've waited for recording to completely finish before disposing the wavein instance?

Commented Unassigned: Waveinputs missing from Visual Studio 2015 NuGet?? [16493]

$
0
0
Hi, I can't find waveinputs after installing nuget package. For example:

int waveInDevices = NAudio.Wave.WaveInputs.WaveIn.DeviceCount

Returns: Type or namespace name does not exist in namespace "Naudio.Wave"

Comments: the correct namespace for `WaveIn` is `NAudio.Wave.WaveIn`

Closed Unassigned: Waveinputs missing from Visual Studio 2015 NuGet?? [16493]

$
0
0
Hi, I can't find waveinputs after installing nuget package. For example:

int waveInDevices = NAudio.Wave.WaveInputs.WaveIn.DeviceCount

Returns: Type or namespace name does not exist in namespace "Naudio.Wave"

New Post: WaveOut.Pause() call creating deadlock


New Post: Help for Exception: NAudio.MmException "UnspecifiedError calling waveOutOpen"

$
0
0
Help Mark
thank You for your answer. Sorry for the late response - its a hobby project of mine. In between I have figured out some interesting things:
First: I tried a different PC with an other soundcard. Yes - there are not the problem - no crash.
Second: Debugging. I had ask because I suspect some *.pdb files or symbol files like for the .Net-Framework who would can be downloaded. So know I fetch the sources for NAudio and build a debug DLL. I figured out what happens and like to give you some information about (sorry about the long text - I do not found how I can append some files here). I do this 2 times, one with 44100 (error) and one with 48000 (no error)

44100 (error)
In debug I stopped at "result = callbackInfo.WaveOutOpen(out hWaveOut, DeviceNumber, waveStream.WaveFormat, callback);" in NAudio
the Watch-Window for waveStream.WaveFormat
+       hWaveOut    {0} System.IntPtr
        DeviceNumber    0   int
-       waveStream.WaveFormat   {IeeeFloat} NAudio.Wave.WaveFormat
        AverageBytesPerSecond   352800  int
        BitsPerSample   32  int
        BlockAlign  8   int
        Channels    2   int
        Encoding    IeeeFloat   NAudio.Wave.WaveFormatEncoding
        ExtraSize   0   int
        SampleRate  44100   int
        averageBytesPerSecond   352800  int
        bitsPerSample   32  short
        blockAlign  8   short
        channels    2   short
        extraSize   0   short
        sampleRate  44100   int
        waveFormatTag   IeeeFloat   NAudio.Wave.WaveFormatEncoding
+       callback    {Method = {Void Callback(IntPtr, WaveMessage, IntPtr, NAudio.Wave.WaveHeader, IntPtr)}} NAudio.Wave.WaveInterop.WaveCallback
next: "result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);"

in the the Watch-Window

+       waveOutHandle   {0} System.IntPtr
+       (IntPtr)deviceNumber    {0} System.IntPtr
+       waveFormat  {IeeeFloat} NAudio.Wave.WaveFormat
+       this.Handle {722242}    System.IntPtr
+       IntPtr.Zero {0} System.IntPtr
        WaveInterop.WaveInOutOpenFlags.CallbackWindow   CallbackWindow  NAudio.Wave.WaveInterop.WaveInOutOpenFlags
and
-       waveFormat  {IeeeFloat} NAudio.Wave.WaveFormat
        AverageBytesPerSecond   352800  int
        BitsPerSample   32  int
        BlockAlign  8   int
        Channels    2   int
        Encoding    IeeeFloat   NAudio.Wave.WaveFormatEncoding
        ExtraSize   0   int
        SampleRate  44100   int
        averageBytesPerSecond   352800  int
        bitsPerSample   32  short
        blockAlign  8   short
        channels    2   short
        extraSize   0   short
        sampleRate  44100   int
        waveFormatTag   IeeeFloat   NAudio.Wave.WaveFormatEncoding
The error comes form here:

WaveOut.cs
row-84: result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);

"result = UnspecifiedError"

because: out waveOutHandle get no Handle means: waveOutHandle == 0;

48000 (no error)
In debug I stopped at "result = callbackInfo.WaveOutOpen(out hWaveOut, DeviceNumber, waveStream.WaveFormat, callback);" in NAudio
the Watch-Window for waveStream.WaveFormat
+       hWaveOut    {0} System.IntPtr
        DeviceNumber    0   int
-       waveStream.WaveFormat   {IeeeFloat} NAudio.Wave.WaveFormat
HL      AverageBytesPerSecond   384000  int
        BitsPerSample   32  int
        BlockAlign  8   int
        Channels    2   int
        Encoding    IeeeFloat   NAudio.Wave.WaveFormatEncoding
        ExtraSize   0   int
HL      SampleRate  48000   int
HL      averageBytesPerSecond   384000  int
        bitsPerSample   32  short
        blockAlign  8   short
        channels    2   short
        extraSize   0   short
HL      sampleRate  48000   int
        waveFormatTag   IeeeFloat   NAudio.Wave.WaveFormatEncoding
+       callback    {Method = {Void Callback(IntPtr, WaveMessage, IntPtr, NAudio.Wave.WaveHeader, IntPtr)}} NAudio.Wave.WaveInterop.WaveCallback
next: "result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);"

in the the Watch-Window
+       waveOutHandle   {0} System.IntPtr
+       (IntPtr)deviceNumber    {0} System.IntPtr
+       waveFormat  {IeeeFloat} NAudio.Wave.WaveFormat
HL +        this.Handle {329090}    System.IntPtr
+       IntPtr.Zero {0} System.IntPtr
        WaveInterop.WaveInOutOpenFlags.CallbackWindow   CallbackWindow  NAudio.Wave.WaveInterop.WaveInOutOpenFlags
and
-       waveFormat  {IeeeFloat} NAudio.Wave.WaveFormat
HL      AverageBytesPerSecond   384000  int
        BitsPerSample   32  int
        BlockAlign  8   int
        Channels    2   int
        Encoding    IeeeFloat   NAudio.Wave.WaveFormatEncoding
        ExtraSize   0   int
HL      SampleRate  48000   int
HL      averageBytesPerSecond   384000  int
        bitsPerSample   32  short
        blockAlign  8   short
        channels    2   short
        extraSize   0   short
        sampleRate  48000   int
        waveFormatTag   IeeeFloat   NAudio.Wave.WaveFormatEncoding
WaveOut.cs
row-84: result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);
result = NoError
  • waveOutHandle {17556744} System.IntPtr
WaveCallbackInfo.cs
row-123: callbackInfo.WaveOutOpen(out hWaveOut, DeviceNumber, waveStream.WaveFormat, callback);
hWaveOut = {17556744}

next (just to comlete debug analyse "=>" is "it follows that" no Lambda):
+       buffers {NAudio.Wave.WaveOutBuffer[2]}  NAudio.Wave.WaveOutBuffer[]

in MyForm:
 waveOut.Play();
 
    Play() 
    playbackState == PlaybackState.Stopped //true
    playbackState //get state Playing
    EnqueueBuffers();
        buffers[n].OnDone()  //tune (short because if debug step)

            internal bool OnDone()
            bytes = waveStream.Read(buffer, 0, buffer.Length);
                buffer        = {byte[57600]}
                buffer.Length = 57600
            //then  
            for (int n = bytes; n < buffer.Length; n++)
                {
                    buffer[n] = 0;
                    }
                    
                    WriteToWaveOut();

                private void WriteToWaveOut()
            {
                MmResult result;

                lock (waveOutLock)
                {
                result = WaveInterop.waveOutWrite(hWaveOut, header, Marshal.SizeOf(header));
                }
                if (result != MmResult.NoError)
                {
                throw new MmException(result, "waveOutWrite");
                }

                GC.KeepAlive(this);
            }                       
                    
                    
                    result = WaveInterop.waveOutWrite(hWaveOut, header, Marshal.SizeOf(header));
                    => tune                 
more in next answer...

New Post: Help for Exception: NAudio.MmException "UnspecifiedError calling waveOutOpen"

$
0
0
Hello mark,
in a second step I find out more. It doesn't depends only on the frequency of 44.100 khz.
I have the audio driver: Realtek Semiconductor Corp. (Vers 6.0.1.7885) from 19.07.2016

The error depends on what I defined in the Windows dialog "Realtek HD Audio Mananger" from "Realtek High Definition Audio" in the tab "Standardformat":
if I define there 24 bits / 48.000 (studio sound)  -> error in  NAudio when set .SetWaveFormat(48000, 2); 
if I define there 16 bits / 48.000 (DVD sound)     -> error in  NAudio when set .SetWaveFormat(48000, 2); 
if I define there 24 bits / 44.100 (studio sound)  -> error in  NAudio when set .SetWaveFormat(44100, 2); 
if I define there 16 bits / 44.100 (CD sound)       -> error in  NAudio when set .SetWaveFormat(44100, 2); 
For every frequency which is setting to "Standardformat" for the audio card in NAudio "waveOutHandle" get "0", means get no handle. And then NAudio crashes.

Is there a way we can fix this?

May be there is a step left in the code that, with other words, the code should has "asked": "hello audio card - if you blocked for that frequency? - yes! then give it free - and then try to get the handle to it? - other give the handle without freeing it.

But I don't now how to do that. It should be done elsewhere in NAudio code.
Maybe anything must be done in the unmanaged code, what is calling from C# - yet, I haven't understand der NAudio code very much.

Or have you a other idea for a workaround? It would be bad if anyone have a Realtek soundcard and use the same settings as I do in my program and it will crashed every time.

New Post: Help for Exception: NAudio.MmException "UnspecifiedError calling waveOutOpen"

$
0
0
Maybe its IEEE float that's causing the issue. You could try opening at 16 bit.

If the soundcard is really blocking a particular frequency, then you'd have to insert a resampler into your pipeline. NAudio has a DMO based resampler you could try.

Commented Unassigned: NAudio.SoundFont.InfoChunk exception [16476]

$
0
0
NAudio.SoundFont.InfoChunk throws an unnecesary exception if some of the information chunks are missing even though they're optional, makes it harder to load some of the SF2 files.
Comments: thanks for reporting. which chunks in particular?

Commented Unassigned: [Window Store Apps] Construct MediaFoundationReader from StorageFile [16471]

$
0
0
In WinRT, files are better identified by a StorageFile object rather than a path string. This is due to the reasons that 1. non-conventional file systems (such as cloud drives) are supported and 2. file access rights are much more restrictive compared to desktop applications. E.g. trying to open an arbitrary file on the file system usually causes a UnauthorizedAccessException. However, if that same file was obtained by a FileOpenPicker control, it is possible to open that file - but only by using the obtained StorageFile object.

It would be great if the MediaFoundationReader supports that, too. I.e. just supply a StorageFile instead of a path to its constructor. A viable alternative would be to open the file in the App and to supply some IRandomAccessStream instead,
Comments: Yes, would be a good addition. you may find the AudioGraph API in UWP already gives you what you need.
Viewing all 5831 articles
Browse latest View live


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