public void RightChannelOnly() { IWaveProvider stereoStream = new TestStereoProvider(); StereoToMonoProvider16 mono = new StereoToMonoProvider16(stereoStream); mono.LeftVolume = 0.0f; mono.RightVolume = 1.0f; int samples = 1000; byte[] buffer = new byte[samples * 2]; int read = mono.Read(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length, read, "bytes read"); WaveBuffer waveBuffer = new WaveBuffer(buffer); short expected = 0; for (int sample = 0; sample < samples; sample++) { short sampleVal = waveBuffer.ShortBuffer[sample]; Assert.AreEqual(expected--, sampleVal, "sample #" + sample.ToString()); } }
private void LoadSample(Map map) { try { int index = 0; foreach (Channel channel in map.Channels) { foreach (Sample sample in channel.ListSample) { List<int> listIndexSample = new List<int>(); dicSample.Add(sample.Name, listIndexSample); for (int i = 0; i < CountInstancePerSample; i++) { WaveStream outStream = new WaveFileReader(sample.FileName); //--- Détection de la fréquence moyenne du son if (i == 0 && sample.Frequency == -1f) { //======= IWaveProvider waveFloat = null; if (outStream.WaveFormat.Channels > 1) { StereoToMonoProvider16 stereo = new StereoToMonoProvider16(outStream); stereo.LeftVolume = 1f; stereo.RightVolume = 1f; waveFloat = new Wave16ToFloatProvider(stereo); } else { waveFloat = new Wave16ToFloatProvider(outStream); } IWaveProvider outStream2 = new AutoTuneWaveProvider(waveFloat); IWaveProvider wave16 = new WaveFloatTo16Provider(outStream2); byte[] buffer = new byte[8192]; int _bytesRead; do { _bytesRead = wave16.Read(buffer, 0, buffer.Length); //writer.WriteData(buffer, 0, _bytesRead); } while (_bytesRead != 0);//&& writer.Length < waveFileReader.Length); //writer.Close(); //======= outStream.Position = 0; //---> Fréquence sonore du sample sample.Frequency = ((AutoTuneWaveProvider)outStream2).Frequency; //---> Note sur un clavier de 88 touches pour la fréqence sample.NoteKey = (12f * (float)Math.Log(sample.Frequency / 55f) + 13f * (float)Math.Log(2f)) / ((float)Math.Log(2f)); Debug.WriteLine(sample.Name + " == " + sample.Frequency.ToString() + " == " + sample.NoteKey.ToString()); } //--- outStream = WaveFormatConversionStream.CreatePcmStream(outStream); outStream = new BlockAlignReductionStream(outStream); reader[index] = outStream; offsetStream[index] = new EffectStream(CreateEffectChain(sample), reader[index]); channelSteam[index] = new WaveChannel32(offsetStream[index]); channelSteam[index].Position = channelSteam[index].Length; mixer.AddInputStream(channelSteam[index]); listIndexSample.Add(index); index++; } sample.Duration = channelSteam[dicSample[sample.Name][0]].TotalTime; } } } catch (Exception ex) { } }