예제 #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();
                }
            }
        }
        /// <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;
        }