1
我產生PCM,想循環的聲音。 我跟着文檔,但是Eclipse都跟我說的Android AudioTrack setloop無效值
08-05 15:46:26.675: E/AudioTrack(27686): setLoop invalid value: loopStart 0, loopEnd 44100, loopCount -1, framecount 11025, user 11025
這裏是我的代碼:
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();
}
請幫忙~~
對不起你們。我剛剛發現了一個偉大的帖子在這裏=。= http://bin-liu.blogspot.dk/2011/12/looping-audio-file-via-audiotrack.html 只是劃分NUMSAMPLES幾次,它會開始工作。 :P – vegligi