public ushort nQuality; // Quality Setting, HIGH BYTE should be NOT LOW byte, otherwhise quality=5 // FUTURE USE, SET TO 0, align strucutre to 331 bytes //[ MarshalAs( UnmanagedType.ByValArray, SizeConst=255-4*4-2 )] //public byte[] btReserved;//[255-4*sizeof(DWORD) - sizeof( WORD )]; public LHV1(WaveFormat format, uint MpeBitRate) { if (format.wFormatTag != (short)WaveFormats.Pcm) { throw new ArgumentOutOfRangeException("format", "Only PCM format supported"); } if (format.wBitsPerSample != 16) { throw new ArgumentOutOfRangeException("format", "Only 16 bits samples supported"); } dwStructVersion = 1; dwStructSize = (uint)Marshal.SizeOf(typeof (BE_CONFIG)); switch (format.nSamplesPerSec) { case 16000: case 22050: case 24000: dwMpegVersion = MPEG2; break; case 32000: case 44100: case 48000: dwMpegVersion = MPEG1; break; default: throw new ArgumentOutOfRangeException("format", "Unsupported sample rate"); } dwSampleRate = (uint)format.nSamplesPerSec; // INPUT FREQUENCY dwReSampleRate = 0; // DON'T RESAMPLE switch (format.nChannels) { case 1: nMode = MpegMode.MONO; break; case 2: nMode = MpegMode.STEREO; break; default: throw new ArgumentOutOfRangeException("format", "Invalid number of channels"); } switch (MpeBitRate) { case 32: case 40: case 48: case 56: case 64: case 80: case 96: case 112: case 128: case 160: //Allowed bit rates in MPEG1 and MPEG2 break; case 192: case 224: case 256: case 320: //Allowed only in MPEG1 if (dwMpegVersion != MPEG1) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } break; case 8: case 16: case 24: case 144: //Allowed only in MPEG2 if (dwMpegVersion != MPEG2) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } break; default: throw new ArgumentOutOfRangeException("MpsBitRate", "Unsupported bit rate"); } dwBitrate = MpeBitRate; // MINIMUM BIT RATE nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY; // QUALITY PRESET SETTING dwPsyModel = 0; // USE DEFAULT PSYCHOACOUSTIC MODEL dwEmphasis = 0; // NO EMPHASIS TURNED ON bOriginal = 1; // SET ORIGINAL FLAG bWriteVBRHeader = 0; bNoRes = 0; // No Bit resorvoir bCopyright = 0; bCRC = 0; bEnableVBR = 0; bPrivate = 0; bStrictIso = 0; dwMaxBitrate = 0; dwVbrAbr_bps = 0; nQuality = 0; nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; nVBRQuality = 0; }
public ushort nQuality; // Quality Setting, HIGH BYTE should be NOT LOW byte, otherwhise quality=5 // FUTURE USE, SET TO 0, align strucutre to 331 bytes //[ MarshalAs( UnmanagedType.ByValArray, SizeConst=255-4*4-2 )] //public byte[] btReserved;//[255-4*sizeof(DWORD) - sizeof( WORD )]; public LHV1(WaveFormat format, uint MpeBitRate) { if (format.wFormatTag != (short)WaveFormats.Pcm) { throw new ArgumentOutOfRangeException("format", "Only PCM format supported"); } if (format.wBitsPerSample != 16) { throw new ArgumentOutOfRangeException("format", "Only 16 bits samples supported"); } dwStructVersion = 1; dwStructSize = (uint)Marshal.SizeOf(typeof(BE_CONFIG)); switch (format.nSamplesPerSec) { case 16000: case 22050: case 24000: dwMpegVersion = MPEG2; break; case 32000: case 44100: case 48000: dwMpegVersion = MPEG1; break; default: throw new ArgumentOutOfRangeException("format", "Unsupported sample rate"); } dwSampleRate = (uint)format.nSamplesPerSec; // INPUT FREQUENCY dwReSampleRate = 0; // DON'T RESAMPLE switch (format.nChannels) { case 1: nMode = MpegMode.MONO; break; case 2: nMode = MpegMode.STEREO; break; default: throw new ArgumentOutOfRangeException("format", "Invalid number of channels"); } switch (MpeBitRate) { case 32: case 40: case 48: case 56: case 64: case 80: case 96: case 112: case 128: case 160: //Allowed bit rates in MPEG1 and MPEG2 break; case 192: case 224: case 256: case 320: //Allowed only in MPEG1 if (dwMpegVersion != MPEG1) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } break; case 8: case 16: case 24: case 144: //Allowed only in MPEG2 if (dwMpegVersion != MPEG2) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } break; default: throw new ArgumentOutOfRangeException("MpsBitRate", "Unsupported bit rate"); } dwBitrate = MpeBitRate; // MINIMUM BIT RATE nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY; // QUALITY PRESET SETTING dwPsyModel = 0; // USE DEFAULT PSYCHOACOUSTIC MODEL dwEmphasis = 0; // NO EMPHASIS TURNED ON bOriginal = 1; // SET ORIGINAL FLAG bWriteVBRHeader = 0; bNoRes = 0; // No Bit resorvoir bCopyright = 0; bCRC = 0; bEnableVBR = 0; bPrivate = 0; bStrictIso = 0; dwMaxBitrate = 0; dwVbrAbr_bps = 0; nQuality = 0; nVbrMethod = VBRMETHOD.VBR_METHOD_NONE; nVBRQuality = 0; }
private static extern int lame_set_mode(IntPtr context, MpegMode value);
public LHV1(WaveFormat waveFormat_0, uint uint_0, uint uint_1) { if (waveFormat_0.waveFormatTag_0 != WaveFormatTag.PCM) { throw new ArgumentOutOfRangeException("format", "Only PCM format supported"); } if (waveFormat_0.short_2 != 16) { throw new ArgumentOutOfRangeException("format", "Only 16 bits samples supported"); } this.dwStructVersion = 1u; this.dwStructSize = (uint)Marshal.SizeOf(typeof(BE_CONFIG)); uint num = (uint)((uint_1 == 0u) ? waveFormat_0.int_0 : ((int)uint_1)); if (num <= 24000u) { if (num == 16000u || num == 22050u || num == 24000u) { this.dwMpegVersion = 0u; goto IL_B6; } } else if (num == 32000u || num == 44100u || num == 48000u) { this.dwMpegVersion = 1u; goto IL_B6; } throw new ArgumentOutOfRangeException("format", "Unsupported sample rate"); IL_B6: this.dwSampleRate = (uint)waveFormat_0.int_0; this.dwReSampleRate = uint_1; switch (waveFormat_0.short_0) { case 1: this.nMode = MpegMode.Mono; break; case 2: this.nMode = MpegMode.Stereo; break; default: throw new ArgumentOutOfRangeException("format", "Invalid number of channels"); } if (uint_0 <= 80u) { if (uint_0 <= 32u) { if (uint_0 <= 16u) { if (uint_0 != 8u && uint_0 != 16u) { goto IL_1E5; } } else if (uint_0 != 24u) { if (uint_0 != 32u) { goto IL_1E5; } goto IL_20E; } } else if (uint_0 <= 48u) { if (uint_0 != 40u && uint_0 != 48u) { goto IL_1E5; } goto IL_20E; } else { if (uint_0 != 56u && uint_0 != 64u && uint_0 != 80u) { goto IL_1E5; } goto IL_20E; } } else if (uint_0 <= 144u) { if (uint_0 <= 112u) { if (uint_0 != 96u && uint_0 != 112u) { goto IL_1E5; } goto IL_20E; } else { if (uint_0 == 128u) { goto IL_20E; } if (uint_0 != 144u) { goto IL_1E5; } } } else { if (uint_0 <= 192u) { if (uint_0 == 160u) { goto IL_20E; } if (uint_0 != 192u) { goto IL_1E5; } } else if (uint_0 != 224u && uint_0 != 256u) { if (uint_0 != 320u) { goto IL_1E5; } } if (this.dwMpegVersion != 1u) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } goto IL_20E; } if (this.dwMpegVersion != 0u) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } goto IL_20E; IL_1E5: throw new ArgumentOutOfRangeException("MpsBitRate", "Unsupported bit rate"); IL_20E: this.dwBitrate = uint_0; this.nPreset = LameQualityPreset.LqpNormalQuality; this.dwPsyModel = 0u; this.dwEmphasis = 0u; this.bOriginal = 1; this.bWriteVBRHeader = 0; this.bNoRes = 0; this.bCopyright = 0; this.bCRC = 0; this.bEnableVBR = 0; this.bPrivate = 0; this.bStrictIso = 0; this.dwMaxBitrate = 0u; this.dwVbrAbr_bps = 0u; this.nQuality = 0; this.nVbrMethod = VbrMethod.None; this.nVBRQuality = 0; }
public LHV1(WaveFormat waveFormat_0, uint uint_0, uint uint_1) { if (waveFormat_0.waveFormatTag_0 != WaveFormatTag.PCM) { throw new ArgumentOutOfRangeException("format", "Only PCM format supported"); } if (waveFormat_0.short_2 != 16) { throw new ArgumentOutOfRangeException("format", "Only 16 bits samples supported"); } this.dwStructVersion = 1u; this.dwStructSize = (uint)Marshal.SizeOf(typeof(BE_CONFIG)); uint num = (uint)((uint_1 == 0u) ? waveFormat_0.int_0 : ((int)uint_1)); if (num <= 24000u) { if (num == 16000u || num == 22050u || num == 24000u) { this.dwMpegVersion = 0u; goto IL_B6; } } else if (num == 32000u || num == 44100u || num == 48000u) { this.dwMpegVersion = 1u; goto IL_B6; } throw new ArgumentOutOfRangeException("format", "Unsupported sample rate"); IL_B6: this.dwSampleRate = (uint)waveFormat_0.int_0; this.dwReSampleRate = uint_1; switch (waveFormat_0.short_0) { case 1: this.nMode = MpegMode.Mono; break; case 2: this.nMode = MpegMode.Stereo; break; default: throw new ArgumentOutOfRangeException("format", "Invalid number of channels"); } if (uint_0 <= 80u) { if (uint_0 <= 32u) { if (uint_0 <= 16u) { if (uint_0 != 8u && uint_0 != 16u) { goto IL_1E5; } } else if (uint_0 != 24u) { if (uint_0 != 32u) { goto IL_1E5; } goto IL_20E; } } else if (uint_0 <= 48u) { if (uint_0 != 40u && uint_0 != 48u) { goto IL_1E5; } goto IL_20E; } else { if (uint_0 != 56u && uint_0 != 64u && uint_0 != 80u) { goto IL_1E5; } goto IL_20E; } } else if (uint_0 <= 144u) { if (uint_0 <= 112u) { if (uint_0 != 96u && uint_0 != 112u) { goto IL_1E5; } goto IL_20E; } else { if (uint_0 == 128u) { goto IL_20E; } if (uint_0 != 144u) { goto IL_1E5; } } } else { if (uint_0 <= 192u) { if (uint_0 == 160u) { goto IL_20E; } if (uint_0 != 192u) { goto IL_1E5; } } else if (uint_0 != 224u && uint_0 != 256u) { if (uint_0 != 320u) { goto IL_1E5; } } if (this.dwMpegVersion != 1u) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } goto IL_20E; } if (this.dwMpegVersion != 0u) { throw new ArgumentOutOfRangeException("MpsBitRate", "Bit rate not compatible with input format"); } goto IL_20E; IL_1E5: throw new ArgumentOutOfRangeException("MpsBitRate", "Unsupported bit rate"); IL_20E: this.dwBitrate = uint_0; this.nPreset = LameQualityPreset.LqpNormalQuality; this.dwPsyModel = 0u; this.dwEmphasis = 0u; this.bOriginal = 1; this.bWriteVBRHeader = 0; this.bNoRes = 0; this.bCopyright = 0; this.bCRC = 0; this.bEnableVBR = 0; this.bPrivate = 0; this.bStrictIso = 0; this.dwMaxBitrate = 0u; this.dwVbrAbr_bps = 0u; this.nQuality = 0; this.nVbrMethod = VbrMethod.None; this.nVBRQuality = 0; }
private static extern int lame_set_mode(IntPtr context, MpegMode value);