private void tsbOpen_Click(object sender, EventArgs e) { if (ofdAudio.ShowDialog() == DialogResult.OK) { string fileName = ofdAudio.FileName; IAudioReader arw = null; switch (Path.GetExtension(fileName.ToLower())) { case ".avi": arw = new AviReader(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); if (!((AviReader)arw).HasAudio) { MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); return; } break; case ".au": case ".snd": arw = new AuReader(File.OpenRead(fileName)); break; case ".wav": arw = new WaveReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); break; case ".mp3": arw = new Mp3ReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); break; default: arw = new DsReader(fileName); if (!((DsReader)arw).HasAudio) { MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); return; } break; //FormatDialog fd = new FormatDialog(false); //if (fd.ShowDialog() == DialogResult.OK) //{ // arw = new RawReadWriter(stream, fd.Format); // break; //} //else //{ // return; //} } rp.Open(arw); } }
/// <summary> /// Вспомогательная функция преобразования Ogg в Wav /// </summary> /// <param name="file">Имя файла</param> static void ToWav(string file) { using (DsReader dr = new DsReader(file)) { if (dr.HasAudio) { IntPtr format = dr.ReadFormat(); using (WaveWriter ww = new WaveWriter(File.Create(file + ".wav"), AudioCompressionManager.FormatBytes(format))) { byte[] data = dr.ReadData(); ww.WriteData(data); } } } }
/// <summary> /// Вспомогательная функция преобразования Wav в Ogg /// </summary> /// <param name="file">Имя файла</param> /// <returns>Новое имя файла</returns> static string ToOgg(string file) { using (DsReader dr = new DsReader(file)) { if (dr.HasAudio) { IntPtr format = dr.ReadFormat(); using (WaveWriter ww = new WaveWriter(File.Create(file + ".ogg"), AudioCompressionManager.FormatBytes(format))) { byte[] data = dr.ReadData(); ww.WriteData(data); } Console.WriteLine("Audio created successfully!"); } else { Console.WriteLine("No audio in this file"); } } return(file + ".ogg"); }
static public string Convert(File file, Encoding targetEnc) { Trace.WriteLine("Converting " + file.Name + file.Extension + " to " + targetEnc.ToString("G")); // Read in file & formatting IAudioReader Reader = new DsReader(file.Path); IntPtr SourceFormat = Reader.ReadFormat(); IntPtr TargetFormat = AudioCompressionManager.GetCompatibleFormat(SourceFormat, AudioCompressionManager.MpegLayer3FormatTag); // Create new file byte[] Data = Reader.ReadData(); byte[] Output = AudioCompressionManager.Convert(SourceFormat, TargetFormat, Data, true); string Filename = Path.GetDirectoryName(file.Path) + "\\" + file.Name + "." + targetEnc.ToString("G").ToLower(); BinaryWriter Writer = new BinaryWriter(System.IO.File.Create(Filename)); Writer.Write(Output, 0, Output.Length); // Cleanup & remove source Reader.Close(); Writer.Close(); file.Delete(); return Filename; }
private void tsbOpen_Click(object sender, EventArgs e) { if (ofdAudio.ShowDialog() == DialogResult.OK) { string fileName = ofdAudio.FileName; IAudioReader arw = null; switch (Path.GetExtension(fileName.ToLower())) { case ".avi": arw = new AviReader(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); if (!((AviReader)arw).HasAudio) { MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); return; } break; case ".au": case ".snd": arw = new AuReader(File.OpenRead(fileName)); break; case ".wav": arw = new WaveReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); break; case ".mp3": arw = new Mp3ReadWriter(File.Open(fileName, FileMode.Open, FileAccess.ReadWrite)); break; default: arw = new DsReader(fileName); if (!((DsReader)arw).HasAudio) { MessageBox.Show(string.Format("'{0}' file is not contains audio data", fileName)); return; } break; //FormatDialog fd = new FormatDialog(false); //if (fd.ShowDialog() == DialogResult.OK) //{ // arw = new RawReadWriter(stream, fd.Format); // break; //} //else //{ // return; //} } rp.Open(arw); } }
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()); }