Question

I generate a PCM and want to loop the sound. I follow the documentation, but Eclipse keep telling me that

08-05 15:46:26.675: E/AudioTrack(27686): setLoop invalid value: loopStart 0, loopEnd 44100, loopCount -1, framecount 11025, user 11025

here is my code:

void genTone() {
    // fill out the array
    for (int i = 1; i < numSamples - 1; i = i + 2) {
        sample[i] = Math.sin(2 * Math.PI * i / (sampleRate / -300));
    }

    // convert to 16 bit pcm sound array
    // assumes the sample buffer is normalised.
    int idx = 0;
    for (double dVal : sample) {
        short val = (short) (dVal * 32767);
        generatedSnd[idx++] = (byte) (val & 0x00ff);
        generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8);
    }

    //write it to audio Track.
    audioTrack.write(generatedSnd, 0, numSamples);
    audioTrack.setLoopPoints(0, numSamples, -1); 
    //from 0.0 ~ 1.0
    audioTrack.setStereoVolume((float)0.5, (float)1); //change amplitude
}



public void buttonPlay(View v) {
    audioTrack.reloadStaticData();
    audioTrack.play();
}

please help ~~

Was it helpful?

Solution

From the documentation: "endInFrames loop end marker expressed in frames"

The log print indicates that your track contains 11025 frames, which is less than the 44100 that you're trying to specify as the end marker (for 16-bit stereo PCM audio, the frame size would be 4 bytes).

Another thing worth noting is that "the track must be stopped or paused for the position to be changed".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top