question: private static ByteBuffer generateWavData ( int sampleCount , int freqHz ) { final int numDataBytes = sampleCount * NUM_CHANNELS * BITS_PER_SAMPLE / 8 ; final double freq = freqHz ; ByteBuffer buf = ByteBuffer . allocate ( numDataBytes ) ; buf . order ( ByteOrder . LITTLE_ENDIAN ) ; if ( BITS_PER_SAMPLE == 8 ) { final double peak = 127.0 ; for ( int i = 0 ; i < sampleCount ; i ++ ) { double timeSec = i / ( double ) SAMPLE_RATE ; double sinValue = Math . sin ( 2 * Math . PI * freq * timeSec ) ; if ( GameSurfaceRenderer . EXTRA_CHECK ) { int output = ( int ) ( peak * sinValue + 127.0 ) ; if ( output < 0 || output >= 256 ) { throw new RuntimeException ( "bad byte gen" ) ; } } buf . put ( ( byte ) ( peak * sinValue + 127.0 ) ) ; } } else if ( BITS_PER_SAMPLE == 16 ) { final double peak = 32767.0 ; ShortBuffer sbuf = buf . asShortBuffer ( ) ; for ( int i = 0 ; i < sampleCount ; i ++ ) { double timeSec = i / ( double ) SAMPLE_RATE ; double sinValue = Math . sin ( 2 * Math . PI * freq * timeSec ) ; sbuf . put ( ( short ) ( peak * sinValue ) ) ; } } buf . position ( 0 ) ; return buf ; }
target:  Generates the raw WAV-compatible audio data.