I'm writing a game and I'd like to use NAudio to add sound to it. I followed a few examples and was rather pleased with NAudio's API and performance.
I ran into the following issue: NAudio will not play short audio files. I've used WaveChannel32.Length to get the following numbers.
Files with length 755712 or less will not play.
Files with length 5935104 do play.
I'm not sure where the exact limit is. There are no exceptions thrown. I was hoping to use NAudio to play files of about 1 second long. Is anyone else having this issue? Is there a fix? Do I need to find a different library?
Comments: Hehe, yes, it is a console app. But I'm running a 3D engine from there. The WaveOutEvent fixed this issue. Thanks once again. Now I have my short and long files loaded in, and I've linked them up to events in the game. Every time the mouse is moved over a button, I do this: sample.Position = 0; if(!isAdded) { isAdded = true; mixer.AddMixerInput(sample as ISampleProvider); } When the mouse is removed from the button it was over (guaranteed to occur), I do this: if(isAdded) { isAdded = false; mixer.RemoveMixerInput(sample); } Where mixer = MixingSampleProvider and sample = AudioFileReader. It seems that this works only once. The sample cannot be reset and re-added to the mixer. Can you help me? Additionally, at initialization, I do this: waveOutDevice = new WaveOutEvent(); ISampleProvider samp = new AudioFileReader(<AudioFile>); mixer = new MixingSampleProvider(new List<ISampleProvider> { samp }); waveOutDevice.Init(new SampleToWaveProvider(mixer)); waveOutDevice.PlaybackStopped += PlaybackStopped; waveOutDevice.Play(); I've found that creating a MixingSampleProvider with an empty List<ISampleProvider> causes a null-ref exception. So I've just added a sample at start-up. There's nothing wrong with a start-up jingle. But perhaps this is related to the issue?
I ran into the following issue: NAudio will not play short audio files. I've used WaveChannel32.Length to get the following numbers.
Files with length 755712 or less will not play.
Files with length 5935104 do play.
I'm not sure where the exact limit is. There are no exceptions thrown. I was hoping to use NAudio to play files of about 1 second long. Is anyone else having this issue? Is there a fix? Do I need to find a different library?
Comments: Hehe, yes, it is a console app. But I'm running a 3D engine from there. The WaveOutEvent fixed this issue. Thanks once again. Now I have my short and long files loaded in, and I've linked them up to events in the game. Every time the mouse is moved over a button, I do this: sample.Position = 0; if(!isAdded) { isAdded = true; mixer.AddMixerInput(sample as ISampleProvider); } When the mouse is removed from the button it was over (guaranteed to occur), I do this: if(isAdded) { isAdded = false; mixer.RemoveMixerInput(sample); } Where mixer = MixingSampleProvider and sample = AudioFileReader. It seems that this works only once. The sample cannot be reset and re-added to the mixer. Can you help me? Additionally, at initialization, I do this: waveOutDevice = new WaveOutEvent(); ISampleProvider samp = new AudioFileReader(<AudioFile>); mixer = new MixingSampleProvider(new List<ISampleProvider> { samp }); waveOutDevice.Init(new SampleToWaveProvider(mixer)); waveOutDevice.PlaybackStopped += PlaybackStopped; waveOutDevice.Play(); I've found that creating a MixingSampleProvider with an empty List<ISampleProvider> causes a null-ref exception. So I've just added a sample at start-up. There's nothing wrong with a start-up jingle. But perhaps this is related to the issue?