src/main/java/net/sourceforge/jaad/aac/sbr/SBR.java
private int sbr_channel_pair_element(IBitStream ld) throws AACException {
		int n, result;

		if(ld.readBool()) {
			//reserved
			ld.readBits(4);
			ld.readBits(4);
		}

		this.bs_coupling = ld.readBool();

		if(this.bs_coupling) {
			if((result = sbr_grid(ld, 0))>0)
				return result;

			/* need to copy some data from left to right */
			this.bs_frame_class[1] = this.bs_frame_class[0];
			this.L_E[1] = this.L_E[0];
			this.L_Q[1] = this.L_Q[0];
			this.bs_pointer[1] = this.bs_pointer[0];

			for(n = 0; n<=this.L_E[0]; n++) {
				this.t_E[1][n] = this.t_E[0][n];
				this.f[1][n] = this.f[0][n];
			}
			for(n = 0; n<=this.L_Q[0]; n++) {
				this.t_Q[1][n] = this.t_Q[0][n];
			}

			sbr_dtdf(ld, 0);
			sbr_dtdf(ld, 1);
			invf_mode(ld, 0);

			/* more copying */
			for(n = 0; n<this.N_Q; n++) {
				this.bs_invf_mode[1][n] = this.bs_invf_mode[0][n];
			}

			sbr_envelope(ld, 0);
			sbr_noise(ld, 0);
			sbr_envelope(ld, 1);
			sbr_noise(ld, 1);

			Arrays.fill(bs_add_harmonic[0], 0, 64, 0);
			Arrays.fill(bs_add_harmonic[1], 0, 64, 0);

			this.bs_add_harmonic_flag[0] = ld.readBool();
			if(this.bs_add_harmonic_flag[0])
				sinusoidal_coding(ld, 0);

			this.bs_add_harmonic_flag[1] = ld.readBool();
			if(this.bs_add_harmonic_flag[1])
				sinusoidal_coding(ld, 1);
		}
		else {
			int[] saved_t_E = new int[6], saved_t_Q = new int[3];
			int saved_L_E = this.L_E[0];
			int saved_L_Q = this.L_Q[0];
			int saved_frame_class = this.bs_frame_class[0];

			for(n = 0; n<saved_L_E; n++) {
				saved_t_E[n] = this.t_E[0][n];
			}
			for(n = 0; n<saved_L_Q; n++) {
				saved_t_Q[n] = this.t_Q[0][n];
			}

			if((result = sbr_grid(ld, 0))>0)
				return result;
			if((result = sbr_grid(ld, 1))>0) {
				/* restore first channel data as well */
				this.bs_frame_class[0] = saved_frame_class;
				this.L_E[0] = saved_L_E;
				this.L_Q[0] = saved_L_Q;
				for(n = 0; n<6; n++) {
					this.t_E[0][n] = saved_t_E[n];
				}
				for(n = 0; n<3; n++) {
					this.t_Q[0][n] = saved_t_Q[n];
				}

				return result;
			}
			sbr_dtdf(ld, 0);
			sbr_dtdf(ld, 1);
			invf_mode(ld, 0);
			invf_mode(ld, 1);
			sbr_envelope(ld, 0);
			sbr_envelope(ld, 1);
			sbr_noise(ld, 0);
			sbr_noise(ld, 1);

			Arrays.fill(bs_add_harmonic[0], 0, 64, 0);
			Arrays.fill(bs_add_harmonic[1], 0, 64, 0);

			this.bs_add_harmonic_flag[0] = ld.readBool();
			if(this.bs_add_harmonic_flag[0])
				sinusoidal_coding(ld, 0);

			this.bs_add_harmonic_flag[1] = ld.readBool();
			if(this.bs_add_harmonic_flag[1])
				sinusoidal_coding(ld, 1);
		}
		NoiseEnvelope.dequantChannel(this, 0);
		NoiseEnvelope.dequantChannel(this, 1);

		if(this.bs_coupling)
			NoiseEnvelope.unmap(this);

		this.bs_extended_data = ld.readBool();
		if(this.bs_extended_data) {
			int nr_bits_left;
			int cnt = ld.readBits(4);
			if(cnt==15) {
				cnt += ld.readBits(8);
			}

			nr_bits_left = 8*cnt;
			while(nr_bits_left>7) {
				int tmp_nr_bits = 0;

				this.bs_extension_id = ld.readBits(2);
				tmp_nr_bits += 2;
				tmp_nr_bits += sbr_extension(ld, this.bs_extension_id, nr_bits_left);

				/* check if the data read is bigger than the number of available bits */
				if(tmp_nr_bits>nr_bits_left)
					return 1;

				nr_bits_left -= tmp_nr_bits;
			}

			/* Corrigendum */
			if(nr_bits_left>0) {
				ld.readBits(nr_bits_left);
			}
		}

		return 0;
	}
private int sbr_channel_pair_element(IBitStream ld) throws AACException {
		int n, result;

		if(ld.readBool()) {
			//reserved
			ld.readBits(4);
			ld.readBits(4);
		}

		this.bs_coupling = ld.readBool();

		if(this.bs_coupling) {
			if((result = sbr_grid(ld, 0))>0)
				return result;

			/* need to copy some data from left to right */
			this.bs_frame_class[1] = this.bs_frame_class[0];
			this.L_E[1] = this.L_E[0];
			this.L_Q[1] = this.L_Q[0];
			this.bs_pointer[1] = this.bs_pointer[0];

			for(n = 0; n<=this.L_E[0]; n++) {
				this.t_E[1][n] = this.t_E[0][n];
				this.f[1][n] = this.f[0][n];
			}
			for(n = 0; n<=this.L_Q[0]; n++) {
				this.t_Q[1][n] = this.t_Q[0][n];
			}

			sbr_dtdf(ld, 0);
			sbr_dtdf(ld, 1);
			invf_mode(ld, 0);

			/* more copying */
			for(n = 0; n<this.N_Q; n++) {
				this.bs_invf_mode[1][n] = this.bs_invf_mode[0][n];
			}

			sbr_envelope(ld, 0);
			sbr_noise(ld, 0);
			sbr_envelope(ld, 1);
			sbr_noise(ld, 1);

			Arrays.fill(bs_add_harmonic[0], 0, 64, 0);
			Arrays.fill(bs_add_harmonic[1], 0, 64, 0);

			this.bs_add_harmonic_flag[0] = ld.readBool();
			if(this.bs_add_harmonic_flag[0])
				sinusoidal_coding(ld, 0);

			this.bs_add_harmonic_flag[1] = ld.readBool();
			if(this.bs_add_harmonic_flag[1])
				sinusoidal_coding(ld, 1);
		}
		else {
			int[] saved_t_E = new int[6], saved_t_Q = new int[3];
			int saved_L_E = this.L_E[0];
			int saved_L_Q = this.L_Q[0];
			int saved_frame_class = this.bs_frame_class[0];

			for(n = 0; n<saved_L_E; n++) {
				saved_t_E[n] = this.t_E[0][n];
			}
			for(n = 0; n<saved_L_Q; n++) {
				saved_t_Q[n] = this.t_Q[0][n];
			}

			if((result = sbr_grid(ld, 0))>0)
				return result;
			if((result = sbr_grid(ld, 1))>0) {
				/* restore first channel data as well */
				this.bs_frame_class[0] = saved_frame_class;
				this.L_E[0] = saved_L_E;
				this.L_Q[0] = saved_L_Q;
				for(n = 0; n<6; n++) {
					this.t_E[0][n] = saved_t_E[n];
				}
				for(n = 0; n<3; n++) {
					this.t_Q[0][n] = saved_t_Q[n];
				}

				return result;
			}
			sbr_dtdf(ld, 0);
			sbr_dtdf(ld, 1);
			invf_mode(ld, 0);
			invf_mode(ld, 1);
			sbr_envelope(ld, 0);
			sbr_envelope(ld, 1);
			sbr_noise(ld, 0);
			sbr_noise(ld, 1);

			Arrays.fill(bs_add_harmonic[0], 0, 64, 0);
			Arrays.fill(bs_add_harmonic[1], 0, 64, 0);

			this.bs_add_harmonic_flag[0] = ld.readBool();
			if(this.bs_add_harmonic_flag[0])
				sinusoidal_coding(ld, 0);

			this.bs_add_harmonic_flag[1] = ld.readBool();
			if(this.bs_add_harmonic_flag[1])
				sinusoidal_coding(ld, 1);
		}
		NoiseEnvelope.dequantChannel(this, 0);
		NoiseEnvelope.dequantChannel(this, 1);

		if(this.bs_coupling)
			NoiseEnvelope.unmap(this);

		this.bs_extended_data = ld.readBool();
		if(this.bs_extended_data) {
			int nr_bits_left;
			int cnt = ld.readBits(4);
			if(cnt==15) {
				cnt += ld.readBits(8);
			}

			nr_bits_left = 8*cnt;
			while(nr_bits_left>7) {
				int tmp_nr_bits = 0;

				this.bs_extension_id = ld.readBits(2);
				tmp_nr_bits += 2;
				tmp_nr_bits += sbr_extension(ld, this.bs_extension_id, nr_bits_left);

				/* check if the data read is bigger than the number of available bits */
				if(tmp_nr_bits>nr_bits_left)
					return 1;

				nr_bits_left -= tmp_nr_bits;
			}

			/* Corrigendum */
			if(nr_bits_left>0) {
				ld.readBits(nr_bits_left);
			}
		}

		return 0;
	}
/* table 6