問題描述
為什麼原生 libmpg123 在帶有 libgdx 的 android 上花費這麼長時間? (Why is native libmpg123 taking so long on android with libgdx?)
I'm trying to use the gdx‑audio extensions, but am having trouble decoding mp3s. It works, but very slowly!! A 10‑second file is taking 6.57 seconds to decode :( Here is the method:
public void decode() {
Mpg123Decoder decoder = new Mpg123Decoder(externalFile);
short[] sampleArray = new short[1024];
// read until we reach the end of the file
while (decoder.readSamples(sampleArray, 0, sampleArray.length) > 0) {}
}
Can anyone tell me why this is taking so long?
‑‑‑‑‑
參考解法
方法 1:
Because libmpg123 is a software decoder, that does all the work on the CPU. Depending on what CPU you have, you usually only get 2x real‑time decoding. We haven't enabled ARM assembly in our libmpg123 build, that could help speeding it up a little, but usually not by much.