30 Days of NAudio Documentation
One of the criticisms I often get about NAudio is that the documentation isn’t good enough. And although I have written numerous tutorials and articles about it (as well as two Pluralsight courses), I do accept that there is a lot of scope for improvement.
So I decided in November to see if I could write a short article or tutorial a day and use it to form the basis for a new set of documentation, especially now that CodePlex (which was the old home for NAudio documentation) is being shut down.
I’ve implemented the documentation as markdown files in the GitHub repo, to make it as simple as possible to allow community contributions and improvements. I’ve just about managed to keep up with the goal of a document a day.
Hopefully I’ll be able to add to and expand on this list in the future, to make NAudio much more accessible to new beginners. I’m also planning to insist on contributors of new features adding a tutorial of their own to ensure the the documentation remains comprehensive going forwards.
Here’s the full list of new articles I’ve written this month:
Playback
- Playing an Audio File from a WinForms application
- Playing an Audio File from a Console application
- Playing Audio from a URL
- Choose an audio output device type
- Enumerate and select Output Devices
- Creating and configuring a WasapiOut device
- Handling playback stopped
- Understanding WaveStream, IWavePlayer and ISampleProvider
Working with Codecs
- Convert an MP3 to WAV
- Encode to MP3 and other formats using MediaFoundationEncoder
- Enumerate Media Foundation Transforms (MFTs)
- Enumerate ACM Codecs
Working with audio files
Manipulating audio
- Convert between mono and stereo
- Concatenating Audio
- Skip and Take Using OffsetSampleProvider
- Using RawSourceWaveStream
- Adjust the pitch of audio using SmbPitchShiftingSampleProvider
Comments
Hi Mark,
samrat matteIs naudio compatible with asp.net too? How can I get real time audio stream from microphone for a radio?
yes, although it would be running server side not client side, so you'd typically only use it for generating files. NAudio does not contain any specific code for streaming audio from a web server, although there are some network streaming examples in the NAudio demo apps that could possibly be adapted to a web scenario
Mark HeathThanks Mark.
samrat mattehi mark
Peter Akakpoi want to get both the left and right peak values from an audio data, how do i go about that?. i have read "Calculating Peak Values" but the calculated value is for one channel.
Well left and right samples are interleaved, so you just loop the samples in pairs through maintaining separate peak values for each channel
Mark HeathHi Mark, I'm using your NAudio librarian in my project, but I'm facing a big problem which is this: I use the ConcateningSampleProvider as an Array
Kaoe FerreiraExample: ConcateningSampleProvider [] sampleProv = new ConcateningSampleProvider [audiosTrack.Count];
Where: audiosTrack is a List of ISampleProvider
Example: List <list <isampleprovider="">> audiosTracks;
I'm adding the songs like this:
audiosTracks [indexTrackCurrent] .Add (new AudioFileReader (newPathFile) .ToMono ()); // ToStereo the problem continues.
In this, at the time of concatenating, within a For loop, I have this line:
concatenatingTracks [i] = new ConcatenatingSampleProvider (audiosTracks [i] .ToArray ());
The Code itself works. He concatenates everything right and also his mix is correct. The problem is that it cuts the audio! The original Audio has 8 seconds in total, but by the time it concatenates and saves the folder by clicking the song, it plays for only 4 seconds thus ending.
It is an important and great project, I need to solve this problem and I do not know where else to go. I need your help
Thank you very much for your attention.
Obs: I'm using in a project on Unity 2018.2.18f
I appreciate the effort to make demos and tutorials, but in my opinion the first document that a developer needs is a namespaces/classes/... reference in PDF or CHM or equivalent format. This helps the developer to quickly find how to use a class, how to call a function. Demos and tutorials are very good tools to learn the basic of the library, but their use is time consuming during the development phase.
Angelo MascaroDear Mr Heath,
Filip D. WilliamsI made a UserControl to play an MP3, with a slider, so that when I use two or more Usercontrols I can play the MP3 and use the slider to lower the volume apart for each MP3. Using the Volume control on WaveOut() itself worked, but then the volume of all UserControls went up and down. So I found somewhere I should use a SampleChannel and set the Volume there : BINGO. But now, when I listen using my headphones, and set the Headphone volume on the computer to 100%, the volume is much lower than not using the SampleChannel.... Weird
private void slider1_Scroll(object sender, ScrollEventArgs e)
{
if (_inputStream != null) _inputStream.Volume = sliderVolume.Value / 100f;
}
private Mp3FileReader _fileStream;
private SampleChannel _inputStream;
private WaveOut _player;
private void button1_Click(object sender, EventArgs e)
{
_fileStream = new Mp3FileReader(_path);
_inputStream = new SampleChannel(_fileStream) {Volume = sliderVolume.Value / 100f};
_player = new WaveOut();
_player.Init(_inputStream);
_player.Play();
//player.PlaybackStopped += _player_PlaybackStopped;
}
What I have tried:
I tried to use directly the WaveOut() volume... worked, but then the slider lowered all the other mp3 volumes too. https://uploads.disquscdn.c...
Hi Mark. I could not find another way to gracefully contact you so am leaving a message on this post. My question is do you offer (or are willing to offer) paid consulting for NAUDIO implementations? Our specific requirement is to convert vox to either wav or mp3 and every attempt we try comes out distorted.
mfoitzik