lib/minim/src/ddf/minim/javasound/FloatSampleTools.java
/**
	 * Central conversion function from a byte array to a normalized float
	 * array. In order to accomodate interleaved and non-interleaved samples,
	 * this method takes inByteStep as parameter which can be used to flexibly
	 * convert the data.
	 * <p>
	 * E.g.:<br>
	 * mono->mono: inByteStep=format.getFrameSize()<br>
	 * interleaved_stereo->interleaved_stereo:
	 * inByteStep=format.getFrameSize()/2, sampleCount*2<br>
	 * stereo->2 mono arrays:<br>
	 * ---inByteOffset=0, outOffset=0, inByteStep=format.getFrameSize()<br>
	 * ---inByteOffset=format.getFrameSize()/2, outOffset=1,
	 * inByteStep=format.getFrameSize()<br>
	 */
Central conversion function from a byte array to a normalized float
array. In order to accomodate interleaved and non-interleaved samples,
this method takes inByteStep as parameter which can be used to flexibly
convert the data.
Central conversion function from a byte array to a normalized float array . In order to accomodate interleaved and non - interleaved samples this method takes inByteStep as parameter which can be used to flexibly convert the data .
static void byte2floatGeneric(byte[] input, int inByteOffset,
			int inByteStep, float[] output, int outOffset, int sampleCount,
			int formatType) {
		int endCount = outOffset + sampleCount;
		int inIndex = inByteOffset;
		for (int outIndex = outOffset; outIndex < endCount; outIndex++, inIndex += inByteStep) {
			switch (formatType) {
			case CT_8S:
				output[outIndex] = input[inIndex] * invTwoPower7;
				break;
			case CT_8U:
				output[outIndex] = ((input[inIndex] & 0xFF) - 128) * invTwoPower7;
				break;
			case CT_16SB:
				output[outIndex] = ((input[inIndex] << 8) 
						| (input[inIndex + 1] & 0xFF))
						* invTwoPower15;
				break;
			case CT_16SL:
				output[outIndex] = ((input[inIndex + 1] << 8) 
						| (input[inIndex] & 0xFF))
						* invTwoPower15;
				break;
			case CT_24_3SB:
				output[outIndex] = ((input[inIndex] << 16)
						| ((input[inIndex + 1] & 0xFF) << 8) 
						| (input[inIndex + 2] & 0xFF))
						* invTwoPower23;
				break;
			case CT_24_3SL:
				output[outIndex] = ((input[inIndex + 2] << 16)
						| ((input[inIndex + 1] & 0xFF) << 8) 
						| (input[inIndex] & 0xFF))
						* invTwoPower23;
				break;
			case CT_24_4SB:
				output[outIndex] = ((input[inIndex + 1] << 16)
						| ((input[inIndex + 2] & 0xFF) << 8) 
						| (input[inIndex + 3] & 0xFF))
						* invTwoPower23;
				break;
			case CT_24_4SL:
				output[outIndex] = ((input[inIndex + 3] << 16)
						| ((input[inIndex + 2] & 0xFF) << 8) 
						| (input[inIndex + 1] & 0xFF))
						* invTwoPower23;
				break;
			case CT_32SB:
				output[outIndex] = ((input[inIndex] << 24)
						| ((input[inIndex + 1] & 0xFF) << 16)
						| ((input[inIndex + 2] & 0xFF) << 8) 
						| (input[inIndex + 3] & 0xFF))
						* invTwoPower31;
				break;
			case CT_32SL:
				output[outIndex] = ((input[inIndex + 3] << 24)
						| ((input[inIndex + 2] & 0xFF) << 16)
						| ((input[inIndex + 1] & 0xFF) << 8) 
						| (input[inIndex] & 0xFF))
						* invTwoPower31;
				break;
			default:
				throw new IllegalArgumentException("unsupported format="
						+ formatType2Str(formatType));
			}
		}
	}
static void byte2floatGeneric ( byte [ ] input , int inByteOffset , int inByteStep , float [ ] output , int outOffset , int sampleCount , int formatType ) { int endCount = outOffset + sampleCount ; int inIndex = inByteOffset ; for ( int outIndex = outOffset ; outIndex < endCount ; outIndex ++ , inIndex += inByteStep ) { switch ( formatType ) { case CT_8S : output [ outIndex ] = input [ inIndex ] * invTwoPower7 ; break ; case CT_8U : output [ outIndex ] = ( ( input [ inIndex ] & 0xFF ) - 128 ) * invTwoPower7 ; break ; case CT_16SB : output [ outIndex ] = ( ( input [ inIndex ] << 8 ) | ( input [ inIndex + 1 ] & 0xFF ) ) * invTwoPower15 ; break ; case CT_16SL : output [ outIndex ] = ( ( input [ inIndex + 1 ] << 8 ) | ( input [ inIndex ] & 0xFF ) ) * invTwoPower15 ; break ; case CT_24_3SB : output [ outIndex ] = ( ( input [ inIndex ] << 16 ) | ( ( input [ inIndex + 1 ] & 0xFF ) << 8 ) | ( input [ inIndex + 2 ] & 0xFF ) ) * invTwoPower23 ; break ; case CT_24_3SL : output [ outIndex ] = ( ( input [ inIndex + 2 ] << 16 ) | ( ( input [ inIndex + 1 ] & 0xFF ) << 8 ) | ( input [ inIndex ] & 0xFF ) ) * invTwoPower23 ; break ; case CT_24_4SB : output [ outIndex ] = ( ( input [ inIndex + 1 ] << 16 ) | ( ( input [ inIndex + 2 ] & 0xFF ) << 8 ) | ( input [ inIndex + 3 ] & 0xFF ) ) * invTwoPower23 ; break ; case CT_24_4SL : output [ outIndex ] = ( ( input [ inIndex + 3 ] << 16 ) | ( ( input [ inIndex + 2 ] & 0xFF ) << 8 ) | ( input [ inIndex + 1 ] & 0xFF ) ) * invTwoPower23 ; break ; case CT_32SB : output [ outIndex ] = ( ( input [ inIndex ] << 24 ) | ( ( input [ inIndex + 1 ] & 0xFF ) << 16 ) | ( ( input [ inIndex + 2 ] & 0xFF ) << 8 ) | ( input [ inIndex + 3 ] & 0xFF ) ) * invTwoPower31 ; break ; case CT_32SL : output [ outIndex ] = ( ( input [ inIndex + 3 ] << 24 ) | ( ( input [ inIndex + 2 ] & 0xFF ) << 16 ) | ( ( input [ inIndex + 1 ] & 0xFF ) << 8 ) | ( input [ inIndex ] & 0xFF ) ) * invTwoPower31 ; break ; default : throw new IllegalArgumentException ( "unsupported format=" + formatType2Str ( formatType ) ) ; } } }
Central conversion function from a byte array to a normalized float
 array.
Central conversion function from a byte array to a normalized float array .
// if (TDebug.TraceAudioConverter) { // TDebug.out("FloatSampleTools.byte2floatGeneric, formatType=" // +formatType2Str(formatType)); // } // do conversion // TODO: verify the indexes