0

I am trying to develop an application which plays one of the predefined arrays of sounds continuously and also change the the tempo,pitch (individually) etc using soundpool class of android.

I know how to change the pitch of a sound.

But I do not know how to play the whole array and also the tempo of that whole array.

Please help!

Thank you in advance!

EDIT : I think I will have to use Handler in order to play the array of sounds, but i don't know how!

1 Answers1

0
public class Sound {

private static int length = 22050 * 10; //10 seconds long
private static byte[] data = new byte[length];

static void fillRandom() {
new Random().nextBytes(data); //Create some random noise to listen to.
}

static void play() {

fillRandom();

final int TEST_SR = 22050; //This is from an example I found online.
final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO;
final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
final int TEST_MODE = AudioTrack.MODE_STATIC; //I need static mode.
final int TEST_STREAM_TYPE = AudioManager.STREAM_ALARM;
AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, length, TEST_MODE);
track.write(data, 0, length);
track.play();
}
}

This code play some random noises. All you have to do is fill the byte[]data array with the proper music files you intend to play...

O_o
  • 1,103
  • 11
  • 36