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

Adjust wav file amplitude and frequency

Nov 4, 2015 at 9:29 AM

I am working on a project where I am simulating the ground run of a jet engine. For this, I'm playing various sounds using NAudio and they all work fine. My problem is that when the engine is running and I adjust the throttle position I need to also adjust the amplitude and frequency of the EngineRunning sound. Is there a way to do this in NAudio? Failing that, is there a simple way to adjust the sound volume while it's playing? I had a quick look into using WaveChannel32 and adjusting the volume through that but I couldn't seem to get it to work. I am currently playing sounds using WaveOut and LoopStream as I need the sounds to keep playing until I change something in the simulation:
WaveFileReader mAudio = new WaveFileReader(mMap.GetFile(soundName));
LoopStream loop = new LoopStream(mAudio);
WaveOut mPlayer = new WaveOut(WaveCallbackInfo.FunctionCallback());
Any help would be greatly appreciated.

Nov 4, 2015 at 12:24 PM
A few bits of advice, first use WaveOutEvent instead of function callbacks which are prone to deadlocks. Second, you could use AudioFileReader which would give you a nice simple way to set the Volume. Note that the volume is not modified per sample, but per block of samples sent to the soundcard, so if you wanted to do gradual fades, it wouldn't be ideal. For that you'd want to create your own custom ISampleProvider.
You can also adjust the volume on the WaveOut / WaveOutEvent directly.
Nov 4, 2015 at 12:54 PM
Hey Mark,

Thanks for the quick response.

I've adjusted my code per your advice and it successfully plays at half volume:
AudioFileReader mAudio = new AudioFileReader(mMap.GetFile(soundName));
mAudio.Volume = 0.5f;
LoopStream loop = new LoopStream(mAudio);
WaveOutEvent mPlayer = new WaveOutEvent();
Just to clarify, is there any way to adjust the wav file amplitude or frequency? My volume solution works but I think that being able to adjust these values according to the movement of the throttle would give me a more representative application.