Hello guys, first NAudio library is awsome keep up the good work. :)
So I am using it with one of my project and I have created this class to play a sond when a intersection with rectangle is available :
publicclass Music {privatestring fileLocation;private IWavePlayer waveout;private WaveStream outputStream; WaveOutEvent audio ;public Drum(string file) {this.fileLocation = file;this.waveout = new WaveOut(); audio = new WaveOutEvent(); }static WaveStream CreateInputStream(string name) { WaveChannel32 inputStream;if (name.EndsWith(".wav")) { WaveStream readerStream = new WaveFileReader(name);if (readerStream.WaveFormat.Encoding != WaveFormatEncoding.Pcm) { readerStream = WaveFormatConversionStream.CreatePcmStream(readerStream); readerStream = new BlockAlignReductionStream(readerStream); }if (readerStream.WaveFormat.BitsPerSample != 16) {var format = new WaveFormat(readerStream.WaveFormat.SampleRate, 16, readerStream.WaveFormat.Channels); readerStream = new WaveFormatConversionStream(format, readerStream); } inputStream = new WaveChannel32(readerStream); }else {thrownew InvalidOperationException("Invalid extension"); }return inputStream; }publicvoid Play() { this.outputStream = CreateInputStream(this.fileLocation); audio.Init(outputStream); audio.Play(); } }
the problem is that I get this error when I intersect alot : AlreadyAllocated calling waveOutOpen.
My first question is how to resolve this error with the class above,and if you have time to correct my code will be greate. :)
My second question is: Is it possible to mix the sounds lets say that I have intersected with two rectangles and I want to mix the both sounds together, I now that NAudio have a mixer.