Soundpool doesn't play maximum number of streams

44 Views Asked by At

I'm using soundpool in the game I'm developing. It plays piano notes most of the time playing several notes simultaneously. On some of the phones, the notes play very well. On the other hand when I tested on another phone some of the notes don't play. To investigate the problem, I've written the following code to understand the origin of the problem. There are 85 notes that play sequentially. When the delay between the notes is about 1 seconds, the notes play well without any skip or delay. This show all the samples are loaded without any error. But when I reduce the delay to 100ms, the notes start to overlap and after playing several notes sequentially in a proper way, the soundpool stops and waits the samples to finish before playing the remaining notes. On the other hand on another phone, even when the delay is 100ms all the notes play properly. Since the maximum number of streams is 100, the soundpool should play all the notes even if they are played simultaneously. I also checked the memory while running the following code and there weren't any overloading.

I have been working on this problem for a couple of days, so if you help me I'd appreciate it greatly.

spl=new SoundPool(100, AudioManager.STREAM_MUSIC, 0));



Handler handler = new Handler();
        Runnable runnable = new Runnable() {
        int cnt1=0,cnt2=0;
            @Override
            public void run() {
        cnt1=cnt1+1;
        if (cnt1>10){
            
            stream=spl.play(sndIds[cnt2],volumesToBePlayed.get(i), volumesToBePlayed.get(i),1,0,1f);
            Log.i("playing", String.valueOf(cnt2) + " " + String.valueOf(stream));
            cnt1=0;
            cnt2=cnt2+1;
            
        }
        if(cnt2>= sndIds.lenght){
            handler.removeCallbacks(this);
        } else {
            handler.postDelayed(this, 100);
        }
            }
        };
        runnable.run();

EDIT: After investigating the problem a bit more, I've noticed that some phones are able to play more simultaneous samples than the others. In the piano applications, like mine, if there would be many simultaneous or overlapping play actions, I think, it is not a good idea to make the max number of streams large since the soundpool skips the notes played when the full capacity is reached. When the maximum is below the capacity of the phone, soundpool dosn't skip the new sound but stop the already playing and the oldest streams first if their priorities are the same. This sounds less disturbing to the user. I solved the problem by reducing the max number of streams to 12.

0

There are 0 best solutions below