This project has moved and is read-only. For the latest updates, please go here.

Novice Questions Related To Using NAudio for Onset Detection

Dec 9, 2014 at 4:33 PM

I'm looking to use NAudio for Onset Detection and am currently trying to draw from a number of different sources ( , but my overall lack of understanding of how NAudio works is leaving me at a bit of a loss.

My basic goals at the moment are to;
  • Successfully load a .wav. file and be able to access the PCM data of that file.
  • Check if that .wav file is in stereo, and if so, average the two channels into one.
  • Check/Know if the data is in 16bit signed integer and convert it to float
However, I can't really be sure whether I'm on the track with these because of the following issues.

First off, if I load a .wav audio file using a WaveFileReader
wavReader = new WaveFileReader(mPath);
does wavReader now contain the PCM data for that audio file? And if so, where is it stored and how is it structured?

Secondly, if I assume that wavReader contains the data 16bit signed integers, will the following code convert that data into floats?
stream32 = new Wave16ToFloatProvider(wavReader);
Apologies for the basic questions, but I haven't been having any luck finding these things out from the documentation and attempting to sort through variables in debug isn't casting any light on the situation either.

Just for reference, I am attempting to use NAudio in a Unity project, with the 'NAudio' and 'NAudio.WindowsMediaFormat' dll's situated in the 'Plugins' folder of my project.

Any help would be greatly appreciated!
Dec 28, 2014 at 8:23 PM
WaveFileReader will return data from the read method in whatever format is in the WAV file. This might be PCM 16 bit (which is most common), but it can in fact be almost anything. If it is 16 bit, then Wave16ToFloatProvider will do what you want, or more simply, use the ToSampleProvider() extension method to get the ability to read floating point samples directly without having to extract them from byte arrays