NAudio and Windows 10
It’s about time I gave an update on Windows 10 and NAudio. The NAudio solution had a Universal Windows project added by Kamen Litchev a while back, and I recently updated this to support the RTM Windows 10 SDK (version 10240). This required editing the project files directly to point to the latest SDK number, and you also now need to supply a project.json
file, or the dependencies on the .NET Core assemblies will be missing and you’ll get thousands of errors.
There is a very basic demo Windows Universal app that lets you play a file. You’ll need to turn on Developer Mode in Windows 10 to enable deploying it so you can debug.
Rather concerningly, the NAudio UWP project builds with lots of warnings about various COM interop features going obsolete. For example 'VarEnum' is obsolete: 'Marshalling VARIANTs may be unavailable in future releases.'
I’m not quite sure what will happen if the ability to marshal variants is taken away, as that is pretty key to a lot of the Media Foundation wrappers.
Obviously you can still use the regular NAudio assemblies in Windows 10. So far, I haven;t noticed any existing audio APIs being taken away, so you can still use WaveOut
, and the ACM functions if you want.
I had a quick look to see if there are any new codecs available on Windows 10 machines. It seems there is an Apple lossless (ALAC) decoder and encoder as well as the long awaited FLAC encoder and decoder. So I’ll be updating the MediaFoundationEncoder
class to make it easier to perform FLAC encoding.
Windows 10 introduces the brand new Audio Graph API. This enables a number of interesting audio applications without the need to use NAudio at all. I’m planning to explore the capabilities of this API further over the coming weeks and see in what ways it compliments what we already have in NAudio.
Finally, I need to research what the best way to put Universal Windows assemblies into NuGet packages is, but once I have done so, I’ll get a UWP NAudio build up into NuGet.
Comments
Firstly Mark, thank you for creating and supporting this NAudio project. I've listened to both of your courses on Pluralsight and they were instrumental in my learning about audio signals and analyzing them. I am still fascinated by the digital representation of sound... and I can't believe it works that way. :)
JohnTo add to the Windows 10 mystery for me, I have a project that was using MediaFoundationReader for an .mp4 file. On a non-Windows 10 system (Win7), this works perfectly. File is reported as a 1-channel, 16-bit sample, 24000Hz stream, file size is 6,443,520 (a 2:14:24 duration file). My application reads in the file from the reader just fine.
However, on my Windows 10 machine the same file (in the same test/api) is reported as a 2-channel, 16-bit sample, 48000Hz stream with a file size of 25,774,080 bytes. I try to read past 6,445,056 bytes and I get an exception (EndOfStreamException in .NET). I downloaded the source for NAudio and I am getting mangled audio in the MediaFoundationDemo for the file as well. As another test, the Windows 10 Media player appears to play the file correctly (default player when I just open the file directly).
Can you offer any guidance to alleviate this problem or just a confirmation that there is an issue? I would actually be glad to help track it down as well if possible, but you'd probably be able to give some great direction! Thanks for reading, and again THANK YOU for saving me hours of time in analysis of audio files!
oh dear, that's a bit concerning. I've just done a quick test playing some mp4 audio on my Win 10 system with the NAudio demo app, and there doesn't seem to be an issue. Your MP4 file is perhaps a little on the unusual side (24kHz), but if the Win10 media player can play it, it's strange that NAudio can't. Is there any chance you can share the file?
Mark HeathThanks so much for the reply Mark - I'm pretty sure I can just share it, but I have to double check due to my client relationship with the company that generated the file (the downside of being a consultant!). I will do that tomorrow morning and send it (or one very similar) over to you. Thanks again.
JohnMark, I sent you a message with a link to the file to your BitBucket account. Let me know if you'd like me to send some other way. Thanks so much for taking a look and I'm very curious about what you find!
Johnhey John, a strange problem, and yes it does seem Win 10 behaves differently. I've checked in a fix to the NAudio source over at GitHub and it will be part of the next release
Mark HeathAwesome Mark, thanks for reviewing it. I'll go ahead and pull it from Git and have a look. You've reduced some technological debt due to Windows 10 (I couldn't resist the PluralSight reference). Cheers from across the pond!
JohnHi Mark, thanks for your support in UWP!
Licantrop0I installed the version 1.7.2 in my Windows 10 app, but I can't find the WaveFileReader, only NAudio.Wave.WaveFormat class... I need to get the total duration of SynthesizeTextToStreamAsync wav stream (I have to wait for the speech to end to start voice recognition). Unfortunately I can't put the MediaElement to play the stream in the VisualTree, so I don't get any NaturalDuration or MediaEnded events...
I'm afraid WaveFileReader isn't in the UWP package - file streams are handled differently in WinRT apps, and so I need to rework those parts of the framework
Mark HeathIt seems that SpeechSynthesizer.SynthesizeTextToStreamAsync outputs a malformed WAVE FMT header (SamplesPerSec and AvgBytesPerSec are inverted in position, and AvgBytesPerSec seems off anyway), can you check it out?
Licantrop0Ultimately, I solved using BackgroundMediaPlayer to get natural duration, but I had to divide the value empirically by 2 because it is always double than the output wave (recorded and measured manually with Audacity).
Suppression State Error Cannot resolve Assembly or Windows Metadata file 'System.Windows.Forms.dll'
Andranik DharaThis error pops up after I include NAudio to my Windows 10 project , I need NAudio and I cant find any other available API's to get the waveform of a sound wave .. please help me ,, and @markheath1010:disqus your project is awesome !!! Loved It !!! :D
you can't use the main NAudio DLL in a Windows 10 project. However, if you look in the NAudio source code you'll see that there is an NAudio.Universal dll which contains a subset of NAudio supported in UWP
Mark HeathHey mark include a FFT project to the NAudio.Universal if you get time , its really needed !! I wanted to build it , but I know nothing of Audio Engineering !!
Andranik DharaBtw can you tell me if I can use the AudioBuffer class and use it to plot WaveForm or some sort of frequency spectrum analyzing ?? I would be grateful to you !! Xx-ThankYou-xX
Can't remember if the FFT is already in NAudio.Universal but there's no reason why it couldn't be added, as its fully managed
Mark Heathi hope you can give us a sample of network chat using windows IOT. many thanks.
kits@workhi there, you'd want to try the new AudioGraph API to make network chat for Windows IoT. If you have access to Pluralsight course, I made a whole course about this API, which you can use in Windows IoT: http://www.shareasale.com/r...
Mark Heaththanks, i hope you can give sample when receiving audio stream from UDP then playing it. just like like your sample in Naudio network chat.
kits@workI have no plans to create one at the moment, but if I do I'll blog about it
Mark Heathi just really want to play sound inside this method, but i don't know how, even if had watched your video :(
kits@workasync void MessageReceived(DatagramSocket socket, DatagramSocketMessageReceivedEventArgs args)
{
DataReader reader = args.GetDataReader();
uint len = reader.UnconsumedBufferLength;
string msg = reader.ReadString(len);
var incomingStream = args.GetDataStream().AsStreamForRead();
var writeStream = _stream.AsStreamForWrite();
var buffer = new byte[1024];
int bytesRead;
}
Hi Mark,
disqus_B7N90EE2CwI'm just getting exploring NAudio and it is awesome. I have listened to your series on PluralSight. I just want to experiment with a UWP app. I your example code on PluralSight you have a sample, Voice Recorder, where you are taking input from microphone and displaying it on a progressbar and have a slider that adjusts the sensitivity. I was not successful in doing this with NAudio in a UWP app because I cannot get a WaveIn.
My question is how do I replicate that exact example in a UWP application?
Cheers.
did you see my UWP Audio course on Pluralsight? AudioGraph can be an easier way to go than NAudio in UWP. There is a demo in the NAudio universal solution of using WasapiCaptureRt if you want to see how to capture samples with NAudio though.
Mark HeathHey Mark...Thanks for UWP support and version 1.8. I'm begging for an example using the RT waveFileWriter. Also...correctly stopping as the writer has no Close...just Dispose.
tim ryanhi there, I'm afraid the RT wave file writer was contributed by someone else, so I haven't actually used it myself yet. Will put it on the TODO list to include an example of using it in the UWP demo app
Mark HeathI have it writing...produces a garbled , speedy .wav. Do you know if you have to create the reader when recording? Simple example soon will beat bass to the punch, which doesn't have a UWP writer..
tim ryangarbled speedy wav sounds like wrong waveformat
Mark HeathHello, I would like to generate Wave visuals for the music files in UWP (windows 10), Can you please let me know is it doiable and is it possible to point to the git repo .
Rohith VijayaI haven't got a UWP waveform sample, but basically the WPF visualization examples in the NAudio WPF demo app are XAML based, which means that there is a good chance it will work with minimal modification in UWP. Also look at this sample I created for WPF waveform rendering: https://bitbucket.org/markh...
Mark HeathI tried to update the WasapiCaptureRT class to allow loopback capture, but it seems impossible to do that in UWP as you can't initialize the output device with the capture property as COM activation is not enabled for the MMDeviceEnumerator in UWP :(
Darrell EmThe DeviceInformation classes don't help in this situation either. Gutted.
yes I seem to remember trying and failing to get that working a while back.
Mark Heath