/// <summary>Create MP3FileWriter to write to supplied stream</summary> /// <param name="outStream">Stream to write encoded data to</param> /// <param name="format">Input Genode.Audio.WavFormat</param> /// <param name="quality">LAME quality preset</param> /// <param name="id3">Optional ID3 data block</param> public LameMP3FileWriter(Stream outStream, Cgen.Audio.WavFormat format, Lame.LAMEPreset quality, int channels = 2, int sampleRate = 44100, ID3TagData id3 = null) : base() { // sanity check if (outStream == null) { throw new ArgumentNullException("outStream"); } // select encoder function that matches data format if (format == Cgen.Audio.WavFormat.PCM) { if (channels == 1) { _encode = encode_pcm_16_mono; } else { _encode = encode_pcm_16_stereo; } } else { if (channels == 1) { _encode = encode_float_mono; } else { _encode = encode_float_stereo; } } // Set base properties this.inputFormat = format; this.outStream = outStream; this.disposeOutput = false; // Allocate buffers based on sample rate this.channels = channels; this.inBuffer = new ArrayUnion(sampleRate * channels * 2); this.outBuffer = new byte[sampleRate * 5 / 4 + 7200]; // Initialize lame library this._lame = new Lame.Wrapper.LibMp3Lame(); this._lame.InputSampleRate = sampleRate; this._lame.NumChannels = channels; this._lame.SetPreset((int)quality); if (id3 != null) { ApplyID3Tag(id3); } this._lame.InitParams(); }
/// <summary>Create MP3FileWriter to write to a file on disk</summary> /// <param name="outFileName">Name of file to create</param> /// <param name="format">Input Genode.Audio.WavFormat</param> /// <param name="quality">LAME quality preset</param> /// <param name="id3">Optional ID3 data block</param> public LameMP3FileWriter(string outFileName, Cgen.Audio.WavFormat format, Lame.LAMEPreset quality, int channels = 2, int sampleRate = 44100, ID3TagData id3 = null) : this(File.Create(outFileName), format, quality, channels, sampleRate, id3) { this.disposeOutput = true; }