Exemplo n.º 1
0
        private void ExportMP3File(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            var            audioItem      = AudioItemManager.GetAudioItem();

            if (audioItem != null)
            {
                saveFileDialog.FileName   = System.IO.Path.GetFileName(audioItem.FilePath) + "processed"; // Default file name
                saveFileDialog.DefaultExt = ".mp3";
                saveFileDialog.Filter     = "MP3 files (.mp3)|*.mp3";

                if (saveFileDialog.ShowDialog() == true)
                {
                    string filename = saveFileDialog.FileName;

                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append(filename.Remove(filename.Length - 4, 4));
                    stringBuilder.Append(".wav");

                    filename = stringBuilder.ToString();

                    stringBuilder.Clear();

                    using (WaveFileWriter writer = new WaveFileWriter(filename, AudioItemManager.GetAudioItem().WaveFormat))
                    {
                        if (AudioItemManager.GetAudioItem() != null)
                        {
                            writer.WriteSamples(AudioItemManager.GetAudioItem().AudioBuffer, 0, AudioItemManager.GetAudioItem().AudioBuffer.Length / 2);
                            writer.Dispose();
                            writer.Close();

                            filename = ConvertWAVToMp3File(filename, stringBuilder);

                            DeleteWAVFileAfterConversion(filename, stringBuilder);
                        }
                        else
                        {
                            MainWindowLogAction("Cannot export not changed file! " + filename);
                        }
                    }
                    if (MainWindowLogAction != null)
                    {
                        MainWindowLogAction("Exported edited audio file, filePath: " + filename);
                    }
                }
            }
            else
            {
                if (MainWindowLogAction != null)
                {
                    MainWindowLogAction("Cannot export empty file!");
                }
            }
        }
Exemplo n.º 2
0
        private void ReverbEffectWorkHandler(object sender, DoWorkEventArgs e)
        {
            List <object> passedParams = e.Argument as List <object>;
            int           delay        = (int)passedParams[0];
            double        decay        = (double)passedParams[1];

            audioItem = AudioItemManager.GetAudioItem();

            if (audioItem != null)
            {
                SetMaxProgressBar();

                float[] samplesToProcess;
                long    beginIndex, endIndex;
                int     seconds, miliseconds, minutes;
                int     fullTime = 0;
                SetDataForProcessing(out samplesToProcess, out minutes, out beginIndex, out endIndex, out seconds, out miliseconds);

                AudioReverbEffect.ReverbEffectInit((short)delay, (float)decay);

                int begIndex = (int)beginIndex;
                int enIndex  = (int)endIndex;

                AudioReverbEffect.AddReverbEffect(ref samplesToProcess, begIndex, enIndex, ref fullTime);

                this.disp.Invoke(DispatcherPriority.Normal, new Action(delegate()
                {
                    MainWindow.progressBar.Value = 100; // Do all the ui thread updates here
                }));

                audioItem.ProcessedAudioBuffer = samplesToProcess;

                AudioItemManager.SetAudioItem(audioItem);

                ResetProgressBar();

                var milisecondsTime = (double)fullTime / 1000;

                e.Result = "Selection : " + minutes + ":" + AudioItemManager.Instance.GetBeginSpan().Seconds.ToString() + ":" + AudioItemManager.Instance.GetBeginSpan().Milliseconds.ToString() + " - " + AudioItemManager.Instance.GetEndSpan().Minutes.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Seconds.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Milliseconds.ToString() +
                           "  " + " -> Processed Reverb effect on audio sample!" + "\nProcessing range length: " + (endIndex - beginIndex).ToString() +
                           "\n" + dllType.ToString() + " library time elapsed: " + milisecondsTime.ToString() + " msec" + "\nThreads count: " + threadsValue.ToString();
            }
            else
            {
                e.Result = "Audio not loaded!";
            }
        }
Exemplo n.º 3
0
        private void ExportWAVFile(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            var            audioItem      = AudioItemManager.GetAudioItem();

            if (audioItem != null)
            {
                saveFileDialog.FileName   = System.IO.Path.GetFileName(audioItem.FilePath) + "processed"; // Default file name
                saveFileDialog.DefaultExt = ".wav";
                saveFileDialog.Filter     = "Wav files (.wav)|*.wav";

                if (saveFileDialog.ShowDialog() == true)
                {
                    string filename = saveFileDialog.FileName;
                    using (WaveFileWriter writer = new WaveFileWriter(filename, AudioItemManager.GetAudioItem().WaveFormat))
                    {
                        if (AudioItemManager.GetAudioItem() != null)
                        {
                            writer.WriteSamples(AudioItemManager.GetAudioItem().AudioBuffer, 0, AudioItemManager.GetAudioItem().AudioBuffer.Length / 2);
                            writer.Dispose();
                            writer.Close();
                        }
                        else
                        {
                            MainWindowLogAction("Cannot export not changed file! " + filename);
                        }

                        writer.Dispose();
                        writer.Close();
                    }
                    if (MainWindowLogAction != null)
                    {
                        MainWindowLogAction("Exported edited audio file, filePath: " + filename);
                    }
                }
            }
            else
            {
                if (MainWindowLogAction != null)
                {
                    MainWindowLogAction("Cannot export empty file!");
                }
            }
        }
Exemplo n.º 4
0
        private void FlangerEffectWorkHandler(object sender, DoWorkEventArgs e)
        {
            List <object> passedParams = e.Argument as List <object>;
            int           effectRate   = (int)passedParams[0];
            int           maxD         = (int)passedParams[1];
            int           minD         = (int)passedParams[2];
            double        fwv          = (double)passedParams[3];
            double        step         = (double)passedParams[4];
            double        fbv          = (double)passedParams[5];

            audioItem = AudioItemManager.GetAudioItem();

            if (audioItem != null)
            {
                SetMaxProgressBar();
                float[] samplesToProcess;
                long    beginIndex, endIndex;
                int     seconds, miliseconds, minutes;
                int     elapsedTime = 0;
                int     fullTime    = 0;
                SetDataForProcessing(out samplesToProcess, out minutes, out beginIndex, out endIndex, out seconds, out miliseconds);

                AudioFlangerEffect.FlangerInit((short)effectRate, 16000, (short)maxD, (short)minD, fwv, step, fbv);

                if (threadsValue > 1)
                {
                    samplesCountForThreads = (int)((endIndex - beginIndex) / threadsValue);
                    samplesThreadToProcess = new int[threadsValue];

                    for (int i = 0; i < threadsValue; i++)
                    {
                        samplesThreadToProcess[i] = (int)beginIndex + (samplesCountForThreads * i);
                    }
                    samplesThreadToProcess[threadsValue - 1] = (int)endIndex - 1;

                    for (int x = 0; x < threadsValue - 1; x++)
                    {
                        int startIndex, stopIndex;
                        startIndex = samplesThreadToProcess[x];
                        stopIndex  = samplesThreadToProcess[x + 1];


                        threads.Add(new Thread(() =>
                        {
                            for (int i = startIndex; i < stopIndex + 1; i++)
                            {
                                samplesToProcess[i] = AudioFlangerEffect.FlangerProcess(samplesToProcess[i], ref elapsedTime);
                                AudioFlangerEffect.FlangerSweep();
                                fullTime += elapsedTime;
                            }
                        }));
                    }

                    for (int i = 0; i < threadsValue - 1; i++)
                    {
                        threads[i].Start();
                        threads[i].Join();
                        var first = i;
                        var range = threadsValue - 1;
                        var z     = (double)first / range;
                        worker.ReportProgress((int)(z * 100));
                    }
                }
                else
                {
                    for (long i = beginIndex; i < endIndex; ++i)
                    {
                        samplesToProcess[i] = AudioFlangerEffect.FlangerProcess(samplesToProcess[i], ref elapsedTime);
                        AudioFlangerEffect.FlangerSweep();
                        if (i % 8000 == 0 && i != 0)
                        {
                            var first = i - beginIndex;
                            var range = endIndex - beginIndex;
                            var x     = (double)first / range;
                            worker.ReportProgress((int)(x * 100));
                            System.Threading.Thread.Sleep(50);
                        }
                        fullTime += elapsedTime;
                    }
                }

                ResetProgressBar();

                audioItem.ProcessedAudioBuffer = samplesToProcess;

                AudioItemManager.SetAudioItem(audioItem);

                var milisecondsTime = (double)fullTime / 1000;

                e.Result = "Selection : " + minutes + ":" + seconds + ":" + miliseconds + " - " + AudioItemManager.Instance.GetEndSpan().Minutes.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Seconds.ToString() + ":" + AudioItemManager.Instance.GetEndSpan().Milliseconds.ToString()
                           + "  " + " -> Processed Flanger effect on audio sample!" + "\nProcessing range length: " + (endIndex - beginIndex).ToString() +
                           "\n" + dllType.ToString() + " library time elapsed: " + milisecondsTime.ToString() + " msec" + "\nThreads count: " + threadsValue.ToString();
            }
            else
            {
                e.Result = "Audio not loaded!";
            }
        }