This project has moved. For the latest updates, please go here.

NAudio in a game ?

Mar 18, 2014 at 10:33 PM
Hello, I'm really interested in using NAudio with the Unity game engine to implement it with a game I'm working on. However, after reading the docs and checking the example projects I still have a pretty basic question that I can't answer myself and will appreciate greatly if somebody answered briefly to it:
  • I've written various algorithms for beat detection, melody analysis, etc. they currently work with FMOD in real-time while the game is playing (which is bad because different framerate affects the audio analysis). These algorithms use the spectrum and wave data from the currently playing audio file. Will I be able to get the spectrum and wave data from certain audio times before the game loads? (in other words, will analyzing audio before the game loads be possible with NAudio?)
    e.g. On 0.015 seconds, get the frequencies from 20Hz to 4Khz, get Wave samples, run the algorithms, save the results and move on to the next time -> 0.03 (do the same) ?
    And if this is possible, how fast/slow would that be ? Let's not take any audio analysis algorithms into account, would just pulling data with a 0.015 seconds interval until the end of the audio file be too slow ?
Thank you for your time! I hope my question isn't too stupid.
Coordinator
Mar 28, 2014 at 11:58 AM
NAudio can give you access to individual samples, so you should be able to perform any of your algorithms. As for speed, it probably won't be as fast as doing it in C/C++, but if you profile your code, you should be able to find ways to speed it up.
Mar 28, 2014 at 12:33 PM
Thank you! I've been using it for several days now and I find it's speed pretty sufficient for our game's needs. I haven't still managed to make the spectrum analysis work so I cannot tell for sure.
Mar 29, 2014 at 3:01 PM
not sure if you've seen this. For the spectrum analysis you can look here https://wpfsvl.codeplex.com/ they have an NAudio sample for WPF. It could help you see how NAudio spec analysis is done.
Mar 30, 2014 at 10:59 AM
Yeah, I have the source code for this but to be honest I'm having trouble finding my way around it. I actually made another topic here asking about getting the spectrum and wave data specifically prior to playing the audio. However, I'm still dwelling on this so I hope that even if no one answers, I'll be able to get something to work soon :)