private void End() { if (waveIn != null) { waveIn.StopRecording(); waveIn.Dispose(); waveIn = null; var waveReader = new Mp3Reader { IsMp3FileReader = false }; if (waveReader.TryRead(memoryStream.GetBuffer(), out var fileInfo)) { var signal = new Signal("Microphone Signal"); signal.SamplingFrq = fileInfo.nSamplesPerSec; signal.StartDateTime = fileInfo.dateTime; for (int i = 0; i < fileInfo.nChannels; i++) { signal.channels.Add(new Channel(fileInfo.data.GetLength(0))); signal.channels[i].Source = signal.fileName; signal.channels[i].Name = fileInfo.channelNames[i] ?? ("Channel " + i); for (int j = 0; j < fileInfo.data.GetLength(0); j++) { signal.channels[i].values[j] = fileInfo.data[j, i]; } } signal.UpdateChannelsInfo(); MainWindow.Instance.ResetSignal(signal); } waveFileWriter.Dispose(); memoryStream.Close(); } }
private string[] IntspectFile(string fileName) { ID3v1 m_id3; Dictionary<WaveInfo, string> m_waveTags = null; IAudioReader ar = null; Stream stream = null; string ext = Path.GetExtension(fileName.ToLower()); m_id3 = null; m_waveTags = null; switch (ext) { case ".avi": stream = File.OpenRead(fileName); ar = new AviReader(stream); if (!((AviReader)ar).HasAudio) { return new string[] { string.Format("'{0}' file is not contains audio data", fileName) }; } break; case ".au": case ".snd": ar = new AuReader(File.OpenRead(fileName)); break; case ".wav": stream = File.OpenRead(fileName); ar = new WaveReader(stream); m_waveTags = (ar as WaveReader).ReadInfoTag(); break; case ".mp3": stream = File.OpenRead(fileName); ar = new Mp3Reader(stream); Mp3Reader mrID3 = new Mp3Reader(File.OpenRead(fileName)); m_id3 = mrID3.ReadID3v1Tag(); break; default: ar = new DsReader(fileName); if (!((DsReader)ar).HasAudio) { return new string[] { string.Format("'{0}' file is not contains audio data", fileName) }; } break; } IntPtr format = ar.ReadFormat(); WaveFormat wf = AudioCompressionManager.GetWaveFormat(format); List<string> list = new List<string>(); list.Add(string.Format("Opening {0}", fileName)); list.Add(string.Format("{0}, {1} Hz, {2} channels, {3} bits per sample", GetFormatTagName(wf.wFormatTag), wf.nSamplesPerSec, wf.nChannels, wf.wBitsPerSample)); list.Add(string.Format("Block Align: {0}, Average Bytes Per Second: {1}", wf.nBlockAlign, wf.nAvgBytesPerSec )); TimeSpan duration = TimeSpan.FromMilliseconds(ar.GetDurationInMS()); list.Add(string.Format("Duration: {0}", duration)); if (m_id3 != null) { list.Add("--------- ID3 -----------"); list.Add(string.Format("Title: {0}", m_id3.Title)); list.Add(string.Format("Artist: {0}", m_id3.Artist)); list.Add(string.Format("Album: {0}", m_id3.Album)); list.Add(string.Format("Year: {0}", m_id3.Year)); list.Add(string.Format("Genre: {0}", m_id3.Genre.ToString())); list.Add(string.Format("Comment: {0}", m_id3.Comment)); } if (m_waveTags != null) { list.Add("--------- Wave tags -----------"); foreach(WaveInfo key in m_waveTags.Keys) list.Add(string.Format("{0}: {1}", key.ToString(), m_waveTags[key])); } ar.Close(); return list.ToArray(); }
private string[] IntspectFile(string fileName) { ID3v1 m_id3; Dictionary <WaveInfo, string> m_waveTags = null; IAudioReader ar = null; Stream stream = null; string ext = Path.GetExtension(fileName.ToLower()); m_id3 = null; m_waveTags = null; switch (ext) { case ".avi": stream = File.OpenRead(fileName); ar = new AviReader(stream); if (!((AviReader)ar).HasAudio) { return(new string[] { string.Format("'{0}' file is not contains audio data", fileName) }); } break; case ".au": case ".snd": ar = new AuReader(File.OpenRead(fileName)); break; case ".wav": stream = File.OpenRead(fileName); ar = new WaveReader(stream); m_waveTags = (ar as WaveReader).ReadInfoTag(); break; case ".mp3": stream = File.OpenRead(fileName); ar = new Mp3Reader(stream); Mp3Reader mrID3 = new Mp3Reader(File.OpenRead(fileName)); m_id3 = mrID3.ReadID3v1Tag(); break; default: ar = new DsReader(fileName); if (!((DsReader)ar).HasAudio) { return(new string[] { string.Format("'{0}' file is not contains audio data", fileName) }); } break; } IntPtr format = ar.ReadFormat(); WaveFormat wf = AudioCompressionManager.GetWaveFormat(format); List <string> list = new List <string>(); list.Add(string.Format("Opening {0}", fileName)); list.Add(string.Format("{0}, {1} Hz, {2} channels, {3} bits per sample", GetFormatTagName(wf.wFormatTag), wf.nSamplesPerSec, wf.nChannels, wf.wBitsPerSample)); list.Add(string.Format("Block Align: {0}, Average Bytes Per Second: {1}", wf.nBlockAlign, wf.nAvgBytesPerSec)); TimeSpan duration = TimeSpan.FromMilliseconds(ar.GetDurationInMS()); list.Add(string.Format("Duration: {0}", duration)); if (m_id3 != null) { list.Add("--------- ID3 -----------"); list.Add(string.Format("Title: {0}", m_id3.Title)); list.Add(string.Format("Artist: {0}", m_id3.Artist)); list.Add(string.Format("Album: {0}", m_id3.Album)); list.Add(string.Format("Year: {0}", m_id3.Year)); list.Add(string.Format("Genre: {0}", m_id3.Genre.ToString())); list.Add(string.Format("Comment: {0}", m_id3.Comment)); } if (m_waveTags != null) { list.Add("--------- Wave tags -----------"); foreach (WaveInfo key in m_waveTags.Keys) { list.Add(string.Format("{0}: {1}", key.ToString(), m_waveTags[key])); } } ar.Close(); return(list.ToArray()); }
private void OpenFileClick(object sender, RoutedEventArgs e) { var openFileDialog = new OpenFileDialog() { Filter = "all files (*.txt;*.wav;*.wave;*.dat;*.mp3)|*.txt;*.wav;*.wave;*.dat;*.mp3|" + "txt files (*.txt)|*.txt|" + "wave files (*.wav;*.wave)|*.wav;*.wave|" + "dat files (*.dat)|*.dat|" + "mp3 files (*.mp3)|*.mp3" }; openFileDialog.FilterIndex = Settings.GetOrDefault("filterIndex", openFileDialog.FilterIndex); if (openFileDialog.ShowDialog() == true) { IReader reader; switch (Path.GetExtension(openFileDialog.FileName)) { case ".mp3": reader = new Mp3Reader(); break; case ".dat": reader = new DatReader(); break; case ".wav": case ".wave": reader = new WaveReader(); break; case ".txt": reader = new TxtReader(); break; default: throw new NotImplementedException(); } if (reader.TryRead(File.ReadAllBytes(openFileDialog.FileName), out var fileInfo)) { var signal = new Signal(Path.GetFileName(openFileDialog.FileName)); signal.SamplingFrq = fileInfo.nSamplesPerSec; signal.StartDateTime = fileInfo.dateTime; for (int i = 0; i < fileInfo.nChannels; i++) { signal.channels.Add(new Channel(fileInfo.data.GetLength(0))); signal.channels[i].Source = signal.fileName; signal.channels[i].Name = fileInfo.channelNames[i] ?? ("Channel " + i); for (int j = 0; j < fileInfo.data.GetLength(0); j++) { signal.channels[i].values[j] = fileInfo.data[j, i]; } } Logger.Info($"File {openFileDialog.FileName} was opened"); signal.UpdateChannelsInfo(); ResetSignal(signal); } else { MessageBox.Show("Incorrect format", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Logger.Info($"File {openFileDialog.FileName} has incorrect format"); } Settings.Set("filterIndex", openFileDialog.FilterIndex); } }