/// <summary>* /// </summary> public override void read_scalefactor(Bitstream stream, Header header) { if (allocation != 0) { scalefactor = scalefactors[stream.get_bits(6)]; channel2_scalefactor = scalefactors[stream.get_bits(6)]; } }
/// <summary>* /// </summary> public override bool read_sampledata(Bitstream stream) { bool returnvalue = base.read_sampledata(stream); if (channel2_allocation != 0) { channel2_sample = (float)(stream.get_bits(channel2_samplelength)); } return(returnvalue); }
/// <summary>* /// </summary> public override void read_allocation(Bitstream stream, Header header, Crc16 crc) { allocation = stream.get_bits(4); channel2_allocation = stream.get_bits(4); if (crc != null) { crc.add_bits(allocation, 4); crc.add_bits(channel2_allocation, 4); } if (allocation != 0) { samplelength = allocation + 1; factor = table_factor[allocation]; offset = table_offset[allocation]; } if (channel2_allocation != 0) { channel2_samplelength = channel2_allocation + 1; channel2_factor = table_factor[channel2_allocation]; channel2_offset = table_offset[channel2_allocation]; } }
/// <summary>* /// </summary> public override bool read_sampledata(Bitstream stream) { if (allocation != 0) { sample = (float)(stream.get_bits(samplelength)); } if (++samplenumber == 12) { samplenumber = 0; return(true); } return(false); }
/// <summary>* /// </summary> public override void read_allocation(Bitstream stream, Header header, Crc16 crc) { if ((allocation = stream.get_bits(4)) == 15) { } // cerr << "WARNING: stream contains an illegal allocation!\n"; // MPEG-stream is corrupted! if (crc != null) { crc.add_bits(allocation, 4); } if (allocation != 0) { samplelength = allocation + 1; factor = table_factor[allocation]; offset = table_offset[allocation]; } }
/// <summary>* /// </summary> public override void read_scalefactor_selection(Bitstream stream, Crc16 crc) { if (allocation != 0) { scfsi = stream.get_bits(2); if (crc != null) crc.add_bits(scfsi, 2); } if (channel2_allocation != 0) { channel2_scfsi = stream.get_bits(2); if (crc != null) crc.add_bits(channel2_scfsi, 2); } }
/// <summary>* /// </summary> public override void read_scalefactor(Bitstream stream, Header header) { base.read_scalefactor(stream, header); if (channel2_allocation != 0) { switch (channel2_scfsi) { case 0: channel2_scalefactor1 = scalefactors[stream.get_bits(6)]; channel2_scalefactor2 = scalefactors[stream.get_bits(6)]; channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 1: channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream.get_bits(6)]; channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 2: channel2_scalefactor1 = channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 3: channel2_scalefactor1 = scalefactors[stream.get_bits(6)]; channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; } prepare_sample_reading(header, channel2_allocation, 1, channel2_factor, channel2_codelength, channel2_c, channel2_d); } }
/// <summary>* /// </summary> public override bool read_sampledata(Bitstream stream) { bool returnvalue = base.read_sampledata(stream); if (channel2_allocation != 0) if (groupingtable[1] != null) { int samplecode = stream.get_bits(channel2_codelength[0]); // create requantized samples: samplecode += samplecode << 1; /* float[] target = channel2_samples; float[] source = channel2_groupingtable[0]; int tmp = 0; int temp = 0; target[tmp++] = source[samplecode + temp]; temp++; target[tmp++] = source[samplecode + temp]; temp++; target[tmp] = source[samplecode + temp]; // memcpy (channel2_samples, channel2_groupingtable + samplecode, 3 * sizeof (real)); */ float[] target = channel2_samples; float[] source = groupingtable[1]; int tmp = 0; int temp = samplecode; target[tmp] = source[temp]; temp++; tmp++; target[tmp] = source[temp]; temp++; tmp++; target[tmp] = source[temp]; } else { channel2_samples[0] = (float) ((stream.get_bits(channel2_codelength[0])) * channel2_factor[0] - 1.0); channel2_samples[1] = (float) ((stream.get_bits(channel2_codelength[0])) * channel2_factor[0] - 1.0); channel2_samples[2] = (float) ((stream.get_bits(channel2_codelength[0])) * channel2_factor[0] - 1.0); } return returnvalue; }
/// <summary>* /// </summary> public override void read_allocation(Bitstream stream, Header header, Crc16 crc) { int length = get_allocationlength(header); allocation = stream.get_bits(length); channel2_allocation = stream.get_bits(length); if (crc != null) { crc.add_bits(allocation, length); crc.add_bits(channel2_allocation, length); } }
/// <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(javazoom.jl.decoder.BitstreamErrors_Fields.UNKNOWN_ERROR); if ((h_sample_frequency = ((SupportClass.URShift(headerstring, 10)) & 3)) == 3) { throw stream.newBitstreamException(javazoom.jl.decoder.BitstreamErrors_Fields.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.set_syncword(headerstring & unchecked((int)0xFFF80CC0)); } sync = true; } else { stream.unreadFrame(); } } while (!sync); stream.parse_frame(); if (h_protection_bit == 0) { // frame contains a crc checksum checksum = (short) stream.get_bits(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>* /// </summary> public override void read_scalefactor(Bitstream stream, Header header) { if (allocation != 0) scalefactor = scalefactors[stream.get_bits(6)]; if (channel2_allocation != 0) channel2_scalefactor = scalefactors[stream.get_bits(6)]; }
/// <summary>* /// </summary> public override void read_allocation(Bitstream stream, Header header, Crc16 crc) { allocation = stream.get_bits(4); channel2_allocation = stream.get_bits(4); // try/catch block to handle invalid allocation // (catch array bounds error) try { if (crc != null) { crc.add_bits(allocation, 4); crc.add_bits(channel2_allocation, 4); } if (allocation != 0) { samplelength = allocation + 1; factor = table_factor[allocation]; offset = table_offset[allocation]; } if (channel2_allocation != 0) { channel2_samplelength = channel2_allocation + 1; channel2_factor = table_factor[channel2_allocation]; channel2_offset = table_offset[channel2_allocation]; } } catch (IndexOutOfRangeException ) { // array bounds error? Invalid allocation // (or unsupported). Ignore for now. } }
/// <summary>* /// </summary> public override bool read_sampledata(Bitstream stream) { if (allocation != 0) if (groupingtable[0] != null) { int samplecode = stream.get_bits(codelength[0]); // create requantized samples: samplecode += samplecode << 1; float[] target = samples; float[] source = groupingtable[0]; /* int tmp = 0; int temp = 0; target[tmp++] = source[samplecode + temp]; temp++; target[tmp++] = source[samplecode + temp]; temp++; target[tmp] = source[samplecode + temp]; */ //Bugfix: int tmp = 0; int temp = samplecode; if (temp > source.Length - 3) temp = source.Length - 3; target[tmp] = source[temp]; temp++; tmp++; target[tmp] = source[temp]; temp++; tmp++; target[tmp] = source[temp]; // memcpy (samples, groupingtable + samplecode, 3 * sizeof (real)); } else { samples[0] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0); samples[1] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0); samples[2] = (float) ((stream.get_bits(codelength[0])) * factor[0] - 1.0); } samplenumber = 0; if (++groupnumber == 12) return true; else return false; }
/// <summary>* /// </summary> public override void read_allocation(Bitstream stream, Header header, Crc16 crc) { if ((allocation = stream.get_bits(4)) == 15) { } // cerr << "WARNING: stream contains an illegal allocation!\n"; // MPEG-stream is corrupted! if (crc != null) crc.add_bits(allocation, 4); if (allocation != 0) { samplelength = allocation + 1; factor = table_factor[allocation]; offset = table_offset[allocation]; } }
/// <summary>* /// </summary> public override void read_scalefactor(Bitstream stream, Header header) { if (allocation != 0) { switch (scfsi) { case 0: scalefactor1 = scalefactors[stream.get_bits(6)]; scalefactor2 = scalefactors[stream.get_bits(6)]; scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 1: scalefactor1 = scalefactor2 = scalefactors[stream.get_bits(6)]; scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 2: scalefactor1 = scalefactor2 = scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 3: scalefactor1 = scalefactors[stream.get_bits(6)]; scalefactor2 = scalefactor3 = scalefactors[stream.get_bits(6)]; break; } prepare_sample_reading(header, allocation, 0, factor, codelength, c, d); } }
/// <summary>* /// </summary> public override bool read_sampledata(Bitstream stream) { if (allocation != 0) { sample = (float) (stream.get_bits(samplelength)); } if (++samplenumber == 12) { samplenumber = 0; return true; } return false; }
/// <summary>* /// </summary> public virtual void read_scalefactor_selection(Bitstream stream, Crc16 crc) { if (allocation != 0) { scfsi = stream.get_bits(2); if (crc != null) crc.add_bits(scfsi, 2); } }
/// <summary>* /// </summary> public override bool read_sampledata(Bitstream stream) { bool returnvalue = base.read_sampledata(stream); if (channel2_allocation != 0) { channel2_sample = (float) (stream.get_bits(channel2_samplelength)); } return (returnvalue); }
/// <summary>* /// </summary> public override void read_scalefactor(Bitstream stream, Header header) { if (allocation != 0) { base.read_scalefactor(stream, header); switch (channel2_scfsi) { case 0: channel2_scalefactor1 = scalefactors[stream.get_bits(6)]; channel2_scalefactor2 = scalefactors[stream.get_bits(6)]; channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 1: channel2_scalefactor1 = channel2_scalefactor2 = scalefactors[stream.get_bits(6)]; channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 2: channel2_scalefactor1 = channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; case 3: channel2_scalefactor1 = scalefactors[stream.get_bits(6)]; channel2_scalefactor2 = channel2_scalefactor3 = scalefactors[stream.get_bits(6)]; break; } } }
/// <summary> Read a 32-bit header from the bitstream. /// </summary> public void read_header(Bitstream stream, Crc16[] crcp) { int headerstring; int channel_bitrate; bool sync = false; ////System.Diagnostics.Trace.WriteLine("Header - read_header"); do { ////System.Diagnostics.Trace.WriteLine("Header - read_header - syncHeader"); headerstring = stream.syncHeader(syncmode); _headerstring = headerstring; // E.B ////System.Diagnostics.Trace.WriteLine("Header - sync"); if (syncmode == Bitstream.INITIAL_SYNC) { ////System.Diagnostics.Trace.WriteLine("Header - read_header - bit shifting"); 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(javazoom.jl.decoder.BitstreamErrors_Fields.UNKNOWN_ERROR); } } if ((h_sample_frequency = ((SupportClass.URShift(headerstring, 10)) & 3)) == 3) { throw stream.newBitstreamException(javazoom.jl.decoder.BitstreamErrors_Fields.UNKNOWN_ERROR); } } ////System.Diagnostics.Trace.WriteLine("Header - read_header - more bit shifting"); 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; } ////System.Diagnostics.Trace.WriteLine("Header - read_header - calculate subbands"); // calculate number of subbands: if (h_layer == 1) { h_number_of_subbands = 32; } else { ////System.Diagnostics.Trace.WriteLine("Header - read_header - manage bitrates"); 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 ////System.Diagnostics.Trace.WriteLine("Header - read_header - calculate framesize"); calculate_framesize(); ////System.Diagnostics.Trace.WriteLine("Header - read_header - calculate read frame data"); // read framedata: stream.read_frame_data(framesize); if (stream.isSyncCurrentPosition(syncmode)) { if (syncmode == Bitstream.INITIAL_SYNC) { syncmode = Bitstream.STRICT_SYNC; stream.set_syncword(headerstring & unchecked ((int)0xFFF80CC0)); } sync = true; } else { stream.unreadFrame(); } }while (!sync); ////System.Diagnostics.Trace.WriteLine("Header - read_header - syncing:" +sync.ToString()); stream.parse_frame(); if (h_protection_bit == 0) { // frame contains a crc checksum checksum = (short)stream.get_bits(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) { /*//HACKED * 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; * }*/ } ////System.Diagnostics.Trace.WriteLine("Header - read_header end"); }