Пример #1
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;
 }
Пример #2
0
            // Constructor:
            public LHV1(LibsndfileWrapper.SF_INFO soundInfo, uint mp3bitrate)
            {
                // Error if not WAV, 16bit

                if (soundInfo.format !=
                        ((int)LibsndfileWrapper.soundFormat.SF_FORMAT_WAV |
                         (int)LibsndfileWrapper.soundFormat.SF_FORMAT_PCM_16) )
                {
                    throw new ArgumentOutOfRangeException(
                            "format",
                            "Only WAV 16 bit uncompressed supported. " +
                            "You gave format " + soundInfo.format);
                }

                  dwStructVersion	= 1;
                  dwStructSize		= (uint)Marshal.SizeOf(typeof(BE_CONFIG));

                  // Handle 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 ArgumentOutOfRangeException(
                          "format", "Sample rate " +
                          soundInfo.samplerate + " not supported");
                  }

                  dwSampleRate = (uint)soundInfo.samplerate;
                  dwReSampleRate = 0;

                  	  // Handle channels

                  switch (soundInfo.channels)
                  {

                case 1 :
                  	mpgmode = mpeg_mode.MONO;
                    break;
                case 2 :
                    mpgmode = mpeg_mode.STEREO;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(
                            "format",
                            "Invalid number of channels:" + soundInfo.channels);

                  }

                  // Handle bit rate

                  switch (mp3bitrate)
                  {

                case 32 :
                case 40 :
                case 48 :
                case 56 :
                case 64 :
                case 80 :
                case 96 :
                case 112 :
                case 128 :

                // Allowed bit rates in MPEG1 and MPEG2:

                case 160 :
                  break;

                case 192 :
                case 224 :
                case 256 :

                // Allowed only in MPEG1:

                case 320 :
                  if (dwMpegVersion	!= MPEG1)
                  {
                    throw new ArgumentOutOfRangeException(
                            "mp3bitrate", "Incompatible bit rate:"+mp3bitrate);
                  }
                  break;

                case 8 :
                case 16 :
                case 24 :

                // Allowed only in MPEG2:

                case 144 :
                  if (dwMpegVersion	!= MPEG2)
                  {
                    throw new ArgumentOutOfRangeException(
                            "mp3bitrate", "Incompatible bit rate:"+mp3bitrate);
                  }
                  break;

                default :
                  throw new ArgumentOutOfRangeException(
                          "mp3bitrate", "Can't support bit rate");

                  }

                  // MINIMUM BIT RATE:

                  dwBitrate	= mp3bitrate;

                  // QUALITY PRESET SETTING:

                  nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY;

                  // USE DEFAULT PSYCHOACOUSTIC MODEL:

                  dwPsyModel = 0;

                  // NO EMPHASIS TURNED ON:

                  dwEmphasis = 0;

                  // SET ORIGINAL FLAG:

                  bOriginal = 1;

                  bWriteVBRHeader	= 0;

                  // No bit reservoir:

                  bNoRes = 0;

                  bCopyright = 0;
                  bCRC = 0;
                  bEnableVBR = 0;
                  bPrivate = 0;
                  bStrictIso = 0;
                  dwMaxBitrate = 0;
                  dwVbrAbr_bps = 0;
                  nQuality = 0;
                  nVbrMethod = VBRMETHOD.VBR_METHOD_NONE;
                  nVBRQuality = 0;
            }
Пример #3
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;
        }
Пример #4
0
            LHV1(LibsndfileWrapper.SF_INFO soundInfo, uint mp3bitrate)
            {
                // Error if not WAV, 16bit

                if (soundInfo.format !=
                    ((int)LibsndfileWrapper.soundFormat.SF_FORMAT_WAV |
                     (int)LibsndfileWrapper.soundFormat.SF_FORMAT_PCM_16))
                {
                    throw new ArgumentOutOfRangeException(
                              "format",
                              "Only WAV 16 bit uncompressed supported. " +
                              "You gave format " + soundInfo.format);
                }


                dwStructVersion = 1;
                dwStructSize    = (uint)Marshal.SizeOf(typeof(BE_CONFIG));


                // Handle 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 ArgumentOutOfRangeException(
                              "format", "Sample rate " +
                              soundInfo.samplerate + " not supported");
                }


                dwSampleRate   = (uint)soundInfo.samplerate;
                dwReSampleRate = 0;


                // Handle channels

                switch (soundInfo.channels)
                {
                case 1:
                    mpgmode = mpeg_mode.MONO;
                    break;

                case 2:
                    mpgmode = mpeg_mode.STEREO;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                              "format",
                              "Invalid number of channels:" + soundInfo.channels);
                }


                // Handle bit rate

                switch (mp3bitrate)
                {
                case 32:
                case 40:
                case 48:
                case 56:
                case 64:
                case 80:
                case 96:
                case 112:
                case 128:

                // Allowed bit rates in MPEG1 and MPEG2:

                case 160:
                    break;

                case 192:
                case 224:
                case 256:

                // Allowed only in MPEG1:

                case 320:
                    if (dwMpegVersion != MPEG1)
                    {
                        throw new ArgumentOutOfRangeException(
                                  "mp3bitrate", "Incompatible bit rate:" + mp3bitrate);
                    }
                    break;

                case 8:
                case 16:
                case 24:

                // Allowed only in MPEG2:

                case 144:
                    if (dwMpegVersion != MPEG2)
                    {
                        throw new ArgumentOutOfRangeException(
                                  "mp3bitrate", "Incompatible bit rate:" + mp3bitrate);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                              "mp3bitrate", "Can't support bit rate");
                }

                // MINIMUM BIT RATE:

                dwBitrate = mp3bitrate;

                // QUALITY PRESET SETTING:

                nPreset = LAME_QUALITY_PRESET.LQP_NORMAL_QUALITY;

                // USE DEFAULT PSYCHOACOUSTIC MODEL:

                dwPsyModel = 0;

                // NO EMPHASIS TURNED ON:

                dwEmphasis = 0;

                // SET ORIGINAL FLAG:

                bOriginal = 1;

                bWriteVBRHeader = 0;

                // No bit reservoir:

                bNoRes = 0;

                bCopyright   = 0;
                bCRC         = 0;
                bEnableVBR   = 0;
                bPrivate     = 0;
                bStrictIso   = 0;
                dwMaxBitrate = 0;
                dwVbrAbr_bps = 0;
                nQuality     = 0;
                nVbrMethod   = VBRMETHOD.VBR_METHOD_NONE;
                nVBRQuality  = 0;
            }