/// <summary> /// Read a 32-bit header from the bitstream. /// </summary> internal void read_header(Bitstream stream, Crc16[] crcp) { int headerstring; int channelBitrate; bool sync = false; do { headerstring = stream.SyncHeader(_Syncmode); _Headerstring = headerstring; if (_Syncmode == Bitstream.INITIAL_SYNC) { _Version = SupportClass.URShift(headerstring, 19) & 1; if ((SupportClass.URShift(headerstring, 20) & 1) == 0) { // SZD: MPEG2.5 detection if (_Version == MPEG2_LSF) { _Version = MPEG25_LSF; } else { throw stream.NewBitstreamException(BitstreamErrors.UNKNOWN_ERROR); } } if ((_SampleFrequency = SupportClass.URShift(headerstring, 10) & 3) == 3) { throw stream.NewBitstreamException(BitstreamErrors.UNKNOWN_ERROR); } } _Layer = 4 - SupportClass.URShift(headerstring, 17) & 3; _ProtectionBit = SupportClass.URShift(headerstring, 16) & 1; _BitrateIndex = SupportClass.URShift(headerstring, 12) & 0xF; _PaddingBit = SupportClass.URShift(headerstring, 9) & 1; _Mode = SupportClass.URShift(headerstring, 6) & 3; _ModeExtension = SupportClass.URShift(headerstring, 4) & 3; if (_Mode == JOINT_STEREO) { _IntensityStereoBound = (_ModeExtension << 2) + 4; } else { _IntensityStereoBound = 0; } // should never be used _Copyright |= (SupportClass.URShift(headerstring, 3) & 1) == 1; _Original |= (SupportClass.URShift(headerstring, 2) & 1) == 1; // calculate number of subbands: if (_Layer == 1) { _NumberOfSubbands = 32; } else { channelBitrate = _BitrateIndex; // calculate bitrate per channel: if (_Mode != SINGLE_CHANNEL) { if (channelBitrate == 4) { channelBitrate = 1; } else { channelBitrate -= 4; } } if (channelBitrate == 1 || channelBitrate == 2) { if (_SampleFrequency == THIRTYTWO) { _NumberOfSubbands = 12; } else { _NumberOfSubbands = 8; } } else if (_SampleFrequency == FOURTYEIGHT || channelBitrate >= 3 && channelBitrate <= 5) { _NumberOfSubbands = 27; } else { _NumberOfSubbands = 30; } } if (_IntensityStereoBound > _NumberOfSubbands) { _IntensityStereoBound = _NumberOfSubbands; } // calculate framesize and nSlots CalculateFrameSize(); // read framedata: stream.Read_frame_data(Framesize); if (stream.IsSyncCurrentPosition(_Syncmode)) { if (_Syncmode == Bitstream.INITIAL_SYNC) { _Syncmode = Bitstream.STRICT_SYNC; stream.SetSyncWord(headerstring & unchecked ((int)0xFFF80CC0)); } sync = true; } else { stream.UnreadFrame(); } } while (!sync); stream.ParseFrame(); if (_ProtectionBit == 0) { // frame contains a crc checksum Checksum = (short)stream.GetBitsFromBuffer(16); if (_CRC == null) { _CRC = new Crc16(); } _CRC.AddBits(headerstring, 16); crcp[0] = _CRC; } else { crcp[0] = null; } if (_SampleFrequency == FOURTYFOUR_POINT_ONE) { /* * if (offset == null) * { * int max = max_number_of_frames(stream); * offset = new int[max]; * for(int i=0; i<max; i++) offset[i] = 0; * } * // Bizarre, y avait ici une acollade ouvrante * int cf = stream.current_frame(); * int lf = stream.last_frame(); * if ((cf > 0) && (cf == lf)) * { * offset[cf] = offset[cf-1] + h_padding_bit; * } * else * { * offset[0] = h_padding_bit; * } */ } }
/// <summary> /// Read a 32-bit header from the bitstream. /// </summary> internal void read_header(Bitstream stream, Crc16[] crcp) { int headerstring; int channel_bitrate; bool sync = false; do { headerstring = stream.syncHeader(syncmode); _headerstring = headerstring; // E.B if (syncmode == Bitstream.INITIAL_SYNC) { h_version = ((SupportClass.URShift(headerstring, 19)) & 1); if (((SupportClass.URShift(headerstring, 20)) & 1) == 0) { // SZD: MPEG2.5 detection if (h_version == MPEG2_LSF) { h_version = MPEG25_LSF; } else { throw stream.newBitstreamException(BitstreamErrors.UNKNOWN_ERROR); } } if ((h_sample_frequency = ((SupportClass.URShift(headerstring, 10)) & 3)) == 3) { throw stream.newBitstreamException(BitstreamErrors.UNKNOWN_ERROR); } } h_layer = 4 - (SupportClass.URShift(headerstring, 17)) & 3; h_protection_bit = (SupportClass.URShift(headerstring, 16)) & 1; h_bitrate_index = (SupportClass.URShift(headerstring, 12)) & 0xF; h_padding_bit = (SupportClass.URShift(headerstring, 9)) & 1; h_mode = ((SupportClass.URShift(headerstring, 6)) & 3); h_mode_extension = (SupportClass.URShift(headerstring, 4)) & 3; if (h_mode == JOINT_STEREO) { h_intensity_stereo_bound = (h_mode_extension << 2) + 4; } else { h_intensity_stereo_bound = 0; } // should never be used if (((SupportClass.URShift(headerstring, 3)) & 1) == 1) { h_copyright = true; } if (((SupportClass.URShift(headerstring, 2)) & 1) == 1) { h_original = true; } // calculate number of subbands: if (h_layer == 1) { h_number_of_subbands = 32; } else { channel_bitrate = h_bitrate_index; // calculate bitrate per channel: if (h_mode != SINGLE_CHANNEL) { if (channel_bitrate == 4) { channel_bitrate = 1; } else { channel_bitrate -= 4; } } if ((channel_bitrate == 1) || (channel_bitrate == 2)) { if (h_sample_frequency == THIRTYTWO) { h_number_of_subbands = 12; } else { h_number_of_subbands = 8; } } else if ((h_sample_frequency == FOURTYEIGHT) || ((channel_bitrate >= 3) && (channel_bitrate <= 5))) { h_number_of_subbands = 27; } else { h_number_of_subbands = 30; } } if (h_intensity_stereo_bound > h_number_of_subbands) { h_intensity_stereo_bound = h_number_of_subbands; } // calculate framesize and nSlots calculate_framesize(); // read framedata: stream.read_frame_data(framesize); if (stream.IsSyncCurrentPosition(syncmode)) { if (syncmode == Bitstream.INITIAL_SYNC) { syncmode = Bitstream.STRICT_SYNC; stream.SetSyncWord(headerstring & unchecked ((int)0xFFF80CC0)); } sync = true; } else { stream.unreadFrame(); } } while (!sync); stream.ParseFrame(); if (h_protection_bit == 0) { // frame contains a crc checksum checksum = (short)stream.GetBitsFromBuffer(16); if (crc == null) { crc = new Crc16(); } crc.add_bits(headerstring, 16); crcp[0] = crc; } else { crcp[0] = null; } if (h_sample_frequency == FOURTYFOUR_POINT_ONE) { /* * if (offset == null) * { * int max = max_number_of_frames(stream); * offset = new int[max]; * for(int i=0; i<max; i++) offset[i] = 0; * } * // Bizarre, y avait ici une acollade ouvrante * int cf = stream.current_frame(); * int lf = stream.last_frame(); * if ((cf > 0) && (cf == lf)) * { * offset[cf] = offset[cf-1] + h_padding_bit; * } * else * { * offset[0] = h_padding_bit; * } */ } }
/// <summary> /// Read a 32-bit header from the bitstream. /// </summary> internal void read_header(Bitstream stream, Crc16[] crcp) { int headerstring; int channel_bitrate; bool sync = false; do { headerstring = stream.syncHeader(syncmode); _headerstring = headerstring; // E.B if (syncmode == Bitstream.INITIAL_SYNC) { h_version = ((SupportClass.URShift(headerstring, 19)) & 1); if (((SupportClass.URShift(headerstring, 20)) & 1) == 0) // SZD: MPEG2.5 detection if (h_version == MPEG2_LSF) h_version = MPEG25_LSF; else throw stream.newBitstreamException(BitstreamErrors.UNKNOWN_ERROR); if ((h_sample_frequency = ((SupportClass.URShift(headerstring, 10)) & 3)) == 3) { throw stream.newBitstreamException(BitstreamErrors.UNKNOWN_ERROR); } } h_layer = 4 - (SupportClass.URShift(headerstring, 17)) & 3; h_protection_bit = (SupportClass.URShift(headerstring, 16)) & 1; h_bitrate_index = (SupportClass.URShift(headerstring, 12)) & 0xF; h_padding_bit = (SupportClass.URShift(headerstring, 9)) & 1; h_mode = ((SupportClass.URShift(headerstring, 6)) & 3); h_mode_extension = (SupportClass.URShift(headerstring, 4)) & 3; if (h_mode == JOINT_STEREO) h_intensity_stereo_bound = (h_mode_extension << 2) + 4; else h_intensity_stereo_bound = 0; // should never be used if (((SupportClass.URShift(headerstring, 3)) & 1) == 1) h_copyright = true; if (((SupportClass.URShift(headerstring, 2)) & 1) == 1) h_original = true; // calculate number of subbands: if (h_layer == 1) h_number_of_subbands = 32; else { channel_bitrate = h_bitrate_index; // calculate bitrate per channel: if (h_mode != SINGLE_CHANNEL) if (channel_bitrate == 4) channel_bitrate = 1; else channel_bitrate -= 4; if ((channel_bitrate == 1) || (channel_bitrate == 2)) if (h_sample_frequency == THIRTYTWO) h_number_of_subbands = 12; else h_number_of_subbands = 8; else if ((h_sample_frequency == FOURTYEIGHT) || ((channel_bitrate >= 3) && (channel_bitrate <= 5))) h_number_of_subbands = 27; else h_number_of_subbands = 30; } if (h_intensity_stereo_bound > h_number_of_subbands) h_intensity_stereo_bound = h_number_of_subbands; // calculate framesize and nSlots calculate_framesize(); // read framedata: stream.read_frame_data(framesize); if (stream.IsSyncCurrentPosition(syncmode)) { if (syncmode == Bitstream.INITIAL_SYNC) { syncmode = Bitstream.STRICT_SYNC; stream.SetSyncWord(headerstring & unchecked((int) 0xFFF80CC0)); } sync = true; } else { stream.unreadFrame(); } } while (!sync); stream.ParseFrame(); if (h_protection_bit == 0) { // frame contains a crc checksum checksum = (short) stream.GetBitsFromBuffer(16); if (crc == null) crc = new Crc16(); crc.add_bits(headerstring, 16); crcp[0] = crc; } else crcp[0] = null; if (h_sample_frequency == FOURTYFOUR_POINT_ONE) { /* if (offset == null) { int max = max_number_of_frames(stream); offset = new int[max]; for(int i=0; i<max; i++) offset[i] = 0; } // Bizarre, y avait ici une acollade ouvrante int cf = stream.current_frame(); int lf = stream.last_frame(); if ((cf > 0) && (cf == lf)) { offset[cf] = offset[cf-1] + h_padding_bit; } else { offset[0] = h_padding_bit; } */ } }