Example #1
0
 public virtual void PlayAudioFile()
 {
     string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
     string wavFile = Path.Combine (currentDirectory, "example.wav");
     WaveFileReader reader = new WaveFileReader (wavFile);
     Wave16ToFloatProvider converter = new Wave16ToFloatProvider (reader);
     Analyser analyser = new Analyser ();
     _client.ProcessFunc += analyser.AnalyseOutAction;
     _jackOut.Init (converter);
     _jackOut.Play ();
     Thread.Sleep (100);
     _jackOut.Stop ();
     reader.Close ();
     Assert.AreNotEqual (0, analyser.NotEmptySamples);
 }
 public static void ApplyAutoTune(string fileToProcess, string tempFile, AutoTuneSettings autotuneSettings)
 {
     using (var reader = new WaveFileReader(fileToProcess))
     {
         IWaveProvider stream32 = new Wave16ToFloatProvider(reader);
         IWaveProvider streamEffect = new AutoTuneWaveProvider(stream32, autotuneSettings);
         IWaveProvider stream16 = new WaveFloatTo16Provider(streamEffect);
         using (var converted = new WaveFileWriter(tempFile, stream16.WaveFormat))
         {
             // buffer length needs to be a power of 2 for FFT to work nicely
             // however, make the buffer too long and pitches aren't detected fast enough
             // successful buffer sizes: 8192, 4096, 2048, 1024
             // (some pitch detection algorithms need at least 2048)
             var buffer = new byte[8192];
             int bytesRead;
             do
             {
                 bytesRead = stream16.Read(buffer, 0, buffer.Length);
                 converted.Write(buffer, 0, bytesRead);
             } while (bytesRead != 0 && converted.Length < reader.Length);
         }
     }
 }
Example #3
0
        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)
            {
            }
        }
Example #4
0
 public virtual void PlayAudioFilePaused()
 {
     string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
     string wavFile = Path.Combine (currentDirectory, "example.wav");
     WaveFileReader reader = new WaveFileReader (wavFile);
     Wave16ToFloatProvider converter = new Wave16ToFloatProvider (reader);
     _jackOut.Init (converter);
     _jackOut.Play ();
     _jackOut.Pause ();
     Thread.Sleep (100);
     _jackOut.Stop ();
     Assert.AreEqual (0, reader.Position);
     reader.Close ();
 }