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: I've created a SilenceProvider that implements ISampleProvider. Like you said, it's pretty easy. But for potential future visitors: public class SilenceProvider : ISampleProvider { private readonly WaveFormat format; public SilenceProvider(WaveFormat format) { this.format = format; } public int Read(float[] buffer, int offset, int count) { for (int i = 0; i < count; i++) { buffer[offset + i] = 0; } return count; } public WaveFormat WaveFormat { get { return format; } } } I just pass it the WaveFormat of an actual sample so that I am certain that the formats match. NAudio now works exactly as I want it within my application. Thank you very much, markheath, for you time and support. I'd like to add your name and "NAudio" to the the credits list of my free game. (It will one day be finished, I think.) And sorry for messing up this thread... I took it quite off-topic there. But! I've gained a good insight into the workings of NAudio.
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: I've created a SilenceProvider that implements ISampleProvider. Like you said, it's pretty easy. But for potential future visitors: public class SilenceProvider : ISampleProvider { private readonly WaveFormat format; public SilenceProvider(WaveFormat format) { this.format = format; } public int Read(float[] buffer, int offset, int count) { for (int i = 0; i < count; i++) { buffer[offset + i] = 0; } return count; } public WaveFormat WaveFormat { get { return format; } } } I just pass it the WaveFormat of an actual sample so that I am certain that the formats match. NAudio now works exactly as I want it within my application. Thank you very much, markheath, for you time and support. I'd like to add your name and "NAudio" to the the credits list of my free game. (It will one day be finished, I think.) And sorry for messing up this thread... I took it quite off-topic there. But! I've gained a good insight into the workings of NAudio.