Question

Is it possible to make Soundpool play a sound at a faster rate, for instance play it 50% faster?

private void loadSound(int position, int group_position) {
    switch (position) {
        case 0:
            myVoice = soundPool.load(PhraseActivity.wr.get(), sound[group_position][0], 2);
            soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                @Override
                public void onLoadComplete(SoundPool soundPool, int sampleId,
                    int status) {
                    soundPool.play(myVoice, 20, 20, 1, 0, 1f);
                } 
            });
        break;
        case 1:
            myVoice = soundPool.load(PhraseActivity.wr.get(), sound[group_position][1], 2);
            soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                @Override
                public void onLoadComplete(SoundPool soundPool, int sampleId,
                    int status) {
                    soundPool.play(myVoice, 20, 20, 1, 0, 1f);
                } 
            });
        break;
    }
}
Was it helpful?

Solution

The playback rate allows the application to vary the playback rate (pitch) of the sound. A value of 1.0 means play back at the original frequency. A value of 2.0 means play back twice as fast, and a value of 0.5 means playback at half speed. see Doc

So you need to change
soundPool.play(myVoice, 20, 20, 1, 0, 1f);
to
soundPool.play(myVoice, 20, 20, 1, 0, 2f);

the value of 2 will rise the speed to 50% more as you wanted

OTHER TIPS

The last parameter of play() controls the playback rate.

See the docs.

Parameters

soundID: a soundID returned by the load() function

leftVolume: left volume value (range = 0.0 to 1.0)

rightVolume: right volume value (range = 0.0 to 1.0)

priority: stream priority (0 = lowest priority)

loop: loop mode (0 = no loop, -1 = loop forever)

rate: playback rate (1.0 = normal playback, range 0.5 to 2.0)

Note that you can only change the speed from 0.5 to 2.0, meaning half to twice as fast. Anything past that and you'll have to come up with a custom implementation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top