Creating Immersive Experiences with Stereo Speakers on Kindle Fire HD

One of the great new features that the Kindle Fire HD offers is a set of dual-driver stereo speakers on both sides of the display. This sound setup opens new possibilities to game and app developers by allowing for a more comprehensive and immersive sound experience.With minor adjustments, any app can leverage the stereo speakers and enhance the user experience. By default, Kindle Fire HD uses both speakers to output balanced sound (left speaker = right speaker). By changing the volume on either side, we can achieve an effect of localized sound. As a simple example, we can consider a conga drum app. The app will have two conga drums displayed, one on the left and one on the right. Tapping on the left conga produces sound only in the left speaker and similarly, tapping on the right drum produces sound only in the right speaker.

The way to control the volume on the speakers depends on the method being used to actually play sound. For the purpose of this post, we will assume that the MediaPlayer class is used, but most other methods should be similar if not identical in nature. The following code will create a MediaPlayer instance that will play audio only through the left speaker:

import android.media.MediaPlayer;

float leftVolume = 1.0f;

float rightVolume = 0.0f;

 

MediaPlayer mPlayer = MediaPlayer.create(…);

if (nPlayer == null) {

            mPlayer.setVolume(leftVolume,rightVolume);

}

The leftVolume and rightVolume parameters can be set toany value between 0.0 (“off”) and 1.0 (“full volume”). The volume level is relative to the master volume of the device so changing these values is basically just changing the balance between the stereo channels or, in this case, the two speakers.

Using the SoundPool class is not all that different:

 

import android.media.SoundPool;

float leftVolume = 1.0f;

float rightVolume = 0.0f;

 

SoundPool sPool = new SoundPool(…);

// Load an asset into the pool

int streamId = sPool.load(…);

 

sPool.play(streamId,leftVolume, rightVolume ,0, 0, 1.0);

Unavailable During Maintenance