public void synthesizeWithMix(int addr,int samples,int leftVol,int rightVol){
  int[] mixedSamples=new int[samples * 2];
  if (leftVol == 0 && rightVol == 0) {
    Arrays.fill(mixedSamples,0);
  }
 else   if (leftVol == MAX_VOLUME && rightVol == MAX_VOLUME) {
    int lengthInBytes=mixedSamples.length * 2;
    IMemoryReader memoryReader=MemoryReader.getMemoryReader(addr,lengthInBytes,2);
    for (int i=0; i < mixedSamples.length; i++) {
      mixedSamples[i]=(short)memoryReader.readNext();
    }
  }
 else {
    int lengthInBytes=mixedSamples.length * 2;
    IMemoryReader memoryReader=MemoryReader.getMemoryReader(addr,lengthInBytes,2);
    for (int i=0; i < samples; i++) {
      short sampleLeft=(short)memoryReader.readNext();
      short sampleRight=(short)memoryReader.readNext();
      sampleLeft=SoundChannel.adjustSample(sampleLeft,leftVol);
      sampleRight=SoundChannel.adjustSample(sampleRight,rightVol);
      mixedSamples[i * 2]=sampleLeft;
      mixedSamples[i * 2 + 1]=sampleRight;
    }
  }
  mix(mixedSamples,addr,samples,MAX_VOLUME,MAX_VOLUME,false);
}

public void synthesizeWithMix ( int addr , int samples , int leftVol , int rightVol ) { int [ ] mixedSamples = new int [ samples * 2 ] ; if ( leftVol == 0 && rightVol == 0 ) { Arrays . fill ( mixedSamples , 0 ) ; } else if ( leftVol == MAX_VOLUME && rightVol == MAX_VOLUME ) { int lengthInBytes = mixedSamples . length * 2 ; IMemoryReader memoryReader = MemoryReader . getMemoryReader ( addr , lengthInBytes , 2 ) ; for ( int i = 0 ; i < mixedSamples . length ; i ++ ) { mixedSamples [ i ] = ( short ) memoryReader . readNext ( ) ; } } else { int lengthInBytes = mixedSamples . length * 2 ; IMemoryReader memoryReader = MemoryReader . getMemoryReader ( addr , lengthInBytes , 2 ) ; for ( int i = 0 ; i < samples ; i ++ ) { short sampleLeft = ( short ) memoryReader . readNext ( ) ; short sampleRight = ( short ) memoryReader . readNext ( ) ; sampleLeft = SoundChannel . adjustSample ( sampleLeft , leftVol ) ; sampleRight = SoundChannel . adjustSample ( sampleRight , rightVol ) ; mixedSamples [ i * 2 ] = sampleLeft ; mixedSamples [ i * 2 + 1 ] = sampleRight ; } } mix ( mixedSamples , addr , samples , MAX_VOLUME , MAX_VOLUME , false ) ; }
synthesizing audio function with mix .
