projects/positioning/app/src/main/java/io/v/positioning/UltrasoundGenerator.java
/**
     * Create a 16-bit PCM sinusoidal tone.
     *
     * @return A byte array containing the encoded tone.
     */
Create a 16-bit PCM sinusoidal tone.
@return A byte array containing the encoded tone.
Create a 16 - bit PCM sinusoidal tone . @return A byte array containing the encoded tone .
private static byte[] createSoundArray(double frequencyHz) {
        int numSamples = DURATION * SAMPLE_RATE;
        byte[] soundBytes = new byte[BYTES_PER_SAMPLE * numSamples];
        double[] sampleTones = new double[numSamples];
        for (int i = 0; i < numSamples; i++) {
            sampleTones[i] = Math.sin(2 * Math.PI * (i / (SAMPLE_RATE / frequencyHz)));
        }
        int idx = 0;
        for (final double dVal : sampleTones) {
            final short val = (short) ((dVal * AMPLITUDE));
            soundBytes[idx++] = (byte) (val & 0x00ff);
            soundBytes[idx++] = (byte) ((val & 0xff00) >>> 8);
        }
        return soundBytes;
    }
private static byte [ ] createSoundArray ( double frequencyHz ) { int numSamples = DURATION * SAMPLE_RATE ; byte [ ] soundBytes = new byte [ BYTES_PER_SAMPLE * numSamples ] ; double [ ] sampleTones = new double [ numSamples ] ; for ( int i = 0 ; i < numSamples ; i ++ ) { sampleTones [ i ] = Math . sin ( 2 * Math . PI * ( i / ( SAMPLE_RATE / frequencyHz ) ) ) ; } int idx = 0 ; for ( final double dVal : sampleTones ) { final short val = ( short ) ( ( dVal * AMPLITUDE ) ) ; soundBytes [ idx ++ ] = ( byte ) ( val & 0x00ff ) ; soundBytes [ idx ++ ] = ( byte ) ( ( val & 0xff00 ) >>> 8 ) ; } return soundBytes ; }
Create a 16-bit PCM sinusoidal tone.
Create a 16 - bit PCM sinusoidal tone .