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

Commented Unassigned: Bug...pin the reference to the callback delegate [16495]

$
0
0
NAudio is a great library! Thanks for sharing it.
A bug fix for your review.

See \naudio_38dadb417edc\NAudio\Wave\MmeInterop\WaveCallbackInfo.cs line 75
My fix is to pin the delegate used by the WinMM callback...

private static WaveInterop.WaveCallback reference; // pin the reference to the callback delegate.
// the CG may choose to clean up the "pointer to the function" as no one is using it!
// except that WinMM is!

internal MmResult WaveOutOpen(out IntPtr waveOutHandle, int deviceNumber, WaveFormat waveFormat, WaveInterop.WaveCallback callback)
{
reference = callback;

if (reference == null)
throw new ApplicationException("callback is null");

MmResult result;
if (Strategy == WaveCallbackStrategy.FunctionCallback)
{
result = WaveInterop.waveOutOpen(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, callback, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackFunction);
}
else
{
result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);
}
return result;
}
I'm using your library in a "busy" .NET C# SDR application.

Comments: thanks for reporting this. any reason you made it static? that would break if more than one output device was in use at once

Commented Unassigned: Bug...pin the reference to the callback delegate [16495]

$
0
0
NAudio is a great library! Thanks for sharing it.
A bug fix for your review.

See \naudio_38dadb417edc\NAudio\Wave\MmeInterop\WaveCallbackInfo.cs line 75
My fix is to pin the delegate used by the WinMM callback...

private static WaveInterop.WaveCallback reference; // pin the reference to the callback delegate.
// the CG may choose to clean up the "pointer to the function" as no one is using it!
// except that WinMM is!

internal MmResult WaveOutOpen(out IntPtr waveOutHandle, int deviceNumber, WaveFormat waveFormat, WaveInterop.WaveCallback callback)
{
reference = callback;

if (reference == null)
throw new ApplicationException("callback is null");

MmResult result;
if (Strategy == WaveCallbackStrategy.FunctionCallback)
{
result = WaveInterop.waveOutOpen(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, callback, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackFunction);
}
else
{
result = WaveInterop.waveOutOpenWindow(out waveOutHandle, (IntPtr)deviceNumber, waveFormat, this.Handle, IntPtr.Zero, WaveInterop.WaveInOutOpenFlags.CallbackWindow);
}
return result;
}
I'm using your library in a "busy" .NET C# SDR application.

Comments: Hi Mark I will send code that will reproduce my issue. Yes, you're correct - my static cludge won't work on multiple devices. Nick

New Post: Bitrate

$
0
0
Hello, I'd like to know how to get or calculate the bitrate in kbps of a mp3-mediafile. I Need the information to display it in the media-panel

New Post: Minimal code to play (only) mp3

$
0
0
Hi,
I found your project to play mp3's and it works perfectly!
I would like to implement it in my exe (need only 2 functions):
  • mp3reader and waveout.
Is there a way to get a minimal version? My exe is only 300kb and integrating this, will increase it to 700kb.

It would be nice to have a minimal version that simply plays mp3, without utils, info about the song and so on.

Thanks,
Adriano

New Post: Reading/Resampling a wav file to a byte array

$
0
0
The error arises during the creation of the reader, which is needed before you use the WDL.

So I cannot get to the WDL step. Back in 8.1, you had to tell the reader what format it was expecting to read. Maybe its related?

The exception thrown is from the Read method of MediaFoundationReader.cs.

New Post: Saving unsigned PCM 8 bit to Wav is Noisy

$
0
0
I have recorded PCM 8000 Hz , 1 Channel ,8 bits from telephone device. I am then using the stream to WaveFileWriter to save it then to Wave file. the issue is that the generated audio file is very noisy. to Investigate I made :

1- Open PCM to other application , when try to set PCM to "unsigned" , i get the same noisy data as the wav file generated by NAudio. When I set the PCM as "Signed" , i get clear audio data.

2- When i open the PCM bytes, it is unsigned , ie data are from 0-255

my code for save the PCM stream is :

Private Mywriter As WaveFileWriter
Mywriter = New WaveFileWriter("D:\xxx.wav", New WaveFormat(8000, 8, 1)
Mywriter.Write(Buffer, 0, Buffer.Length) ' after receiving the PCM stream
Mywriter.Close() ' to push the wav file

kindly advice

New Post: Saving unsigned PCM 8 bit to Wav is Noisy

$
0
0
I have recorded PCM 8000 Hz , 1 Channel ,8 bits from telephone device. I am then using the stream to WaveFileWriter to save it then to Wave file. the issue is that the generated audio file is very noisy. to Investigate I made :

1- Open PCM to other application , when try to set PCM to "unsigned" , i get the same noisy data as the wav file generated by NAudio. When I set the PCM as "Signed" , i get clear audio data.

2- When i open the PCM bytes, it is unsigned , ie data are from 0-255

my code for save the PCM stream is :

Private Mywriter As WaveFileWriter
Mywriter = New WaveFileWriter("D:\xxx.wav", New WaveFormat(8000, 8, 1)
Mywriter.Write(Buffer, 0, Buffer.Length) ' after receiving the PCM stream
Mywriter.Close() ' to push the wav file

kindly advice

New Post: NAudio + PortAudio

$
0
0
Dear Mark, congratulations for the work done. Do you ever thought about the possibility of adding to framework an implementation of IWavePlayer for PortAudio? Something like PortAudioOut...
NAudio would be portable to other platforms like Mac and Linux.
I await your comments...

New Post: Playing/Analyzing 20ms segments of WAV file

$
0
0
Hi,

I'm having trouble using the component for the simple purpose I need.
I would like to have the DATA stream only inside my buffer (array) and then offset it for 20ms (and playing those segments in real-time.

I've tried using this:

WaveFileReader reader = new WaveFileReader(fullFileName);
             byte[] buffer = new byte[reader.Length];
            int read = reader.Read(buffer, 0, buffer.Length);
            short[] sampleBuffer = new short[read / 2];
            Buffer.BlockCopy(buffer, 0, sampleBuffer, 0, read);
I can see that sampleBuffer contains the data (real pos-neg values, which I don't get if I'm using byte[] sampleBuffer = File.ReadAllBytes(fullFileName); ).

I'm using the following WAV file:
  • Pcm 8000Hz 1 channels 16 bits per sample
  • Extra Size: 0 Block Align: 2 Average Bytes Per Second: 16000
  • WaveFormat: 16 bit PCM: 8kHz 1 channels
  • Length: 351360 bytes: 00:00:21.9600000

Commented Unassigned: Occasional AccessViolation in WDMAUD.DRV [16396]

$
0
0
Under load, I am getting an occasional AccessViolation in WDMAUD.DRV, and my application is crashing.

Comments: Is a fix available ?

Commented Unassigned: Occasional AccessViolation in WDMAUD.DRV [16396]

$
0
0
Under load, I am getting an occasional AccessViolation in WDMAUD.DRV, and my application is crashing.

Comments: was checked in ages ago so should be in the latest 1.7.3 release

New Post: Reading/Resampling a wav file to a byte array

$
0
0
Not knowing what to make of this error, I opened up the NAudio.Universal master code and ran it, and had the exact same exception. When I hit the 'load' button and feed it a .wav file it triggers an exception. Picture attached on OneDrive. The error appears on line 223 of MediaFoundationReader.cs Anyone have a clue? At least it's not something I did.

https://1drv.ms/i/s!Apomoggzevs3g9cUuVVCUQJOEzYyqA

System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'NAudio.MediaFoundation.IMFSourceReader'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{70AE66F2-C809-4E4F-8915-BDCB406B7993}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Source=mscorlib
StackTrace:
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at NAudio.MediaFoundation.IMFSourceReader.ReadSample(Int32 dwStreamIndex, Int32 dwControlFlags, Int32& pdwActualStreamIndex, MF_SOURCE_READER_FLAG& pdwStreamFlags, UInt64& pllTimestamp, IMFSample& ppSample)
   at NAudio.Wave.MediaFoundationReader.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.<>c.<BeginReadInternal>b__39_0(Object )
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
InnerException:

New Post: Can I use naudio to play the same mp3 to 2 output devices at the same time?

$
0
0
Greetings,

I have written a little "soundboard" app in visual studio that plays mp3 files triggered by button presses. Right now I'm simply using the System.Windows.Media MediaPlayer for that, so the sound is played using the currently selected sound output device in Windows. Now I would like to ALSO play the same sound (at the same time) to a second output device.

The reason is that I want to use the soundboard to play jingles, effects, etc. in a small quiz I do on a popular community Discord server. I have setup a Virtual Audio Cable (VAC) so that the Discord VoIP app takes the VAC output as its input device. The VAC has two input devices that it can mix, one of which is of course my microphone, and I want my WFP soundboard app to use the second VAC input as its output device (while at the same time also playing the sound using the default output device, so I can hear it in my headphones).

Can I use naudio to do that? If so, could you give me a little hint on how to start implementing this?

Thank you in advance!
Konadi

New Post: Reading/Resampling a wav file to a byte array

$
0
0
To get around this problem, I simply did not use the async version of the Read method. No errors that way.
var result = reader.Read(wavByteArray, 0, x);

New Post: Writing a wav from a buffer in a Store App

$
0
0
Ah, I managed to read a wav in to a byte[] called waveByteArray, and now want to write it back out again.

In the old nAudio, this used the WaveFileWriter. But in a UWP that's no longer there. What I see is WaveFileWriterRT.

So how do I get there from here?
I created the destination file in a user picked location:
            StorageFile destination = await storageFolder.CreateFileAsync("thisIsAtest.wav", CreationCollisionOption.ReplaceExisting);
I created the wav source provider:
var result = reader.Read(wavByteArray, 0, (int)reader.Length);

and tried to write it out like this:
await WaveFileWriterRT.CreateWaveFileAsync(destination.Path, reader);

I get an empty file. Suggestions? Examples?
Thanks.

!! Nevermind Got something to work by doing this.
                stream = await  destination.OpenAsync(FileAccessMode.ReadWrite);
                WaveFileWriterRT wfr_RT;
                wfr_RT = new WaveFileWriterRT(stream.AsStream(), waveformat);
                await wfr_RT.WriteAsync(wavByteArray, 0, (int)reader.Length);
                await wfr_RT.FlushAsync();

New Post: Prevent audio skip when recording during heavy system load.

$
0
0
I did have the same some time ago with an Usb device and was able to solve it by setting the priority class of my project to high somewhere at startup:
    Process.GetCurrentProcess.PriorityClass = ProcessPriorityClass.High

New Post: Writing a wav from a buffer in a Store App

New Post: Can I use naudio to play the same mp3 to 2 output devices at the same time?

$
0
0
There's no built-in easy way at the moment. One option would be to have one device being fed from a BufferedWaveProvider, and then insert something into the signal chain going to the first device to always copy its data into that BufferedWaveProvider.

New Post: Playing/Analyzing 20ms segments of WAV file

$
0
0
WaveFileReader.Read only returns data from the data chunk of the WAV file. You can use OffsetSampleProvider to achieve delays / skipping over portions of the file depending on your needs.

New Post: NAudio + PortAudio

$
0
0
It's not something I've ever needed myself, but it could be useful. It could be made as an extension project for NAudio.
Viewing all 5831 articles
Browse latest View live


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