我是一名高中生,正在使用电位器,蓝牙和吉他应用程序进行arduidroid项目。我的问题是,当我弹奏吉他应用程序时,我会收到一个不会崩溃的错误。
AudioFlinger could not create track, status: -12
Error -12 initializing AudioTrack
Error code -20 when initializing AudioTrack.
如何使用此question中的音频发生器,使用3个不同的按钮播放尽可能多的声音。
void genTone(double freq){
// fill out the array
for (int i = 0; i < numSamples; ++i) {
sample[i]= 2*(i%(sampleRate/freq))/(sampleRate/freq)-1;
}
// 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);
}
}
void playSound(){
final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
sampleRate, AudioFormat.CHANNEL_OUT_STEREO,
AudioFormat.ENCODING_PCM_16BIT, generatedSnd.length,
AudioTrack.MODE_STATIC);
audioTrack.write(generatedSnd, 0, generatedSnd.length);
audioTrack.play();
}
if(BString.isPressed()){
/*genTone(BStringFreq);
playSound();*/
final Thread thread = new Thread(new Runnable() {
public void run() {
genTone(BStringFreq);
handler.post(new Runnable() {
public void run() {
playSound();
}
});
}
});
thread.start();
}
}
以下是我的代码的一些片段。请帮助我,因为我迷失在这个问题上。