Code example for AudioTrack

Methods: play

0
	private final int latency;
 
	AndroidAudioDevice (int samplingRate, boolean isMono) {
		this.isMono = isMono;
		int minSize = AudioTrack.getMinBufferSize(samplingRate, isMono ? AudioFormat.CHANNEL_CONFIGURATION_MONO
			: AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT);
		track = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, isMono ? AudioFormat.CHANNEL_CONFIGURATION_MONO
			: AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, minSize, AudioTrack.MODE_STREAM);
		track.play();
		latency = minSize / (isMono?1:2);
	} 
 
	@Override public void dispose () { 
		track.stop();
		track.release();
	} 
 
	@Override public boolean isMono () { 
		return isMono;
	}