'Android specific frequency AudioTrack infinity dutaion

i made specific frequency sound, used AutioTrack

private static final int duration = 10; // seconds
private static final int sampleRate = 8000;
private static final int numSamples = duration * sampleRate;
private static final double sample[] = new double[numSamples];
private static double freqOfTone = 0; // hz
final byte generatedSnd[] = new byte[2 * numSamples];
final AudioTrack p7 = new AudioTrack(AudioManager.STREAM_MUSIC,
                sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT, numSamples,
                AudioTrack.MODE_STATIC);

    for (int i = 0; i < numSamples; ++i) {
                sample[i] = Math.sin(2 * Math.PI * i / (sampleRate/hz));
            }
    
            // convert to 16 bit pcm sound array
            // assumes the sample buffer is normalised.
            int idx = 0;
            for (final double dVal : sample) {
                // scale to maximum amplitude
                final short val = (short) ((dVal * 32767));
                // in 16 bit wav PCM, first byte is the low order byte
                generatedSnd[idx++] = (byte) (val & 0x00ff);
                generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8);
            }
    p7.write(generatedSnd, 0, generatedSnd.length);
    p7.play();

like this. first line is set duration but i want to make infinity duration. (not loop) is it possible? please help me



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source