src/main/java/net/sourceforge/jaad/aac/ps/PS.java
private void ps_data_decode() {
		int env, bin;

		/* ps data not available, use data from previous frame */
		if(this.ps_data_available==0) {
			this.num_env = 0;
		}

		for(env = 0; env<this.num_env; env++) {
			int[] iid_index_prev;
			int[] icc_index_prev;
			int[] ipd_index_prev;
			int[] opd_index_prev;

			int num_iid_steps = (this.iid_mode<3) ? 7 : 15 /*fine quant*/;

			if(env==0) {
				/* take last envelope from previous frame */
				iid_index_prev = this.iid_index_prev;
				icc_index_prev = this.icc_index_prev;
				ipd_index_prev = this.ipd_index_prev;
				opd_index_prev = this.opd_index_prev;
			}
			else {
				/* take index values from previous envelope */
				iid_index_prev = this.iid_index[env-1];
				icc_index_prev = this.icc_index[env-1];
				ipd_index_prev = this.ipd_index[env-1];
				opd_index_prev = this.opd_index[env-1];
			}

//        iid = 1;
        /* delta decode iid parameters */
			delta_decode(this.enable_iid, this.iid_index[env], iid_index_prev,
				this.iid_dt[env], this.nr_iid_par,
				(this.iid_mode==0||this.iid_mode==3) ? 2 : 1,
				-num_iid_steps, num_iid_steps);
//        iid = 0;

			/* delta decode icc parameters */
			delta_decode(this.enable_icc, this.icc_index[env], icc_index_prev,
				this.icc_dt[env], this.nr_icc_par,
				(this.icc_mode==0||this.icc_mode==3) ? 2 : 1,
				0, 7);

			/* delta modulo decode ipd parameters */
			delta_modulo_decode(this.enable_ipdopd, this.ipd_index[env], ipd_index_prev,
				this.ipd_dt[env], this.nr_ipdopd_par, 1, 7);

			/* delta modulo decode opd parameters */
			delta_modulo_decode(this.enable_ipdopd, this.opd_index[env], opd_index_prev,
				this.opd_dt[env], this.nr_ipdopd_par, 1, 7);
		}

		/* handle error case */
		if(this.num_env==0) {
			/* force to 1 */
			this.num_env = 1;

			if(this.enable_iid) {
				for(bin = 0; bin<34; bin++) {
					this.iid_index[0][bin] = this.iid_index_prev[bin];
				}
			}
			else {
				for(bin = 0; bin<34; bin++) {
					this.iid_index[0][bin] = 0;
				}
			}

			if(this.enable_icc) {
				for(bin = 0; bin<34; bin++) {
					this.icc_index[0][bin] = this.icc_index_prev[bin];
				}
			}
			else {
				for(bin = 0; bin<34; bin++) {
					this.icc_index[0][bin] = 0;
				}
			}

			if(this.enable_ipdopd) {
				for(bin = 0; bin<17; bin++) {
					this.ipd_index[0][bin] = this.ipd_index_prev[bin];
					this.opd_index[0][bin] = this.opd_index_prev[bin];
				}
			}
			else {
				for(bin = 0; bin<17; bin++) {
					this.ipd_index[0][bin] = 0;
					this.opd_index[0][bin] = 0;
				}
			}
		}

		/* update previous indices */
		for(bin = 0; bin<34; bin++) {
			this.iid_index_prev[bin] = this.iid_index[this.num_env-1][bin];
		}
		for(bin = 0; bin<34; bin++) {
			this.icc_index_prev[bin] = this.icc_index[this.num_env-1][bin];
		}
		for(bin = 0; bin<17; bin++) {
			this.ipd_index_prev[bin] = this.ipd_index[this.num_env-1][bin];
			this.opd_index_prev[bin] = this.opd_index[this.num_env-1][bin];
		}

		this.ps_data_available = 0;

		if(this.frame_class==0) {
			this.border_position[0] = 0;
			for(env = 1; env<this.num_env; env++) {
				this.border_position[env] = (env*this.numTimeSlotsRate)/this.num_env;
			}
			this.border_position[this.num_env] = this.numTimeSlotsRate;
		}
		else {
			this.border_position[0] = 0;

			if(this.border_position[this.num_env]<this.numTimeSlotsRate) {
				for(bin = 0; bin<34; bin++) {
					this.iid_index[this.num_env][bin] = this.iid_index[this.num_env-1][bin];
					this.icc_index[this.num_env][bin] = this.icc_index[this.num_env-1][bin];
				}
				for(bin = 0; bin<17; bin++) {
					this.ipd_index[this.num_env][bin] = this.ipd_index[this.num_env-1][bin];
					this.opd_index[this.num_env][bin] = this.opd_index[this.num_env-1][bin];
				}
				this.num_env++;
				this.border_position[this.num_env] = this.numTimeSlotsRate;
			}

			for(env = 1; env<this.num_env; env++) {
				int thr = this.numTimeSlotsRate-(this.num_env-env);

				if(this.border_position[env]>thr) {
					this.border_position[env] = thr;
				}
				else {
					thr = this.border_position[env-1]+1;
					if(this.border_position[env]<thr) {
						this.border_position[env] = thr;
					}
				}
			}
		}

		/* make sure that the indices of all parameters can be mapped
		 * to the same hybrid synthesis filterbank
		 */
		if(this.use34hybrid_bands) {
			for(env = 0; env<this.num_env; env++) {
				if(this.iid_mode!=2&&this.iid_mode!=5)
					map20indexto34(this.iid_index[env], 34);
				if(this.icc_mode!=2&&this.icc_mode!=5)
					map20indexto34(this.icc_index[env], 34);
				if(this.ipd_mode!=2&&this.ipd_mode!=5) {
					map20indexto34(this.ipd_index[env], 17);
					map20indexto34(this.opd_index[env], 17);
				}
			}
		}
	}
private void ps_data_decode() {
		int env, bin;

		/* ps data not available, use data from previous frame */
		if(this.ps_data_available==0) {
			this.num_env = 0;
		}

		for(env = 0; env<this.num_env; env++) {
			int[] iid_index_prev;
			int[] icc_index_prev;
			int[] ipd_index_prev;
			int[] opd_index_prev;

			int num_iid_steps = (this.iid_mode<3) ? 7 : 15 /*fine quant*/;

			if(env==0) {
				/* take last envelope from previous frame */
				iid_index_prev = this.iid_index_prev;
				icc_index_prev = this.icc_index_prev;
				ipd_index_prev = this.ipd_index_prev;
				opd_index_prev = this.opd_index_prev;
			}
			else {
				/* take index values from previous envelope */
				iid_index_prev = this.iid_index[env-1];
				icc_index_prev = this.icc_index[env-1];
				ipd_index_prev = this.ipd_index[env-1];
				opd_index_prev = this.opd_index[env-1];
			}

//        iid = 1;
        /* delta decode iid parameters */
			delta_decode(this.enable_iid, this.iid_index[env], iid_index_prev,
				this.iid_dt[env], this.nr_iid_par,
				(this.iid_mode==0||this.iid_mode==3) ? 2 : 1,
				-num_iid_steps, num_iid_steps);
//        iid = 0;

			/* delta decode icc parameters */
			delta_decode(this.enable_icc, this.icc_index[env], icc_index_prev,
				this.icc_dt[env], this.nr_icc_par,
				(this.icc_mode==0||this.icc_mode==3) ? 2 : 1,
				0, 7);

			/* delta modulo decode ipd parameters */
			delta_modulo_decode(this.enable_ipdopd, this.ipd_index[env], ipd_index_prev,
				this.ipd_dt[env], this.nr_ipdopd_par, 1, 7);

			/* delta modulo decode opd parameters */
			delta_modulo_decode(this.enable_ipdopd, this.opd_index[env], opd_index_prev,
				this.opd_dt[env], this.nr_ipdopd_par, 1, 7);
		}

		/* handle error case */
		if(this.num_env==0) {
			/* force to 1 */
			this.num_env = 1;

			if(this.enable_iid) {
				for(bin = 0; bin<34; bin++) {
					this.iid_index[0][bin] = this.iid_index_prev[bin];
				}
			}
			else {
				for(bin = 0; bin<34; bin++) {
					this.iid_index[0][bin] = 0;
				}
			}

			if(this.enable_icc) {
				for(bin = 0; bin<34; bin++) {
					this.icc_index[0][bin] = this.icc_index_prev[bin];
				}
			}
			else {
				for(bin = 0; bin<34; bin++) {
					this.icc_index[0][bin] = 0;
				}
			}

			if(this.enable_ipdopd) {
				for(bin = 0; bin<17; bin++) {
					this.ipd_index[0][bin] = this.ipd_index_prev[bin];
					this.opd_index[0][bin] = this.opd_index_prev[bin];
				}
			}
			else {
				for(bin = 0; bin<17; bin++) {
					this.ipd_index[0][bin] = 0;
					this.opd_index[0][bin] = 0;
				}
			}
		}

		/* update previous indices */
		for(bin = 0; bin<34; bin++) {
			this.iid_index_prev[bin] = this.iid_index[this.num_env-1][bin];
		}
		for(bin = 0; bin<34; bin++) {
			this.icc_index_prev[bin] = this.icc_index[this.num_env-1][bin];
		}
		for(bin = 0; bin<17; bin++) {
			this.ipd_index_prev[bin] = this.ipd_index[this.num_env-1][bin];
			this.opd_index_prev[bin] = this.opd_index[this.num_env-1][bin];
		}

		this.ps_data_available = 0;

		if(this.frame_class==0) {
			this.border_position[0] = 0;
			for(env = 1; env<this.num_env; env++) {
				this.border_position[env] = (env*this.numTimeSlotsRate)/this.num_env;
			}
			this.border_position[this.num_env] = this.numTimeSlotsRate;
		}
		else {
			this.border_position[0] = 0;

			if(this.border_position[this.num_env]<this.numTimeSlotsRate) {
				for(bin = 0; bin<34; bin++) {
					this.iid_index[this.num_env][bin] = this.iid_index[this.num_env-1][bin];
					this.icc_index[this.num_env][bin] = this.icc_index[this.num_env-1][bin];
				}
				for(bin = 0; bin<17; bin++) {
					this.ipd_index[this.num_env][bin] = this.ipd_index[this.num_env-1][bin];
					this.opd_index[this.num_env][bin] = this.opd_index[this.num_env-1][bin];
				}
				this.num_env++;
				this.border_position[this.num_env] = this.numTimeSlotsRate;
			}

			for(env = 1; env<this.num_env; env++) {
				int thr = this.numTimeSlotsRate-(this.num_env-env);

				if(this.border_position[env]>thr) {
					this.border_position[env] = thr;
				}
				else {
					thr = this.border_position[env-1]+1;
					if(this.border_position[env]<thr) {
						this.border_position[env] = thr;
					}
				}
			}
		}

		/* make sure that the indices of all parameters can be mapped
		 * to the same hybrid synthesis filterbank
		 */
		if(this.use34hybrid_bands) {
			for(env = 0; env<this.num_env; env++) {
				if(this.iid_mode!=2&&this.iid_mode!=5)
					map20indexto34(this.iid_index[env], 34);
				if(this.icc_mode!=2&&this.icc_mode!=5)
					map20indexto34(this.icc_index[env], 34);
				if(this.ipd_mode!=2&&this.ipd_mode!=5) {
					map20indexto34(this.ipd_index[env], 17);
					map20indexto34(this.opd_index[env], 17);
				}
			}
		}
	}
/* parse the bitstream data decoded in ps_data()