AudioTrack setPlaybackRate - 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 setPlaybackRate method.

This code example shows how to use the following methods:getState, 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);
        //--------    test        -------------- 
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        assertTrue(TEST_NAME, track.setPlaybackRate(0) == AudioTrack.ERROR_BAD_VALUE);
        //-------- tear down      -------------- 
        track.release();
    } 
     
    //Test case 6: setPlaybackRate() accepts values twice the output sample rate 
    @LargeTest 
    public void testSetPlaybackRateTwiceOutputSR() throws Exception { 
        // constants for test 
        final String TEST_NAME = "testSetPlaybackRateTwiceOutputSR";
        final int TEST_SR = 22050;
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:play, reloadStaticData, setPlaybackRate, stop
	} 
 
	public void play(double speed) {
		// Otherwise it plays the sound twice the first time 
		if (!first) {
			at.stop();
			at.reloadStaticData();
		} 
		at.setPlaybackRate((int) (DEFAULT_RATE * speed));
		first = false;
		at.play();
	} 
 
	public void dispose() { 
		at.release();
		buffer = null;
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:play, reloadStaticData, setPlaybackRate, stop
	} 
 
	public void play(double speed) {
		// Otherwise it plays the sound twice the first time 
		if (!first) {
			at.stop();
			at.reloadStaticData();
		} 
		at.setPlaybackRate((int) (DEFAULT_RATE * speed));
		first = false;
		at.play();
	} 
 
	public void dispose() { 
		at.release();
		buffer = null;
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getState, play, release, setPlaybackRate, write
        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];
        int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE);
        //--------    test        -------------- 
        track.write(data, 0, data.length);
        track.write(data, 0, data.length);
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        track.play();
        assertTrue(TEST_NAME, track.setPlaybackRate(2*outputSR) == AudioTrack.SUCCESS);
        //-------- tear down      -------------- 
        track.release();
    } 
     
    //Test case 7: setPlaybackRate() and retrieve value, should be the same for half the content SR 

5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getState, play, release, setPlaybackRate, write
        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];
        int outputSR = AudioTrack.getNativeOutputSampleRate(TEST_STREAM_TYPE);
        //--------    test        -------------- 
        track.write(data, 0, data.length);
        track.write(data, 0, data.length);
        assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
        track.play();
        assertTrue(TEST_NAME, track.setPlaybackRate(2*outputSR) == AudioTrack.SUCCESS);
        //-------- tear down      -------------- 
        track.release();
    } 
     
    //Test case 7: setPlaybackRate() and retrieve value, should be the same for half the content SR 

4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPlaybackRate
	} 
 
	public static void rate(final short id, final int rate) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) != null) {
			audiotrack.setPlaybackRate(rate);
		} 
	} 
 
	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) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPlaybackRate
	} 
 
	public static void rate(final short id, final int rate) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) != null) {
			audiotrack.setPlaybackRate(rate);
		} 
	} 
 
	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) {
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPlaybackRate
 
    private void tweakSpeed(int i) {
        //int sampleRate = _speaker.getPlaybackRate(); 
        _sampleRate += i;
        if ((((_origSampleRate -_sampleRate)*100.0)/_origSampleRate) < 2.0){
            _speaker.setPlaybackRate(_sampleRate);
        } else { 
            _sampleRate -= i;
        } 
        AndroidLog.getLog().debug( 
                this.getClass().getSimpleName()
                + ".tweakSpeed(): would set speed to " + _sampleRate);
    } 
 
    AudioTrack getAudioTrack() {
        return _speaker;
    } 
} 
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:setPlaybackRate
	} 
 
	public static void rate(final short id, final int rate) {
		AudioTrack audiotrack;
		if ((audiotrack = audiotracks.get(id)) != null) {
			audiotrack.setPlaybackRate(rate);
		} 
	} 
 
	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;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
setPlaybackRate Method Overview
Sets the playback sample rate for this track.
See Code Examples for other Android AudioTrack Methods: