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: Losing the WaveMixerStream32 helped a lot! Thanks. The short files now play nicely. Here's my current rapid-hack code: WaveOut playbackDevice = new WaveOut(); AudioFileReader samp2 = new AudioFileReader(<FileOne>); AudioFileReader samp3 = new AudioFileReader(<FileTwo>); MixingSampleProvider mixy = new MixingSampleProvider(new List<ISampleProvider> { samp2, samp3 }); playbackDevice.Init(new SampleToWaveProvider(mixy)); playbackDevice.PlaybackStopped += Stopped; playbackDevice.Play(); Thread.Sleep(TimeSpan.FromSeconds(60.0)); // Prevent program from closing before files are done. Function Stopped simple prints "Stopped" to the terminal. If I put 1-second files in one and two, it mixes them nicely. It does exactly what I want them to do. If I put 16-second files in one and two, it mixes them correctly but stops playing them after about 1 second. How come? I'd like to be able to play long music files and short effects. I imagine I'd use a MixingSampleProvider to mix it all together. I've seen it has functions: AddMixerInput, RemoveMixerInput. Perfect! But it needs to be able to handle a single 60-second file playing, and then suddenly mixing in a 1-second file. And then another! And then the same one again! Am I on the right track to getting this set up?
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: Losing the WaveMixerStream32 helped a lot! Thanks. The short files now play nicely. Here's my current rapid-hack code: WaveOut playbackDevice = new WaveOut(); AudioFileReader samp2 = new AudioFileReader(<FileOne>); AudioFileReader samp3 = new AudioFileReader(<FileTwo>); MixingSampleProvider mixy = new MixingSampleProvider(new List<ISampleProvider> { samp2, samp3 }); playbackDevice.Init(new SampleToWaveProvider(mixy)); playbackDevice.PlaybackStopped += Stopped; playbackDevice.Play(); Thread.Sleep(TimeSpan.FromSeconds(60.0)); // Prevent program from closing before files are done. Function Stopped simple prints "Stopped" to the terminal. If I put 1-second files in one and two, it mixes them nicely. It does exactly what I want them to do. If I put 16-second files in one and two, it mixes them correctly but stops playing them after about 1 second. How come? I'd like to be able to play long music files and short effects. I imagine I'd use a MixingSampleProvider to mix it all together. I've seen it has functions: AddMixerInput, RemoveMixerInput. Perfect! But it needs to be able to handle a single 60-second file playing, and then suddenly mixing in a 1-second file. And then another! And then the same one again! Am I on the right track to getting this set up?