AudioTrack getPlaybackRate - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AudioTrack getPlaybackRate method.

This code example shows how to use the following methods:getPlaybackRate, getState, play, release, setPlaybackRate
        final int TEST_MODE = AudioTrack.MODE_STREAM;
        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
         
        //-------- initialization -------------- 
        int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
        AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, 
                minBuffSize, TEST_MODE);
        byte data[] = new byte[minBuffSize/2];
        //--------    test        -------------- 
        track.write(data, 0, data.length);
        track.write(data, 0, data.length);
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        track.play();
        track.setPlaybackRate((int)(TEST_SR/2));
        assertTrue(TEST_NAME, track.getPlaybackRate() == (int)(TEST_SR/2));
        //-------- tear down      -------------- 
        track.release();
    } 
     
    //Test case 8: setPlaybackRate() invalid operation if track not initialized 

6
CodeRank
This code example shows how to use the following methods:getNotificationMarkerPosition, getPlaybackHeadPosition, getPlaybackRate, getPositionNotificationPeriod, getSampleRate
                                        AudioManager.STREAM_VOICE_CALL));
 
        final int playBufSize = minPlayBufSize; // 3200; // 100 ms buffer
        // byte[] playBuffer = new byte [playBufSize]; 
        try { 
            _at = new AudioTrack(
                            AudioManager.STREAM_VOICE_CALL,
                            16000, 
                            AudioFormat.CHANNEL_CONFIGURATION_MONO,
                            AudioFormat.ENCODING_PCM_16BIT,
                            playBufSize, AudioTrack.MODE_STREAM);
        } catch (Exception e) {
            WebrtcLog(e.getMessage());
        } 
 
        // Log some info (non-static) 
        WebrtcLog("Notification marker pos = " 
                        + _at.getNotificationMarkerPosition());
        WebrtcLog("Play head pos = " + _at.getPlaybackHeadPosition());
        WebrtcLog("Pos notification dt = " 

6
CodeRank
This code example shows how to use the following methods:getPlaybackRate, getState, play, release, setPlaybackRate
        final int TEST_MODE = AudioTrack.MODE_STREAM;
        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
         
        //-------- initialization -------------- 
        int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
        AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, 
                minBuffSize, TEST_MODE);
        byte data[] = new byte[minBuffSize/2];
        //--------    test        -------------- 
        track.write(data, 0, data.length);
        track.write(data, 0, data.length);
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        track.play();
        track.setPlaybackRate((int)(TEST_SR/2));
        assertTrue(TEST_NAME, track.getPlaybackRate() == (int)(TEST_SR/2));
        //-------- tear down      -------------- 
        track.release();
    } 
     
    //Test case 8: setPlaybackRate() invalid operation if track not initialized 

5
CodeRank
This code example shows how to use the following methods:getPlaybackRate, getState, play, release, setPlaybackRate
        final int TEST_MODE = AudioTrack.MODE_STREAM;
        final int TEST_STREAM_TYPE = AudioManager.STREAM_MUSIC;
         
        //-------- initialization -------------- 
        int minBuffSize = AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT);
        AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, 
                minBuffSize, TEST_MODE);
        byte data[] = new byte[minBuffSize/2];
        //--------    test        -------------- 
        track.write(data, 0, data.length);
        track.write(data, 0, data.length);
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        track.play();
        track.setPlaybackRate((int)(TEST_SR/2));
        assertTrue(TEST_NAME, track.getPlaybackRate() == (int)(TEST_SR/2));
        //-------- tear down      -------------- 
        track.release();
    } 
     
    //Test case 8: setPlaybackRate() invalid operation if track not initialized 

4
CodeRank
This code example shows how to use the following methods:getPlaybackRate
	} 
 
	public static int rate(final short id) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) != null) {
			return audiotrack.getPlaybackRate();
		} 
		return 0; 
	} 
 
	public static void write(final short id, final int rate, final byte channels, final byte[] sample, final int length) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) == null) {
			audiotrack = open(id, rate, channels,
					(rate == 48000)
						? AudioTrack.getMinBufferSize(
								48000, 
								(channels == 2)
									? AudioFormat.CHANNEL_CONFIGURATION_STEREO
									: AudioFormat.CHANNEL_CONFIGURATION_MONO,
5
CodeRank
This code example shows how to use the following methods:getPlaybackRate
	} 
 
	public static int rate(final short id) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) != null) {
			return audiotrack.getPlaybackRate();
		} 
		return 0; 
	} 
 
	public static void write(final short id, final int rate, final byte channels, final byte[] sample, final int length) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) == null) {
			audiotrack = open(id, rate, channels, VentriloInterface.pcmlengthforrate(rate) * channels * 2);
			audiotrack.play();
		} 
		audiotrack.write(sample, 0, length);
	} 
 
} 
4
CodeRank
This code example shows how to use the following methods:getPlaybackRate
	} 
 
	public static int rate(final short id) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) != null) {
			return audiotrack.getPlaybackRate();
		} 
		return 0; 
	} 
 
	public static void write(final short id, final int rate,
			final byte channels, final byte[] sample, final int length) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) == null) {
			audiotrack = open(id, rate, channels, VentriloInterface
					.pcmlengthforrate(rate)
					* channels * 2);
			audiotrack.play();
		} 
		audiotrack.write(sample, 0, length);
4
CodeRank
getPlaybackRate Method Overview
Returns the current playback rate in Hz.
See Code Examples for other Android AudioTrack Methods: