Search in sources :

Example 76 with AudioTrack

use of android.media.AudioTrack in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioTrackTest method testWriteShortNegativeSize.

//Test case 8: write() fails with negative size
@LargeTest
public void testWriteShortNegativeSize() throws Exception {
    // constants for test
    final String TEST_NAME = "testWriteShortNegativeSize";
    final int TEST_SR = 22050;
    final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO;
    final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
    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, 2 * minBuffSize, TEST_MODE);
    short[] data = new short[minBuffSize / 2];
    //--------    test        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    assertTrue(TEST_NAME, track.write(data, 0, -10) == AudioTrack.ERROR_BAD_VALUE);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 77 with AudioTrack

use of android.media.AudioTrack in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioTrackTest method testSetPlaybackRateTwiceOutputSR.

//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;
    final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO;
    final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
    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();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 78 with AudioTrack

use of android.media.AudioTrack in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioTrackTest method testSetGetPlaybackRate.

//Test case 7: setPlaybackRate() and retrieve value, should be the same for half the content SR
@LargeTest
public void testSetGetPlaybackRate() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetGetPlaybackRate";
    final int TEST_SR = 22050;
    final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO;
    final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
    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();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 79 with AudioTrack

use of android.media.AudioTrack in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioTrackTest method testSetLoopPointsStartTooFar.

//Test case 8: setLoopPoints() fails with start beyond what can be written for the track
@LargeTest
public void testSetLoopPointsStartTooFar() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetLoopPointsStartTooFar";
    final int TEST_SR = 22050;
    final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO;
    final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
    final int TEST_MODE = AudioTrack.MODE_STATIC;
    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];
    //16bit data
    int dataSizeInFrames = minBuffSize / 2;
    //--------    test        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_NO_STATIC_DATA);
    track.write(data, 0, data.length);
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    assertTrue(TEST_NAME, track.setLoopPoints(dataSizeInFrames + 20, dataSizeInFrames + 50, 2) == AudioTrack.ERROR_BAD_VALUE);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 80 with AudioTrack

use of android.media.AudioTrack in project android_frameworks_base by DirtyUnicorns.

the class MediaAudioTrackTest method testPlaybackHeadPositionIncrease.

//Test case 2: getPlaybackHeadPosition() increases after play()
@LargeTest
public void testPlaybackHeadPositionIncrease() throws Exception {
    // constants for test
    final String TEST_NAME = "testPlaybackHeadPositionIncrease";
    final int TEST_SR = 22050;
    final int TEST_CONF = AudioFormat.CHANNEL_OUT_STEREO;
    final int TEST_FORMAT = AudioFormat.ENCODING_PCM_16BIT;
    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        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    track.write(data, 0, data.length);
    track.write(data, 0, data.length);
    track.play();
    Thread.sleep(100);
    log(TEST_NAME, "position =" + track.getPlaybackHeadPosition());
    assertTrue(TEST_NAME, track.getPlaybackHeadPosition() > 0);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

AudioTrack (android.media.AudioTrack)262 LargeTest (android.test.suitebuilder.annotation.LargeTest)222 AudioEffect (android.media.audiofx.AudioEffect)6 SystemApi (android.annotation.SystemApi)5 AudioFormat (android.media.AudioFormat)5 SuppressLint (android.annotation.SuppressLint)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 CalledByNative (org.chromium.base.CalledByNative)1 Sonic (org.vinuxproject.sonic.Sonic)1