123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using NAudio.Wave;
- using SongVocalSectionAnalyser.AudioAnalysis;
- using SongVocalSectionAnalyser.Common;
- using SongVocalSectionAnalyser.UI;
- using System;
- using System.IO;
- using System.Windows.Forms;
- namespace SongVocalSectionAnalyser
- {
- public partial class MainForm : Form
- {
- //Manual PreProcess: vocal isolate by invert instrumental ver.
- //Load and parse audio file
- //Split audio sample data by 10ms chunks
- //Extract volume from every chunk
- //Extract MA from continuous per 10 chunks
- //Debouncing chunks by threshold and
- //Looking chunks segment continuous by threshold
- public MainForm()
- {
- InitializeComponent();
- }
- private SongData _songData;
- private WaveOut _waveOut;
- private void LoadButton_Click(object sender, System.EventArgs e)
- {
- var filePath = FilePathTextBox.Text;
- if (string.IsNullOrEmpty(filePath)) throw new InvalidOperationException("File path are required");
- var fileExtension = Path.GetExtension(filePath);
- Func<string, int, float, int, int, SongData> loaderFunc;
- switch (fileExtension.TrimStart('.').ToUpper())
- {
- case "MP3":
- loaderFunc = SongLoader.LoadFromMp3File;
- break;
- case "WAV":
- loaderFunc = SongLoader.LoadFromWavFile;
- break;
- default: throw new NotSupportedException("File extension no supported");
- }
- _songData = loaderFunc(filePath, (int)MsPerChunkUpDown.Value, (float)ChunkThresholdUpDown.Value, (int)ChunkDebounceUpDown.Value, (int)ChunksPerMaUpDown.Value);
- MainChart.SetData(_songData);
- }
- private void ReChunkButton_Click(object sender, EventArgs e)
- {
- _songData = new SongData(_songData, (int)MsPerChunkUpDown.Value, (float)ChunkThresholdUpDown.Value, (int)ChunkDebounceUpDown.Value, (int)ChunksPerMaUpDown.Value);
- MainChart.SetData(_songData);
- }
- private void ReBuildChartButton_Click(object sender, EventArgs e)
- {
- MainSplitContainer.Panel1.Controls.Remove(MainChart);
- MainChart.Dispose();
- MainChart = new InteractiveChart
- {
- Dock = DockStyle.Fill
- };
- MainSplitContainer.Panel1.Controls.Add(MainChart);
- MainChart.SetData(_songData);
- MainChart.TimelineClicked += MainChart_TimelineClicked;
- }
- private void MainChart_TimelineClicked(TimeSpan arg1, ChunkGroup arg2)
- {
- RightRichTextBox.AppendText($"Timeline Clicked pos[{arg1.ToStringH2M2S2F2()}] group[{arg2.Begin.ToStringH2M2S2F2()}]-[{arg2.End.ToStringH2M2S2F2()}]{Environment.NewLine}");
- _waveOut?.Dispose();
- _waveOut = new WaveOut();
- var songDataWaveProvider = PlayChunkRadioButton.Checked
- ? new SongDataWaveProvider(_songData, arg2.Begin, arg2.End)
- : new SongDataWaveProvider(_songData, arg1);
- songDataWaveProvider.Playing+= i => Invoke(new Action(() => MainChart.PlayingSample = i));
- _waveOut.Init(songDataWaveProvider);
- _waveOut.Play();
- }
- private void StopPlayButton_Click(object sender, EventArgs e)
- {
- _waveOut?.Dispose();
- MainChart.PlayingSample = null;
- }
- }
- }
|