Пример #1
0
        private void AudioWaveForm_Click(object sender, EventArgs e)
        {
            if (audioVisualizer.WavePeaks == null)
            {
                if (string.IsNullOrEmpty(_videoFileName))
                {
                    buttonOpenVideo_Click(sender, e);
                    if (string.IsNullOrEmpty(_videoFileName))
                        return;
                }

                if (mediaPlayer != null)
                    mediaPlayer.Pause();
                var addWaveForm = new AddWareForm();
                string peakWaveFileName = GetPeakWaveFileName(_videoFileName);
                string spectrogramFolder = GetSpectrogramFolder(_videoFileName);
                addWaveForm.Initialize(_videoFileName, spectrogramFolder, _videoAudioTrackNumber);
                if (addWaveForm.ShowDialog() == DialogResult.OK)
                {
                    addWaveForm.WavePeak.WritePeakSamples(peakWaveFileName);
                    var audioPeakWave = new WavePeakGenerator(peakWaveFileName);
                    audioPeakWave.GenerateAllSamples();
                    audioPeakWave.Close();
                    audioVisualizer.WavePeaks = audioPeakWave;
                    if (addWaveForm.SpectrogramBitmaps != null)
                        audioVisualizer.InitializeSpectrogram(addWaveForm.SpectrogramBitmaps, spectrogramFolder);
                    timerWaveForm.Start();
                }
            }
        }
Пример #2
0
        private void AudioWaveFormDragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            string fileName = files[0];
            if (files.Length != 1)
            {
                MessageBox.Show(_language.DropOnlyOneFile);
                return;
            }

            string ext = Path.GetExtension(fileName).ToLower();
            if (ext != ".wav")
            {
                if (audioVisualizer.WavePeaks == null && (Utilities.GetMovieFileExtensions().Contains(ext) || ext == ".mp3"))
                {
                    _videoFileName = fileName;
                    AudioWaveForm_Click(null, null);
                    OpenVideo(_videoFileName);
                    return;
                }
                try
                {
                    var fi = new FileInfo(fileName);
                    if (fi.Length < 1024 * 500)
                    {
                        var lines = new List<string>();
                        foreach (string line in File.ReadAllLines(fileName))
                            lines.Add(line);
                        foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
                        {
                            if (format.IsMine(lines, fileName))
                            {
                                OpenSubtitle(fileName, null);
                                return;
                            }
                        }
                    }
                }
                catch
                {
                }
            }


            if (string.IsNullOrEmpty(_videoFileName))
                buttonOpenVideo_Click(null, null);
            if (_videoFileName == null)
                return;

            if (ext != ".wav")
            {
                MessageBox.Show(string.Format(".Wav only!", fileName));
                return;
            }

            var addWaveForm = new AddWareForm();
            string spectrogramFolder = GetSpectrogramFolder(_videoFileName);
            addWaveForm.InitializeViaWaveFile(fileName, spectrogramFolder);
            if (addWaveForm.ShowDialog() == DialogResult.OK)
            {
                string peakWaveFileName = GetPeakWaveFileName(_videoFileName);
                addWaveForm.WavePeak.WritePeakSamples(peakWaveFileName);
                var audioPeakWave = new WavePeakGenerator(peakWaveFileName);
                audioPeakWave.GenerateAllSamples();
                audioVisualizer.WavePeaks = audioPeakWave;
                timerWaveForm.Start();
            }
        }
        /// <summary>
        /// The read wave file.
        /// </summary>
        /// <param name="targetFile">
        /// The target file.
        /// </param>
        /// <param name="delayInMilliseconds">
        /// The delay in milliseconds.
        /// </param>
        private void ReadWaveFile(string targetFile, int delayInMilliseconds)
        {
            this.labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingPeakFile;
            this.Refresh();

            var waveFile = new WavePeakGenerator(targetFile);

            int sampleRate = Configuration.Settings.VideoControls.WaveformMinimumSampleRate; // Normally 128
            while (waveFile.Header.SampleRate % sampleRate != 0 && sampleRate < 5000)
            {
                sampleRate++; // old sample-rate / new sample-rate must have rest = 0
            }

            waveFile.GeneratePeakSamples(sampleRate, delayInMilliseconds); // samples per second - SampleRate

            if (Configuration.Settings.VideoControls.GenerateSpectrogram)
            {
                this.labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
                this.Refresh();
                Directory.CreateDirectory(this._spectrogramDirectory);
                this.SpectrogramBitmaps = waveFile.GenerateFourierData(256, this._spectrogramDirectory, delayInMilliseconds); // image height = nfft / 2
            }

            this.WavePeak = waveFile;
            waveFile.Close();

            this.labelPleaseWait.Visible = false;
        }