Exemplo n.º 1
0
        public byte[] adjustSpeed(byte[] data, double speedFactor)
        {
            MemoryStream msInput      = new MemoryStream(data);
            MemoryStream msOutput     = new MemoryStream();
            string       tempfilename = $"{DateTime.Now.ToFileTimeUtc()}.wav";

            using (var reader = new WaveFileReader(msInput))
            {
                var stupidIeeeNecessity = WaveFormat.CreateIeeeFloatWaveFormat(reader.WaveFormat.SampleRate, reader.WaveFormat.Channels);
                using (var resampler = new MediaFoundationResampler(reader, stupidIeeeNecessity))
                {
                    WaveFileWriter.CreateWaveFile(tempfilename, resampler);
                }
            }

            using (var ieeeReader = new WaveFileReader(tempfilename))
            {
                var stwp = new SoundTouchWaveProvider(ieeeReader);
                stwp.Tempo = speedFactor;
                WaveFileWriter.WriteWavFileToStream(msOutput, stwp);
            }

            File.Delete(tempfilename);
            return(msOutput.ToArray());
        }
Exemplo n.º 2
0
        public static string finalLapMaker(string path, double factor)
        {
            int    indexof = path.LastIndexOf('_');
            string newpath = path.Substring(0, indexof) + "_f.wav";

            if (Char.IsUpper(path[indexof + 1]))
            {
                newpath = path.Substring(0, indexof) + "_F.wav";
            }

            string temppath = path.Substring(0, indexof) + "_ieeetemp.wav";

            using (var reader = new WaveFileReader(path))
            {
                var outFormat = WaveFormat.CreateIeeeFloatWaveFormat(reader.WaveFormat.SampleRate, reader.WaveFormat.Channels);
                using (var resampler = new MediaFoundationResampler(reader, outFormat))
                {
                    WaveFileWriter.CreateWaveFile(temppath, resampler);
                }
            }

            using (var input = new WaveFileReader(temppath))
            {
                var stwp = new SoundTouchWaveProvider(input);
                stwp.Tempo = factor;
                WaveFileWriter.CreateWaveFile(newpath, stwp);
            }

            return(newpath);
        }
Exemplo n.º 3
0
        public override PlaybackStates Play(Track track, WaveOutEvent player, string speed)
        {
            if (lastPlayback != track.FilePath)
            {
                player.Stop();
                lastPlayback = track.FilePath;
            }

            if (player.PlaybackState == PlaybackState.Stopped)
            {
                var audioFile = new AudioFileReader(track.FilePath);

                var output = new SoundTouchWaveProvider(audioFile);


                if (speed == "0.5x")
                {
                    output.RateChange = -50;
                }
                if (speed == "1.0x")
                {
                    output.RateChange = 0;
                }
                if (speed == "1.5x")
                {
                    output.RateChange = +50;
                }
                if (speed == "2.0x")
                {
                    output.RateChange = +100;
                }

                player.Init(output);
            }

            player.Play();
            return(new StatePaused());
        }