Пример #1
0
        public void ApplyEffects(IEffectsOptions options)
        {
            var mp3Path = options.Mp3File;

            this.PitchEffect.Semitones = options.Semitones;

            var tasksCount = 5;

            this.ProgressNotifier.Initialize(tasksCount, "Change the pitch of the mp3 file");

            this.ProgressNotifier.Tick("Read mp3 file...");
            var inMp3Bytes = File.ReadAllBytes(mp3Path);

            this.ProgressNotifier.Tick("Convert to wav...");
            var inWavBytes = AudioUtils.Mp3ToWav(inMp3Bytes);

            var waveSamples = AudioUtils.WavToWaveSamples(inWavBytes);
            var sampleRate  = waveSamples.WaveFormat.SampleRate;
            var samples     = waveSamples.Samples;

            this.InitializeEffects(sampleRate);

            this.ProgressNotifier.Tick("Apply effects...");
            this.ProcessSamples(samples, 0, samples.Length, waveSamples.WaveFormat);

            var outWavBytes = AudioUtils.WaveSamplesToWav(waveSamples);

            this.ProgressNotifier.Tick("Convert to mp3...");
            var outMp3Bytes = AudioUtils.WavToMp3(outWavBytes);
            var outMp3Path  = options.OutputFile;

            if (string.IsNullOrEmpty(outMp3Path))
            {
                outMp3Path = GetOutputMp3Path(mp3Path, options.Semitones);
            }

            this.ProgressNotifier.Tick("Save mp3 file...");
            File.WriteAllBytes(outMp3Path, outMp3Bytes);

            this.ProgressNotifier.UpdateMessage("Finished!");
        }
Пример #2
0
        private int ApplyEffects(IEffectsOptions options)
        {
            if (options.Semitones == 0)
            {
                MessageBox.Show("Changing the pitch by 0 semitones does not alter the original audio. Skipping.");
                return(0);
            }

            try
            {
                var progressBar = new ProgressBarProgressNotifier(this.ProgressBar, this.ProgressLabel);
                var pipeline    = new AudioPipeline(progressBar);
                pipeline.ApplyEffects(options);

                return(0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(-1);
            }
        }
Пример #3
0
        private static int Run(IEffectsOptions options)
        {
            if (options.Semitones == 0)
            {
                Console.WriteLine("Changing the pitch by 0 semitones does not alter the original audio. Skipping.");
                return(0);
            }

            try
            {
                using (var progressBar = new ProgressBarProgressNotifier())
                {
                    var pipeline = new AudioPipeline(progressBar);
                    pipeline.ApplyEffects(options);
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(-1);
            }
        }