/// <summary> /// Converts Wav to MP3. /// </summary> /// <param name="inputFile">The input file.</param> /// <param name="outputPath">The output path.</param> /// <returns> /// Path of changed file /// </returns> public static string ConvertWavToMp3(string inputFile, string outputPath) { var reader = new WaveStream(inputFile); try { var config = new BE_CONFIG(reader.Format, (uint)(Math.Abs(BitRate - 0.0) < 0.1 ? DefaultBitRate : BitRate)); var writer = new Mp3Writer(new FileStream(outputPath, FileMode.Create), reader.Format, config); try { var buffer = new byte[writer.OptimalBufferSize]; int read; while ((read = reader.Read(buffer, 0, buffer.Length)) > 0) { writer.Write(buffer, 0, read); } } finally { writer.Close(); } } finally { reader.Close(); } return(outputPath); }
private void Init() { if (inited) { return; } m_Mp3Config = MakeConfig(); uint LameResult = Lame_encDll.beInitStream(m_Mp3Config, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream); if (LameResult != Lame_encDll.BE_ERR_SUCCESSFUL) { throw new ApplicationException(string.Format("Lame_encDll.beInitStream failed with the error code {0}", LameResult)); } m_InBuffer = new byte[m_InputSamples * 2]; //Input buffer is expected as short[] m_OutBuffer = new byte[Math.Max(65536, m_OutBufferSize)]; if (_IO == null) { _IO = new FileStream(_path, FileMode.Create, FileAccess.Write, FileShare.Read); } inited = true; }
public EditMp3Writer() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); m_Config = new BE_CONFIG(editFormat1.Format); DoSetInitialValues(); }
protected override BE_CONFIG MakeConfig() { BE_CONFIG Mp3Config = new BE_CONFIG(Settings.PCM, m_settings.CustomBitrate > 0 ? (uint)m_settings.CustomBitrate : LAMEEncoderCBRSettings.bps_table[m_settings.EncoderModeIndex], 5); Mp3Config.format.lhv1.bWriteVBRHeader = 1; Mp3Config.format.lhv1.nMode = m_settings.StereoMode; //Mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; // --cbr //Mp3Config.format.lhv1.nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY; return(Mp3Config); }
protected override BE_CONFIG MakeConfig() { BE_CONFIG Mp3Config = new BE_CONFIG(Settings.PCM, 0, (uint)m_settings.Quality); Mp3Config.format.lhv1.bWriteVBRHeader = 1; Mp3Config.format.lhv1.nMode = MpegMode.JOINT_STEREO; Mp3Config.format.lhv1.bEnableVBR = 1; Mp3Config.format.lhv1.nVBRQuality = 9 - m_settings.EncoderModeIndex; Mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NEW; // --vbr-new return(Mp3Config); }
public void Download(Track track) { counter = 0; downloadingTrack = track; var stream = new FileStream("downloading", FileMode.Create); var waveFormat = new WaveFormat(44100, 16, 2); var beConfig = new BE_CONFIG(waveFormat, 320); wr = new Mp3Writer(stream, waveFormat, beConfig); session.PlayerLoad(track); session.PlayerPlay(true); if (OnDownloadProgress != null) { OnDownloadProgress(0); } }
public void Download(Track track) { if (!canPlay(track)) { if (OnDownloadComplete != null) { OnDownloadComplete(false); } return; } counter = 0; downloadingTrack = track; var dir = downloadPath + escape(downloadingTrack.Album().Name()) + "\\"; var fileName = dir + escape(GetTrackFullName(downloadingTrack)) + ".mp3"; if (GetDownloadType() == DownloadType.SKIP && File.Exists(fileName)) { if (OnDownloadProgress != null) { OnDownloadProgress(100); } if (OnDownloadComplete != null) { OnDownloadComplete(true); } return; } var stream = new FileStream("downloading", FileMode.Create); var waveFormat = new WaveFormat(44100, 16, 2); var beConfig = new BE_CONFIG(waveFormat, 320); wr = new Mp3Writer(stream, waveFormat, beConfig); session.PlayerLoad(track); session.PlayerPlay(true); if (OnDownloadProgress != null) { OnDownloadProgress(0); } }
public Stream16(Stream stream_1, WaveFormat waveFormat_1, BE_CONFIG be_CONFIG_1) : base(stream_1, waveFormat_1) { try { this.be_CONFIG_0 = be_CONFIG_1; uint num = LameEncoder.beInitStream(this.be_CONFIG_0, ref this.uint_1, ref this.uint_2, ref this.uint_0); if (num != 0u) { throw new ApplicationException(string.Format("Lame_encDll.beInitStream failed with the error code {0}", num)); } this.byte_0 = new byte[this.uint_1 * 2u]; this.byte_1 = new byte[this.uint_2]; } catch { base.Close(); throw; } }
/// <summary> /// Create a Mp3Writer with specific MP3 format /// </summary> /// <param name="Output">Stream that will hold the MP3 resulting data</param> /// <param name="InputDataFormat">PCM format of input data</param> /// <param name="Mp3Config">Desired MP3 config</param> public Mp3Writer(Stream Output, WaveFormat InputDataFormat, BE_CONFIG Mp3Config) : base(Output, InputDataFormat) { try { m_Mp3Config = Mp3Config; uint LameResult = Lame_encDll.beInitStream(m_Mp3Config, ref m_InputSamples, ref m_OutBufferSize, ref m_hLameStream); if (LameResult != Lame_encDll.BE_ERR_SUCCESSFUL) { throw new ApplicationException(string.Format("Lame_encDll.beInitStream failed with the error code {0}", LameResult)); } m_InBuffer = new byte[m_InputSamples * 2]; //Input buffer is expected as short[] m_OutBuffer = new byte[m_OutBufferSize]; } catch { base.Close(); throw; } }
public void Download(Track track) { if (!CanPlay(track)) { if (OnDownloadComplete != null) { OnDownloadComplete(false); } return; } _downloadingTrack = track; var fileName = getUpdatedTrackName(_downloadingTrack); if (GetDownloadType() == DownloadType.SKIP && File.Exists(fileName)) { if (OnDownloadProgress != null) { OnDownloadProgress(100); } if (OnDownloadComplete != null) { OnDownloadComplete(true); } return; } var stream = new FileStream("downloading", FileMode.Create); var waveFormat = new WaveFormat(44100, 16, 2); var beConfig = new BE_CONFIG(waveFormat, 320); _wr = new Mp3Writer(stream, waveFormat, beConfig); _session.PlayerLoad(track); _session.PlayerPlay(true); _session.SetVolumeNormalization(bool.Parse(GUI.frmMain.configuration.GetConfiguration("volume_normalization"))); if (OnDownloadProgress != null) { OnDownloadProgress(0); } }
public static extern uint beInitStream(BE_CONFIG pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);
public static extern uint beInitStream(BE_CONFIG be_CONFIG_0, ref uint uint_0, ref uint uint_1, ref uint uint_2);
private static void SaveTrack(TrackInfo trackInfo) { string targetFileName = trackInfo.MusicTag.Title; if (m_Drive.Open(trackInfo.Item.Path[0])) { char[] Drives = CDDrive.GetCDDriveLetters(); if ((Array.IndexOf(Drives, trackInfo.Item.Path[0]) > -1) && (m_Drive.IsCDReady()) && (m_Drive.Refresh())) { try { m_Drive.LockCD(); if (dlgProgress.IsCanceled) { m_CancelRipping = true; } if (!m_CancelRipping) { try { try { WaveFormat Format = new WaveFormat(44100, 16, 2); BE_CONFIG mp3Config = new BE_CONFIG(Format); if (mp3VBR) { mp3Config.format.lhv1.bEnableVBR = 1; if (mp3FastMode) { mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NEW; } else { mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_DEFAULT; } mp3Config.format.lhv1.nVBRQuality = mp3Quality; } else if (mp3CBR) { mp3Config.format.lhv1.bEnableVBR = 0; mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; mp3Config.format.lhv1.dwBitrate = Convert.ToUInt16(Rates[mp3BitRate]); } else { mp3Config.format.lhv1.bEnableVBR = 1; mp3Config.format.lhv1.nVbrMethod = VBRMETHOD.VBR_METHOD_ABR; uint ConToKbwVbrAbr_bps = Convert.ToUInt16(Rates[mp3BitRate]); mp3Config.format.lhv1.dwVbrAbr_bps = ConToKbwVbrAbr_bps * 1000; } if (mp3MONO) { mp3Config.format.lhv1.nMode = MpegMode.MONO; } mp3Config.format.lhv1.bWriteVBRHeader = 1; Stream WaveFile = new FileStream(trackInfo.TempFileName, FileMode.Create, FileAccess.Write); m_Writer = new Mp3Writer(WaveFile, Format, mp3Config); if (!m_CancelRipping) { try { Log.Info("CDIMP: Processing track {0}", trackInfo.MusicTag.Track); DateTime InitTime = DateTime.Now; if ( m_Drive.ReadTrack(trackInfo.MusicTag.Track, new CdDataReadEventHandler(WriteWaveData), new CdReadProgressEventHandler(CdReadProgress)) > 0) { if (dlgProgress.IsCanceled) { m_CancelRipping = true; } if (!m_CancelRipping) { TimeSpan Duration = DateTime.Now - InitTime; double Speed = m_Drive.TrackSize(trackInfo.MusicTag.Track) / Duration.TotalSeconds / Format.nAvgBytesPerSec; Log.Info("CDIMP: Done reading track {0} at {1:0.00}x speed", trackInfo.MusicTag.Track, Speed); } } else { Log.Info("CDIMP: Error reading track {0}", trackInfo.MusicTag.Track); m_Writer.Close(); WaveFile.Close(); if (File.Exists(trackInfo.TempFileName)) { try { File.Delete(trackInfo.TempFileName); } catch {} } //progressBar1.Value = 0; } } finally { m_Writer.Close(); m_Writer = null; WaveFile.Close(); Lame_encDll.beWriteVBRHeader(trackInfo.TempFileName); } } } finally {} } finally { m_Drive.Close(); } } } finally { //progressBar1.Value = 0; } } if (dlgProgress.IsCanceled) { m_CancelRipping = true; } if (m_CancelRipping) { if (File.Exists(trackInfo.TempFileName)) { File.Delete(trackInfo.TempFileName); } m_Drive.Close(); } } }
public void Start() { if (Listener == null) { try { BE_CONFIG mp3Config = new BE_CONFIG(new WaveFormat((int)SamplingRate, 16, 1)); mp3Config.format.lhv1.bEnableVBR = 1; mp3Config.format.lhv1.dwMaxBitrate = 128; mp3Config.format.lhv1.nMode = MpegMode.MONO; mp3Config.format.lhv1.nPreset = LAME_QUALITY_PRESET.LQP_AM; Mp3Writer = new Mp3Writer(mp3Config); Listener = new TcpListener(IPAddress.Any, 12121); Listener.Start(); } catch (Exception e) { Status = "Failed: " + e.GetType().ToString(); return; } AcceptThread = new Thread(() => { while (true) { TcpClient client = Listener.AcceptTcpClient(); Stream stream = client.GetStream(); TextReader reader = new StreamReader(stream); /* wait for request */ string line = ""; do { line = reader.ReadLine(); if (line.ToLower().StartsWith("icy-metadata:")) { SendMetadata = (line.Substring(13).Trim() == "1"); } } while (line != ""); string header = ""; header += "ICY 200 OK\r\n"; header += "icy-notice1:g3gg0.de\r\n"; header += "icy-notice2:MP3 Stream Node\r\n"; header += "icy-name:RX-FFT MP3 Stream\r\n"; header += "icy-genre:development\r\n"; header += "icy-url:http://g3gg0.de/\r\n"; header += "icy-pub:1\r\n"; header += "icy-br:128\r\n"; SendMetadata = false; if (SendMetadata) { header += "icy-metaint:" + MetaInt + "\r\n"; } else { header += "icy-metaint:0\r\n"; } header += "\r\n"; byte[] arr = TextEncoding.GetBytes(header); stream.Write(arr, 0, arr.Length); lock (ClientStreams) { ClientInfo info = new ClientInfo(); info.Stream = stream; info.DataSent = 0; info.UpdateMeta = true; ClientStreams.AddLast(info); UpdateStatus(); } } } ); AcceptThread.Start(); } }
protected Mp3WriterConfig(SerializationInfo info, StreamingContext context) : base(info, context) { m_BeConfig = (BE_CONFIG)info.GetValue("BE_CONFIG", typeof(BE_CONFIG)); }
public Mp3WriterConfig(WaveFormat InFormat, BE_CONFIG beconfig) : base(InFormat) { m_BeConfig = beconfig; }
beInitStream(BE_CONFIG pbeConfig, ref uint dwSamples, ref uint dwBufferSize, ref uint phbeStream);