Exemple #1
0
 private static void ReadFromTestProvider(int bytesToRead, int bufferSize)
 {
     TestWaveProvider source = new TestWaveProvider(44100, 1);
     AutoTuneWaveProvider autoTune = new AutoTuneWaveProvider(source);
     byte[] buffer = new byte[bufferSize];
     int bytesRead = 0;
     while (bytesRead < bytesToRead)
     {
         bytesRead += autoTune.Read(buffer, 0, buffer.Length);
     }
 }
Exemple #2
0
 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);
         }
     }
 }
 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);
         }
     }
 }
Exemple #4
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)
            {
            }
        }