public ByteData decodeFrame ( Frame frame , ByteData pcmData ) { // required size of the byte buffer int byteSize = frame . header . blockSize * channels * ( ( streamInfo . getBitsPerSample ( ) + 7 ) / 2 ) ; if ( pcmData == null || pcmData . getData ( ) . length < byteSize ) { pcmData = new ByteData ( byteSize ) ; } else { pcmData . setLen ( 0 ) ; } if ( streamInfo . getBitsPerSample ( ) == 8 ) { for ( int i = 0 ; i < frame . header . blockSize ; i ++ ) { for ( int channel = 0 ; channel < channels ; channel ++ ) { pcmData . append ( ( byte ) ( channelData [ channel ] . getOutput ( ) [ i ] + 0x80 ) ) ; } } } else if ( streamInfo . getBitsPerSample ( ) == 16 ) { for ( int i = 0 ; i < frame . header . blockSize ; i ++ ) { for ( int channel = 0 ; channel < channels ; channel ++ ) { short val = ( short ) ( channelData [ channel ] . getOutput ( ) [ i ] ) ; pcmData . append ( ( byte ) ( val & 0xff ) ) ; pcmData . append ( ( byte ) ( ( val >> 8 ) & 0xff ) ) ; } } } else if ( streamInfo . getBitsPerSample ( ) == 24 ) { for ( int i = 0 ; i < frame . header . blockSize ; i ++ ) { for ( int channel = 0 ; channel < channels ; channel ++ ) { int val = ( channelData [ channel ] . getOutput ( ) [ i ] ) ; pcmData . append ( ( byte ) ( val & 0xff ) ) ; pcmData . append ( ( byte ) ( ( val >> 8 ) & 0xff ) ) ; pcmData . append ( ( byte ) ( ( val >> 16 ) & 0xff ) ) ; } } } return pcmData ; }
Fill the given ByteData object with PCM data from the frame .