public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
	  {
	    if ((allocation != 0) && (channels != OutputChannels.RIGHT_CHANNEL))
	    {
	  	 float sample = samples[samplenumber];
	  
	  	 if (groupingtable[0] == null)
	  		sample = (sample + d[0]) * c[0];
	  	 if (groupnumber <= 4)
	  		sample *= scalefactor1;
	  	 else if (groupnumber <= 8)
	  		sample *= scalefactor2;
	  	 else
	  		sample *= scalefactor3;
	  	 filter1.input_sample(sample, subbandnumber);
	    }
	  
	    if (++samplenumber == 3)
	  	 return true;
	    else
		 return false;
	  }
	};
	
	 /**
	  * Class for layer II subbands in joint stereo mode.
	  */
	static class SubbandLayer2IntensityStereo extends SubbandLayer2
	{
	  protected int		 channel2_scfsi;
	  protected float 	 channel2_scalefactor1, channel2_scalefactor2, channel2_scalefactor3;

	  /**
	   * Constructor
	   */
	  public SubbandLayer2IntensityStereo (int subbandnumber)
	  {
	 	super(subbandnumber);
	  }

	  /**
	   *
	   */
	  public void read_allocation(Bitstream stream, Header header, Crc16 crc)
	  {
	    super.read_allocation (stream, header, crc);
	  }
	  
	  /**
	   *
	   */
	  public void read_scalefactor_selection(Bitstream stream, Crc16 crc)
	  {
	    if (allocation != 0)
	    {
	  	 scfsi = stream.get_bits(2);
	  	 channel2_scfsi = stream.get_bits(2);
	  	 if (crc != null)
	  	 {
	  		crc.add_bits(scfsi, 2);
	  		crc.add_bits(channel2_scfsi, 2);
	  	 }
	    }  
	  }
	  
	  /**
	   *
	   */
	  public void read_scalefactor(Bitstream stream, Header header)
	  {
	    if (allocation != 0)
	    {
	  	 super.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;
	  	 }
	    }
	  
	  }
	  
	  /**
	   *
	   */
	  public boolean read_sampledata(Bitstream stream)
	  {
		 return super.read_sampledata (stream);
	  }
	  
	  /**
	   *
	   */
	  public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
	  {
		  if (allocation != 0)
		  {
			 float sample = samples[samplenumber];
		
			 if (groupingtable[0] == null)
				sample = (sample + d[0]) * c[0];
		       if (channels == OutputChannels.BOTH_CHANNELS)
			   {
				  float sample2 = sample;
			      if (groupnumber <= 4)
			      {
					sample *= scalefactor1;
					sample2 *= channel2_scalefactor1;
				  }
				  else if (groupnumber <= 8)
				  {
					sample *= scalefactor2;
					sample2 *= channel2_scalefactor2;
				  }
				  else
				  {
					sample *= scalefactor3;
					sample2 *= channel2_scalefactor3;
				  }
				  filter1.input_sample(sample, subbandnumber);
			      filter2.input_sample(sample2, subbandnumber);
			    }
		 	   	else if (channels == OutputChannels.LEFT_CHANNEL)
				{
					if (groupnumber <= 4)
						sample *= scalefactor1;
		 	     	else if (groupnumber <= 8)
						sample *= scalefactor2;
					else
						sample *= scalefactor3;
					filter1.input_sample(sample, subbandnumber);
				 }
				 else
				 {
					if (groupnumber <= 4)
					sample *= channel2_scalefactor1;
					else if (groupnumber <= 8)
						sample *= channel2_scalefactor2;
					else
						sample *= channel2_scalefactor3;
					filter1.input_sample(sample, subbandnumber);
			 	}
		  	}
		
		  if (++samplenumber == 3)
			 return true;
		  else
		 return false;
	  }
	};

	 /**
	  * Class for layer II subbands in stereo mode.
	  */
	static class SubbandLayer2Stereo extends SubbandLayer2
	{
	  protected int			channel2_allocation;
	  protected int 		channel2_scfsi;
	  protected float	 	channel2_scalefactor1, channel2_scalefactor2, channel2_scalefactor3;
	  //protected boolean	 	channel2_grouping;  ???? Never used!
	  protected int[] 		channel2_codelength = {0};
	  //protected float[][] 	channel2_groupingtable = {{0},{0}};
	  protected float[]	 	channel2_factor = {0};
	  protected float[] 	channel2_samples;
	  protected float[]	 	channel2_c = {0};
	  protected float[]		channel2_d = {0};
	  
	  /**
	   * Constructor
	   */
	  public SubbandLayer2Stereo(int subbandnumber)
	  {
	 	super(subbandnumber);
		channel2_samples = new float[3];
	  }
	  
	  /**
	   *
	   */
	  public 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);
	    }
	  }

	  /**
	   *
	   */
	  public 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);
	  	  }
	  }

	  /**
	   *
	   */
	  public void read_scalefactor(Bitstream stream, Header header)
	  {
	    super.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);
	   }
	  }

	  /**
	   *
	   */
	  public boolean read_sampledata (Bitstream stream)
	  {
	    boolean returnvalue = super.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;
	  }

	  /**
	   *
	   */
	  public boolean put_next_sample(int channels, SynthesisFilter filter1, SynthesisFilter filter2)
	  {
	    boolean returnvalue = super.put_next_sample(channels, filter1, filter2);
	    if ((channel2_allocation != 0) && (channels != OutputChannels.LEFT_CHANNEL))
	    {
	  	 float sample = channel2_samples[samplenumber - 1];
	  
	  	 if (groupingtable[1] == null)
	  		sample = (sample + channel2_d[0]) * channel2_c[0];
	  
	  	 if (groupnumber <= 4)
	  		sample *= channel2_scalefactor1;
	  	 else if (groupnumber <= 8)
	  		sample *= channel2_scalefactor2;
	  	 else
	  		sample *= channel2_scalefactor3;
	  	 if (channels == OutputChannels.BOTH_CHANNELS)
	  		filter2.input_sample(sample, subbandnumber);
	  	 else
	  		filter1.input_sample(sample, subbandnumber);
	    }
	  	return returnvalue;
	  }