public virtual void create(Bitstream stream0, Header header0, SynthesisFilter filtera, SynthesisFilter filterb, Obuffer buffer0, int which_ch0) { stream = stream0; header = header0; filter1 = filtera; filter2 = filterb; buffer = buffer0; which_channels = which_ch0; }
/// <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 void read_allocation(Bitstream stream, Header header, Crc16 crc) { base.read_allocation(stream, header, crc); }
/// <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]; } }
public virtual void decodedFrame(int frameNo, Header header, Obuffer o) { if (isDetail(MAX_DETAIL)) { //UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' System.String headerString = header.ToString(); pw.WriteLine("Decoded frame " + frameNo + ": " + headerString); pw.WriteLine("Output: " + o); } else if (isDetail(VERBOSE_DETAIL)) { if (frameNo == 0) { pw.Write("Converting."); pw.Flush(); } if ((frameNo % 10) == 0) { pw.Write('.'); pw.Flush(); } } }
protected internal virtual FrameDecoder retrieveDecoder(Header header, Bitstream stream, int layer) { FrameDecoder decoder = null; // REVIEW: allow channel output selection type // (LEFT, RIGHT, BOTH, DOWNMIX) switch (layer) { case 3: if (l3decoder == null) { l3decoder = new LayerIIIDecoder(stream, header, filter1, filter2, output, (int)OutputChannelsEnum.BOTH_CHANNELS); } decoder = l3decoder; break; case 2: if (l2decoder == null) { l2decoder = new LayerIIDecoder(); l2decoder.create(stream, header, filter1, filter2, output, (int)OutputChannelsEnum.BOTH_CHANNELS); } decoder = l2decoder; break; case 1: if (l1decoder == null) { l1decoder = new LayerIDecoder(); l1decoder.create(stream, header, filter1, filter2, output, (int)OutputChannelsEnum.BOTH_CHANNELS); } decoder = l1decoder; break; } if (decoder == null) { throw newDecoderException(javazoom.jl.decoder.DecoderErrors_Fields.UNSUPPORTED_LAYER, null); } return decoder; }
private void InitBlock() { crc = new Crc16[1]; syncbuf = new sbyte[4]; frame_bytes = new sbyte[BUFFER_INT_SIZE * 4]; framebuffer = new int[BUFFER_INT_SIZE]; header = new Header(); }
/// <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>* /// </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>* /// </summary> protected internal virtual void prepare_sample_reading(Header header, int allocation, int channel, float[] factor, int[] codelength, float[] c, float[] d) { int channel_bitrate = header.bitrate_index(); // calculate bitrate per channel: if (header.mode() != Header.SINGLE_CHANNEL) if (channel_bitrate == 4) channel_bitrate = 1; else channel_bitrate -= 4; if (channel_bitrate == 1 || channel_bitrate == 2) { // table 3-B.2c or 3-B.2d groupingtable[channel] = table_cd_groupingtables[allocation]; factor[0] = table_cd_factor[allocation]; codelength[0] = table_cd_codelength[allocation]; c[0] = table_cd_c[allocation]; d[0] = table_cd_d[allocation]; } else { // tables 3-B.2a or 3-B.2b if (subbandnumber <= 2) { groupingtable[channel] = table_ab1_groupingtables[allocation]; factor[0] = table_ab1_factor[allocation]; codelength[0] = table_ab1_codelength[allocation]; c[0] = table_ab1_c[allocation]; d[0] = table_ab1_d[allocation]; } else { groupingtable[channel] = table_ab234_groupingtables[allocation]; if (subbandnumber <= 10) { factor[0] = table_ab2_factor[allocation]; codelength[0] = table_ab2_codelength[allocation]; c[0] = table_ab2_c[allocation]; d[0] = table_ab2_d[allocation]; } else if (subbandnumber <= 22) { factor[0] = table_ab3_factor[allocation]; codelength[0] = table_ab3_codelength[allocation]; c[0] = table_ab3_c[allocation]; d[0] = table_ab3_d[allocation]; } else { factor[0] = table_ab4_factor[allocation]; codelength[0] = table_ab4_codelength[allocation]; c[0] = table_ab4_c[allocation]; d[0] = table_ab4_d[allocation]; } } } }
/// <summary>* /// </summary> protected internal virtual int get_allocationlength(Header header) { if (header.version() == Header.MPEG1) { int channel_bitrate = header.bitrate_index(); // calculate bitrate per channel: if (header.mode() != Header.SINGLE_CHANNEL) if (channel_bitrate == 4) channel_bitrate = 1; else channel_bitrate -= 4; if (channel_bitrate == 1 || channel_bitrate == 2) // table 3-B.2c or 3-B.2d if (subbandnumber <= 1) return 4; else return 3; // tables 3-B.2a or 3-B.2b else if (subbandnumber <= 10) return 4; else if (subbandnumber <= 22) return 3; else return 2; } else { // MPEG-2 LSF -- Jeff // table B.1 of ISO/IEC 13818-3 if (subbandnumber <= 3) return 4; else if (subbandnumber <= 10) return 3; else return 2; } }
/// <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); } }
public virtual void readFrame(int frameNo, Header header) { if ((frameNo == 0) && isDetail(VERBOSE_DETAIL)) { //UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' System.String headerString = header.ToString(); pw.WriteLine("File is a " + headerString); } else if (isDetail(MAX_DETAIL)) { //UPGRADE_TODO: The equivalent in .NET for method 'java.Object.toString' may return a different value. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1043"' System.String headerString = header.ToString(); pw.WriteLine("Read frame " + frameNo + ": " + headerString); } }
/// <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> Constructor. /// </summary> // REVIEW: these constructor arguments should be moved to the // decodeFrame() method, where possible, so that one public LayerIIIDecoder(Bitstream stream0, Header header0, SynthesisFilter filtera, SynthesisFilter filterb, Obuffer buffer0, int which_ch0) { InitBlock(); huffcodetab.inithuff(); is_1d = new int[SBLIMIT * SSLIMIT + 4]; ro = new float[2][][]; for (int i = 0; i < 2; i++) { ro[i] = new float[SBLIMIT][]; for (int i2 = 0; i2 < SBLIMIT; i2++) { ro[i][i2] = new float[SSLIMIT]; } } lr = new float[2][][]; for (int i3 = 0; i3 < 2; i3++) { lr[i3] = new float[SBLIMIT][]; for (int i4 = 0; i4 < SBLIMIT; i4++) { lr[i3][i4] = new float[SSLIMIT]; } } out_1d = new float[SBLIMIT * SSLIMIT]; prevblck = new float[2][]; for (int i5 = 0; i5 < 2; i5++) { prevblck[i5] = new float[SBLIMIT * SSLIMIT]; } k = new float[2][]; for (int i6 = 0; i6 < 2; i6++) { k[i6] = new float[SBLIMIT * SSLIMIT]; } nonzero = new int[2]; //III_scalefact_t III_scalefac_t = new temporaire2[2]; III_scalefac_t[0] = new temporaire2(); III_scalefac_t[1] = new temporaire2(); scalefac = III_scalefac_t; // L3TABLE INIT sfBandIndex = new SBI[9]; // SZD: MPEG2.5 +3 indices int[] l0 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576}; int[] s0 = new int[]{0, 4, 8, 12, 18, 24, 32, 42, 56, 74, 100, 132, 174, 192}; int[] l1 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 114, 136, 162, 194, 232, 278, 330, 394, 464, 540, 576}; int[] s1 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 136, 180, 192}; int[] l2 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576}; int[] s2 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192}; int[] l3 = new int[]{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 52, 62, 74, 90, 110, 134, 162, 196, 238, 288, 342, 418, 576}; int[] s3 = new int[]{0, 4, 8, 12, 16, 22, 30, 40, 52, 66, 84, 106, 136, 192}; int[] l4 = new int[]{0, 4, 8, 12, 16, 20, 24, 30, 36, 42, 50, 60, 72, 88, 106, 128, 156, 190, 230, 276, 330, 384, 576}; int[] s4 = new int[]{0, 4, 8, 12, 16, 22, 28, 38, 50, 64, 80, 100, 126, 192}; int[] l5 = new int[]{0, 4, 8, 12, 16, 20, 24, 30, 36, 44, 54, 66, 82, 102, 126, 156, 194, 240, 296, 364, 448, 550, 576}; int[] s5 = new int[]{0, 4, 8, 12, 16, 22, 30, 42, 58, 78, 104, 138, 180, 192}; // SZD: MPEG2.5 int[] l6 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576}; int[] s6 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192}; int[] l7 = new int[]{0, 6, 12, 18, 24, 30, 36, 44, 54, 66, 80, 96, 116, 140, 168, 200, 238, 284, 336, 396, 464, 522, 576}; int[] s7 = new int[]{0, 4, 8, 12, 18, 26, 36, 48, 62, 80, 104, 134, 174, 192}; int[] l8 = new int[]{0, 12, 24, 36, 48, 60, 72, 88, 108, 132, 160, 192, 232, 280, 336, 400, 476, 566, 568, 570, 572, 574, 576}; int[] s8 = new int[]{0, 8, 16, 24, 36, 52, 72, 96, 124, 160, 162, 164, 166, 192}; sfBandIndex[0] = new SBI(l0, s0); sfBandIndex[1] = new SBI(l1, s1); sfBandIndex[2] = new SBI(l2, s2); sfBandIndex[3] = new SBI(l3, s3); sfBandIndex[4] = new SBI(l4, s4); sfBandIndex[5] = new SBI(l5, s5); //SZD: MPEG2.5 sfBandIndex[6] = new SBI(l6, s6); sfBandIndex[7] = new SBI(l7, s7); sfBandIndex[8] = new SBI(l8, s8); // END OF L3TABLE INIT if (reorder_table == null) { // SZD: generate LUT reorder_table = new int[9][]; for (int i = 0; i < 9; i++) reorder_table[i] = reorder(sfBandIndex[i].s); } // Sftable int[] ll0 = new int[]{0, 6, 11, 16, 21}; int[] ss0 = new int[]{0, 6, 12}; sftable = new Sftable(this, ll0, ss0); // END OF Sftable // scalefac_buffer scalefac_buffer = new int[54]; // END OF scalefac_buffer stream = stream0; header = header0; filter1 = filtera; filter2 = filterb; buffer = buffer0; which_channels = which_ch0; frame_start = 0; channels = (header.mode() == Header.SINGLE_CHANNEL)?1:2; max_gr = (header.version() == Header.MPEG1)?2:1; sfreq = header.sample_frequency() + ((header.version() == Header.MPEG1)?3:(header.version() == Header.MPEG25_LSF)?6:0); // SZD if (channels == 2) { switch (which_channels) { case (int)OutputChannelsEnum.LEFT_CHANNEL: case (int)OutputChannelsEnum.DOWNMIX_CHANNELS: first_channel = last_channel = 0; break; case (int)OutputChannelsEnum.RIGHT_CHANNEL: first_channel = last_channel = 1; break; case (int)OutputChannelsEnum.BOTH_CHANNELS: default: first_channel = 0; last_channel = 1; break; } } else { first_channel = last_channel = 0; } for (int ch = 0; ch < 2; ch++) for (int j = 0; j < 576; j++) prevblck[ch][j] = 0.0f; nonzero[0] = nonzero[1] = 576; br = new BitReserve(); si = new III_side_info_t(); }
public abstract void read_allocation(Bitstream stream, Header header, Crc16 crc);
/// <summary> Decodes one frame from an MPEG audio bitstream. /// /// </summary> /// <param name="header The">header describing the frame to decode. /// </param> /// <param name="bitstream The">bistream that provides the bits for te body of the frame. /// /// </param> /// <returns> A SampleBuffer containing the decoded samples. /// /// </returns> public virtual Obuffer decodeFrame(Header header, Bitstream stream) { if (!initialized) { initialize(header); } int layer = header.layer(); output.clear_buffer(); FrameDecoder decoder = retrieveDecoder(header, stream, layer); decoder.decodeFrame(); output.write_buffer(1); return output; }
public abstract void read_scalefactor(Bitstream stream, Header header);
private void initialize(Header header) { // REVIEW: allow customizable scale factor float scalefactor = 32700.0f; int mode = header.mode(); int layer = header.layer(); int channels = mode == Header.SINGLE_CHANNEL?1:2; // set up output buffer if not set up by client. if (output == null) output = new SampleBuffer(header.frequency(), channels); float[] factors = equalizer.BandFactors; //Console.WriteLine("NOT CREATING SYNTHESIS FILTERS"); filter1 = new SynthesisFilter(0, scalefactor, factors); // REVIEW: allow mono output for stereo if (channels == 2) filter2 = new SynthesisFilter(1, scalefactor, factors); outputChannels = channels; outputFrequency = header.frequency(); initialized = true; }
/// <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]; } }