private void btnConvert_Click(object sender, EventArgs e) { if (newFormat == IntPtr.Zero) { MessageBox.Show("Please, specify destination format for converting"); return; } string fileName = tbFile2.Text + ".wav"; int size = ar.Milliseconds2Bytes(1000); int len = ar.GetLengthInBytes(); AcmConverter ac = new AcmConverter(oldFormat, newFormat, false); FileStream fs = new FileStream(fileName, FileMode.Create); WaveWriter ww = new WaveWriter(fs, AudioCompressionManager.FormatBytes(newFormat)); pbConvert.Maximum = len; int y = 0; while (y < len) { pbConvert.Value = y; byte[] data = ar.ReadDataInBytes(y, size); if (data.Length == 0) { break; } y += data.Length; byte[] newData = ac.Convert(data); ww.WriteData(newData); } ww.Close(); ar.Close(); gbConvert.Enabled = false; btnMakeMp3.Enabled = tbFile2.Text.ToLower().EndsWith(".wav"); OpenContainingFolder(fileName); }
private void Save(IntPtr format, byte[] data, string fileName) { //string fileName = string.Format(@"e:\Down\wav\{0}.wav", name); WaveWriter ww = new WaveWriter(File.Create(fileName), AudioCompressionManager.FormatBytes(format)); ww.WriteData(data); ww.Close(); }
public void DataRecorder(object sender, DataEventArgs e) { byte[] data = e.Data; ww.WriteData(data); long pos = recEx.GetPosition(TimeFormat.Milliseconds); OnChangePosition(pos); short[] buffer = AudioCompressionManager.RecalculateData(recEx.Format, data, vum.ClientRectangle.Width); vum.Data = buffer; }
private byte[] PcmToWav(int file) { WaveFormat wf = GetWaveFormat(); FormatDetails[] fdArr = AudioCompressionManager.GetFormatList(wf); IntPtr format = fdArr[0].FormatHandle; MemoryStream ms = new MemoryStream(); WaveWriter ww = new WaveWriter(ms, AudioCompressionManager.FormatBytes(format)); ww.WriteData(files[file]); ww.Close(); byte[] wav = ms.GetBuffer(); ms.Close(); return(wav); }
/// <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); } } } }
private void buttonSaveAs_Click(object sender, System.EventArgs e) { if (listViewTracks.SelectedIndices.Count > 0) { int ndx = listViewTracks.SelectedIndices[0]; string title = string.Format("track{0:00}", ndx + 1); saveFileDialog.FileName = string.Format("{0}.wav", title); if (saveFileDialog.ShowDialog() == DialogResult.OK) { ripping = true; try { statusBar.Text = string.Format("Reading track {0}", ndx + 1); UpdateVisualControls(); IntPtr format = CdDrive.GetFormat(); WaveWriter ww = new WaveWriter(File.Create(saveFileDialog.FileName), AudioCompressionManager.FormatBytes(format)); CdReader cr = cda.GetReader(ndx); int durationInMS = cr.GetDurationInMS(); int max = durationInMS / 1000; progressBar1.Minimum = 0; progressBar1.Value = 0; progressBar1.Maximum = max + 1; for (int i = 0; i <= max; i++) { byte[] data = cr.ReadData(i, 1); ww.WriteData(data); progressBar1.Value = i + 1; Application.DoEvents(); } cr.Close(); ww.Close(); DsConvert.ToWma(saveFileDialog.FileName, saveFileDialog.FileName + ".wma", DsConvert.WmaProfile.Stereo128); } finally { ripping = false; } } } UpdateVisualControls(); }
/// <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"); }
private void ConvertToMp3(string AudioFileName, string Mp3FileName) { string wavFile = AudioFileName; string mp3File = Mp3FileName; using (WaveReader wr = new WaveReader(File.OpenRead(wavFile))) { IntPtr pcmFormat = wr.ReadFormat(); byte[] pcmData = wr.ReadData(); wr.Close(); WaveFormat wf = AudioCompressionManager.GetWaveFormat(pcmFormat); if (wf.wFormatTag != AudioCompressionManager.PcmFormatTag)//Decode if not PCM data { Decode2Pcm(ref pcmFormat, ref pcmData, ref wf); } IntPtr webFormat = AudioCompressionManager.GetCompatibleFormat(pcmFormat, AudioCompressionManager.MpegLayer3FormatTag); byte[] webData = AudioCompressionManager.Convert(pcmFormat, webFormat, pcmData, false); MemoryStream ms = new MemoryStream(); using (WaveWriter ww = new WaveWriter(ms, AudioCompressionManager.FormatBytes(webFormat))) { ww.WriteData(webData); using (WaveReader wr2 = new WaveReader(ms)) { using (FileStream fs = File.OpenWrite(mp3File)) { wr2.MakeMP3(fs); } } } File.Delete(AudioFileName); } }
void rex_Data(object sender, DataEventArgs e) { AudioWaveWriter.WriteData(e.Data); }
private void ConvertToCCITT(String f, String FileName) { try { WaveReader newWr = new WaveReader(File.OpenRead(f)); IntPtr oldPcm = newWr.ReadFormat(); byte[] oldPcmData = newWr.ReadData(); IntPtr newFormat = AudioCompressionManager.GetPcmFormat(1, 16, 8000); byte[] newData = { }; WaveFormat wf = AudioCompressionManager.GetWaveFormat(oldPcm); newWr.Close(); if (FileName != "0") { f = FileName; } if (File.Exists(textBox1.Text + Path.GetFileName(f))) { File.Delete(textBox1.Text + Path.GetFileName(f)); } // **** debug **** //txtStatus.Text += f + eol; int samp = wf.nSamplesPerSec; int bps = wf.wBitsPerSample; // sample rate is > 8000 if (samp > 8000) { newData = AudioCompressionManager.Resample(oldPcm, oldPcmData, newFormat); } IntPtr ccittOut = AudioCompressionManager.GetCompatibleFormat(newFormat, AudioCompressionManager.MuLawFormatTag); byte[] finalData = AudioCompressionManager.Convert(newFormat, ccittOut, newData, false); WaveWriter finalWr = new WaveWriter(File.Create(textBox1.Text + Path.GetFileName(f)), AudioCompressionManager.FormatBytes(ccittOut)); finalWr.WriteData(finalData); finalWr.Close(); // **** debug ***** //TextOps(dirUlaw + Path.GetFileName(f) + eol2); //DeleteFile(f); } catch (NullReferenceException nex) { //TextOps("NullReferenceException: " + nex.Message.ToString() + cr); } catch (IOException iex) { //TextOps("IOException: " + iex.Message.ToString() + cr); } catch (AudioException ex) { //TextOps("AudioException: " + ex.Message.ToString() + cr); } }
// CONVERT TO PCM 8KHz 16-bit mono private void ConvertToPcm(String f, String FileName) { try { WaveReader wr = new WaveReader(File.OpenRead(f)); IntPtr oldFormat = wr.ReadFormat(); byte[] oldData = wr.ReadData(); IntPtr newFormat = AudioCompressionManager.GetPcmFormat(1, 16, 8000); byte[] newData = { }; WaveFormat wf = AudioCompressionManager.GetWaveFormat(oldFormat); wr.Close(); if (FileName != "0") { f = FileName; } if (File.Exists(textBox1.Text + Path.GetFileName(f))) { File.Delete(textBox1.Text + Path.GetFileName(f)); } // **** debug **** //txtStatus.Text += f + eol; int samp = wf.nSamplesPerSec; int bps = wf.wBitsPerSample; // sample rate is > 8000 if (samp > 8000) { newData = AudioCompressionManager.Resample(oldFormat, oldData, newFormat); WaveWriter ww = new WaveWriter(File.Create(textBox1.Text + Path.GetFileName(f)), AudioCompressionManager.FormatBytes(newFormat)); ww.WriteData(newData); ww.Close(); // **** debug ***** //TextOps(dirPcm + Path.GetFileName(f) + eol2); } else { //TextOps(Path.GetFileName(f) + " already exists at 8KHz" + cr); } //DeleteFile(f); } catch (NullReferenceException nex) { //TextOps("NullReferenceException: " + nex.Message.ToString() + cr); } catch (IOException iex) { //TextOps("IOException: " + iex.Message.ToString() + cr); } catch (AudioException ex) { //TextOps("AudioException: " + ex.Message.ToString() + cr); } }