1

I'm generating a tone on android

public void toneer(){
    final int duration = 10; // duration of sound
    final int sampleRate = 22050; // Hz (maximum frequency is 7902.13Hz (B8))
    final int numSamples = duration * sampleRate;
    final double samples[] = new double[numSamples];
    final short buffer[] = new short[numSamples];
    for (int i = 0; i < numSamples; ++i)
    {

        samples[i] = Math.sin(2 * Math.PI * i / (sampleRate / 440)); // Sine wave
        buffer[i] = (short) (samples[i] * Short.MAX_VALUE);  // Higher amplitude increases volume
    }


    AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
            sampleRate, AudioFormat.CHANNEL_OUT_MONO,
            AudioFormat.ENCODING_PCM_16BIT, buffer.length,
            AudioTrack.MODE_STATIC);
    audioTrack.write(buffer,  0, buffer.length);
    audioTrack.play();
}

I have seen some places discussing that is possible to have the buffer just sound on the left of the right?

My question is: how to generate a "binaural" beat, one frequency in one ear, while another tone is played on the second ear?

manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216

0 Answers0