private void button2_Click(object sender, EventArgs e) { Database database = MdiParent1.Database; Dictionary <int, Contact> dictionary = database.Load(new Contact()) .ToDictionary(contact => Database.ConvertTo <int>(((Contact)contact).Id), contact => (Contact)contact); using (var spectrumBuilder = new SpectrumBuilder(MdiParent1.SpectrumLength, MdiParent1.Frequency)) { foreach (string file in recordingPanel1.Files) { using (var waveFileReader = new WaveFileReader(Path.Combine(RecordingPanel.AudioFolder, file))) spectrumBuilder.Add(waveFileReader); } double[] data = spectrumBuilder.GetData(); List <ClientCorrelation> list = MdiParent1.ContactClassifier.Select(character => new ClientCorrelation { Id = character.Key, Value = new CorrelationBuilder(data, character.Value).GetValue() }).ToList(); list.Sort(); var listBoxForm = new ListBoxForm(list.Select(item => dictionary[item.Id]).Cast <object>(), list.Select(item => item.Value)); listBoxForm.ShowDialog(); } }
private void button5_Click(object sender, EventArgs e) { using (var waveBuilder = new WaveBuilder(MdiParent1.Duration, MdiParent1.Frequency)) { foreach (string file in recordingPanel1.Files) { using (var waveFileReader = new WaveFileReader(Path.Combine(RecordingPanel.AudioFolder, file))) waveBuilder.Add(waveFileReader); } Complex[] data = waveBuilder.GetData_Complex(); var soundCorrelations = new List <AudioForm.SoundCorrelation>(); foreach (var sound in MdiParent1.SoundsClassifier) { string phoneme = sound.Key; int count = data.Length; Complex[] complexs = data.Zip(sound.Value, (x, y) => (x * y)).ToArray(); var input = new fftw_complexarray(complexs); var output = new fftw_complexarray(count); fftw_plan.dft_1d(count, input, output, fftw_direction.Backward, fftw_flags.Estimate).Execute(); List <double> list = output.GetData_Complex().Select(x => x.Magnitude).ToList(); list.Sort(); if (list.Count > MdiParent1.SinglePhonemeCount) { list.RemoveRange(0, list.Count - MdiParent1.SinglePhonemeCount); } soundCorrelations.AddRange( list.Select(value => new AudioForm.SoundCorrelation { Phoneme = phoneme, Value = value })); soundCorrelations.Sort(); if (soundCorrelations.Count > MdiParent1.TotalPhonemeCount) { soundCorrelations.RemoveRange(MdiParent1.TotalPhonemeCount, soundCorrelations.Count - MdiParent1.TotalPhonemeCount); } } var listBoxForm = new ListBoxForm(soundCorrelations.Select(item => item.Phoneme).Cast <object>(), soundCorrelations.Select(item => item.Value)); listBoxForm.ShowDialog(); } }
private void button5_Click(object sender, EventArgs e) { Database database = MdiParent1.Database; var list = new List <ClientCorrelation>(); Dictionary <int, Contact> dictionary = database.Load(new Contact()) .ToDictionary(contact => Database.ConvertTo <int>(((Contact)contact).Id), contact => (Contact)contact); foreach (string file in recordingPanel1.Files) { using (var waveFileReader = new WaveFileReader(Path.Combine(RecordingPanel.AudioFolder, file))) { using (var waveBuilder = new WaveBuilder(MdiParent1.Duration, MdiParent1.Frequency)) { waveBuilder.Add(waveFileReader); Complex[] data = waveBuilder.GetData_Complex(true); foreach (var audioFile in MdiParent1.AudioFileClassifier) { int count = data.Length; var input = new fftw_complexarray(data.Zip(audioFile.Value, (x, y) => (x * y)).ToArray()); var output = new fftw_complexarray(count); fftw_plan.dft_1d(count, input, output, fftw_direction.Forward, fftw_flags.Estimate) .Execute(); double value = output.GetData_Complex().Select(x => x.Magnitude).Max(); list.Add(new ClientCorrelation { Id = audioFile.Key, Value = value }); } } } } list.Sort(); var listBoxForm = new ListBoxForm(list.Select(item => dictionary[item.Id]).Cast <object>(), list.Select(item => item.Value)); listBoxForm.ShowDialog(); }