I try to create a continuous sound (440Hz) with the setLoopPoints method.

It tryed several examples i found on fora and google but i don't get it 
working.

The return value of track.setLoopPoints(0,sound.length/4, -1) is 0, and 
thats ok.

Can someone tell me what i am doing wrong?

Here is my code:
 int sr = 48000;
int numOfSamples = sr;
    double sample[] = new double[numOfSamples];
    byte sound[] = new byte[2 * numOfSamples];

    // fill out the array
    for (int i = 0; i < numOfSamples; ++i) {
            sample[i] = Math.sin(2 * Math.PI * i / (sr / 440));           
    }

    int i = 0;
    for (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
        sound[i++] = (byte) (val & 0x00ff);
        sound[i++] = (byte) ((val & 0xff00) >>> 8);
    }

    // Obtain a minimum buffer size
    int minBuffer = AudioTrack.getMinBufferSize(sr, 
     AudioFormat.CHANNEL_OUT_MONO, 
     AudioFormat.ENCODING_PCM_16BIT);
   
        // Create an AudioTrack
        AudioTrack track = new AudioTrack(
         AudioManager.STREAM_MUSIC, 
         sr, 
         AudioFormat.CHANNEL_OUT_STEREO, 
                AudioFormat.ENCODING_PCM_16BIT, 
                sound.length, 
                AudioTrack.MODE_STATIC);

        // Write audio data to track
        track.write(sound, 0, sound.length);
       int a = track.setLoopPoints(0,sound.length/4, -1);
        // Begin playing track
        track.play();

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to