Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SoundPool error: no more track names available

I'm having troubles with the soundpool class. Here it goes:

In my game app (music app btw) I need to reproduce at least 32 short sounds at the same time, so I declare my soundpool like that:

private SoundPool sp;
sp = new SoundPool(128, AudioManager.STREAM_MUSIC, 0);

After that I load all the MP3 sounds needed, about 80 sound of 55KB each. I have no troubles loading all the sounds, but its slow! Well it's no the problem. The real trouble is when I play about 20 sounds at the same time, there's an error in my log:

ERROR/AudioFlinger(59): no more track names available
ERROR/AudioTrack(26349): AudioFlinger could not create track, status: -12
ERROR/SoundPool(26349): Error creating AudioTrack

After that every sound that i try to play throws the same error, and no sound can be played. Not even sounds of another Activity / soundpool. I have no clue of what's going or how to fix it! Should I change the format of the sound files? Should I free memory or something after playing a sound?

(I'm testing on a Samsung Galaxy S I9000, 2.3.3 OS system. The app is 2.1)

like image 693
Carles Avatar asked Dec 05 '11 15:12

Carles


2 Answers

see this (in android group)

For audio, there's a hard limit of 32 active AudioTrack objects per device (not per app: you need to share those 32 with rest of the system),

like image 127
ifreedom Avatar answered Oct 19 '22 17:10

ifreedom


A couple of thoughts here. One: the first parameter to the SoundPool constructor is not the number of sounds you want to load into it, it's the maximum number of simultaneous streams that you'll be playing. Second, SoundPool has limited memory for sounds, about 1MB. So I wouldn't be at all surprised if you hit some undocumented limit to the number of tracks you can load in at one time. Notice that 80 sounds times 55k per sound is definitely over 1MB. And that limit is for after the mp3s have been uncompressed into audio data inside SoundPool.

like image 39
Dave MacLean Avatar answered Oct 19 '22 19:10

Dave MacLean