public LameHeaderVersion1(SOUND_INFO soundInfo, MP3_Settings settings) { #region " Check the input format " if (soundInfo.format != ((int)SOUND_FORMAT.WAV | (int)SOUND_FORMAT.PCM_S16)) { throw new InvalidDataException("Wrong format!", new Exception("Only 16 bit uncompressed WAV supported. You gave " + soundInfo.format)); } # endregion
/// <summary> /// Initializes a new instance of the <see cref="Lame"/> class. /// </summary> /// <param name="InputWaveFile">The input wave file.</param> /// <param name="settings">The encoding settings.</param> public Lame(string InputWaveFile, MP3_Settings settings) { inputWaveFile = InputWaveFile; SOUND_INFO info = new SOUND_INFO(); GetSoundFileInfo(InputWaveFile, ref info); LAME_CONFIG mp3config = new LAME_CONFIG(info, settings); if (beInitStream(mp3config, ref Samples, ref outputBufferSize, ref StreamHandle) != LAME_ERR_SUCCESSFUL) throw new Exception("Failed to initialize lame!"); optimalBufferSize = 2 * (int)Samples; InputBuffer = new byte[optimalBufferSize]; OutputBuffer = new byte[OutputBufferSize]; }
/// <summary> /// Initializes a new instance of the <see cref="Lame"/> class. /// </summary> /// <param name="settings">The encoding settings.</param> public Lame(MP3_Settings settings, int Channels, int SampleRate) { SOUND_INFO info = new SOUND_INFO(); info.format = 0x010002; info.samplerate = SampleRate; info.channels = Channels; LAME_CONFIG mp3config = new LAME_CONFIG(info, settings); if (beInitStream(mp3config, ref Samples, ref outputBufferSize, ref StreamHandle) != LAME_ERR_SUCCESSFUL) throw new Exception("Failed to initialize lame!"); optimalBufferSize = 2 * (int)Samples; InputBuffer = new byte[optimalBufferSize]; OutputBuffer = new byte[OutputBufferSize]; }
public config(SOUND_INFO soundInfo, MP3_Settings settings) { lhv1 = new LameHeaderVersion1(soundInfo, settings); }
public LAME_CONFIG(SOUND_INFO soundInfo, MP3_Settings settings) { dwConfig = BE_CONFIG_LAME; union = new config(soundInfo, settings); }
public LameHeaderVersion1(SOUND_INFO soundInfo, MP3_Settings settings) { #region " Check the input format " if (soundInfo.format != ((int)SOUND_FORMAT.WAV | (int)SOUND_FORMAT.PCM_S16)) { throw new InvalidDataException("Wrong format!", new Exception("Only 16 bit uncompressed WAV supported. You gave " + soundInfo.format)); } # endregion dwStructVersion = 1; dwStructSize = (uint)Marshal.SizeOf(typeof(LAME_CONFIG)); # region " Check input sample rate " switch (soundInfo.samplerate) { case 16000: case 22050: case 24000: dwMpegVersion = MPEG2; break; case 32000: case 44100: case 48000: dwMpegVersion = MPEG1; break; default: throw new InvalidDataException("Wrong format!", new Exception("Sample rate " + soundInfo.samplerate + " not supported.")); } # endregion dwSampleRate = (uint)soundInfo.samplerate; dwReSampleRate = 0; # region " Set encoding channels " switch (soundInfo.channels) { case 1: nMode = MPEG_MODE.MONO; break; case 2: nMode = MPEG_MODE.STEREO; break; default: throw new InvalidDataException("Wrong format!", new Exception("Invalid number of channels:" + soundInfo.channels)); } # endregion # region " Check encoding bit rate " switch (settings.Bitrate) { case 32: case 40: case 48: case 56: case 64: case 80: case 96: case 112: case 128: case 160: break; // Allowed only in MPEG1: case 192: case 224: case 256: case 320: if (dwMpegVersion != MPEG1) { throw new InvalidDataException("Wrong mp3 bit rate!", new Exception("Incompatible bit rate:" + settings.Bitrate)); } break; // Allowed only in MPEG2: case 8: case 16: case 24: case 144: if (dwMpegVersion != MPEG2) { throw new InvalidDataException("Wrong mp3 bit rate!", new Exception("Incompatible bit rate:" + settings.Bitrate)); } break; default: throw new InvalidDataException("Wrong mp3 bit rate!", new Exception("Can't support bit rate")); } # endregion dwBitrate = settings.Bitrate; nPreset = settings.QualityPreset; bEnableVBR = settings.VBR_enabled ? 1 : 0; dwMaxBitrate = settings.VBR_maxBitrate; dwVbrAbr_bps = 0; nQuality = 0; nVbrMethod = settings.VBR_method; nVBRQuality = settings.VBR_Quality; bWriteVBRHeader = settings.VBR_WriteHeader ? 1 : 0; bOriginal = settings.OriginalBit ? 1 : 0; bCopyright = settings.CopyrightBit ? 1 : 0; bCRC = settings.CRC_Bit ? 1 : 0; bPrivate = settings.PrivatBit ? 1 : 0; bNoRes = settings.DisableBitReservoir ? 1 : 0; bStrictIso = settings.StrictISOencoding ? 1 : 0; dwPsyModel = 0; dwEmphasis = 0; }