Log.e("", "" + NativeWrapper.initLib());
int err = NativeWrapper.initMP3(filename);
Log.e("", "err " + err);
if (err != MPG123_OK) {
// TODO: Show error
}
Log.e("", "file name " + filename);
AudioFileInformations audioInfo = NativeWrapper
.getAudioInformations();
if (!audioInfo.success) {
// TODO: Show error
} else {
int minBufferSize = AudioTrack.getMinBufferSize((int) 44100,
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.STREAM_MUSIC, (int) 44100,
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
AudioFormat.ENCODING_PCM_16BIT, minBufferSize * 4,
AudioTrack.MODE_STREAM);
buffer = new short[minBufferSize];
boolean first = true;
signalThread.doNotify();
try {
fos = new FileOutputStream(Environment
.getExternalStorageDirectory().getPath()
+ "/"
+ "jumme_out.mp3");
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
do {
if (ended)
break;
try {
err = NativeWrapper
.decodeMP3(minBufferSize * 2, buffer);
if (err == MPG123_OK || err == MPG123_NEW_FORMAT) {
first = false;
track.write(bufferbyte, 0, bufferbyte.length); track.flush();
} else
break;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} while (!ended);
if (err == MPG123_DONE) {
track.flush();
track.stop();
try {
fos.flush();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
现在我已经通过NDK解码了PCM,我想动态地改变音高和速度......但是我想如何处理速度和音高......我所能做的就是改变音轨中的采样率。 。这只适用于KitKat .. 我也实施了Sonic-NDK ..它正在播放带噪音的声音.. 但Sonic需要喂PCM,所以我通过mpg123转换为pcm并动态喂它..但整个过程不够快,我听到循环中的差距.. 代码是:
void recursive() {
buffer = new short[minBufferSize];
err = NativeWrapper.decodeMP3(minBufferSize * 2, buffer);
byte[] bufferbyte = ShortToByte_Twiddle_Method(buffer);
sonic.putBytes(bufferbyte, bufferbyte.length);
int available = sonic.availableBytes();
modifiedSamples = new byte[available ];
sonic.receiveBytes(modifiedSamples, available);
track.write(modifiedSamples, 0, available); // Write
if (err != MPG123_DONE) {
recursive();
}
}
所以现在我有三个问题: 1.这就是为什么我的音轨只在19 API工作正常 2.我将如何消除块中的间隙和噪声(下面的代码) 3.有没有其他方法可以动态地实现音高和速度的操作是否有任何其他库或什么或我应该做什么。