EvilDuck
EvilDuck

Reputation: 4436

Extremely slow OGG decodeing on Galaxy Nexus

I have encountered a really weird issue on my Galaxy Nexus. What I'm trying to do is load 48 OGG samples into SoundPool at the start of my service (music related application). Files are 11-15K each. Loading code is simple:

for (String note : sm) { // 48 iterations
    int soundId = soundPool.load(getResources().getAssets().openFd(note), 1);
    loadedSoundsMap.put(note, soundId);
}

I have measured that on my Nexus One 2.3.6 I loads in 1-2 seconds. But on a brand new Galaxy Nexus 4.0.2 it loads in 9 seconds!

I really doubt it's a file IO taking so much time to read 1mb total, so I think something is screwed up in decompressor implementation.

Can anyone suggest what could cause such slow work?

P. S. Mp3 gives about the same picture.

Upvotes: 1

Views: 707

Answers (2)

Taras
Taras

Reputation: 2576

The problem lies in the SoundPool implementation. Audio hardware works in front of uncompressed data - PCM, so as SoundPool keeps all sounds loaded, it decompresses OGG or MP3 files to WAV. In order to improve UX, you can run a thread which decodes from OGG to WAV files on application start. When running a player if sound is converted - use WAV file, OGG otherwise. Here's a link to nice OGG decoder: libvorbis-libogg-android. Keep in mind that OGG decoder decodes to raw PCM, so you have to add WAV header.

On Android L there's also an issue with AwesomePlayer, when loading any file to SoundPool takes very long time. Switching to NuPlayer in Developer options helps, but it should be fixed by Android team somehow.

Upvotes: 0

Related Questions