Search in sources :

Example 31 with AudioTrack

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

the class MediaAudioTrackTest method testSetLoopPointsEndTooFar.

//Test case 9: setLoopPoints() fails with end beyond what can be written for the track
@LargeTest
public void testSetLoopPointsEndTooFar() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetLoopPointsEndTooFar";
    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 - 10, dataSizeInFrames + 50, 2) == AudioTrack.ERROR_BAD_VALUE);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 32 with AudioTrack

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

the class MediaAudioTrackTest method testSetPlaybackHeadPositionPaused.

//Test case 3: setPlaybackHeadPosition() on paused track
@LargeTest
public void testSetPlaybackHeadPositionPaused() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetPlaybackHeadPositionPaused";
    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);
    byte[] data = new byte[minBuffSize];
    //--------    test        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    track.write(data, 0, data.length);
    track.write(data, 0, data.length);
    track.play();
    track.pause();
    assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_PAUSED);
    assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.SUCCESS);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 33 with AudioTrack

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

the class MediaAudioTrackTest method testWriteByte.

//Test case 9: write() succeeds and returns the size that was written for 16bit
@LargeTest
public void testWriteByte() throws Exception {
    // constants for test
    final String TEST_NAME = "testWriteByte";
    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);
    byte[] data = new byte[minBuffSize];
    //--------    test        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    assertTrue(TEST_NAME, track.write(data, 0, data.length) == data.length);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 34 with AudioTrack

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

the class MediaAudioTrackTest method testSetPlaybackRateZero.

//Test case 5: setPlaybackRate(0) returns bad value error
@LargeTest
public void testSetPlaybackRateZero() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetPlaybackRateZero";
    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);
    //--------    test        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    assertTrue(TEST_NAME, track.setPlaybackRate(0) == AudioTrack.ERROR_BAD_VALUE);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 35 with AudioTrack

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

the class MediaAudioTrackTest method testSetPlaybackHeadPositionPlaying.

//-----------------------------------------------------------------
//      Playback progress
//----------------------------------
//Test case 1: setPlaybackHeadPosition() on playing track
@LargeTest
public void testSetPlaybackHeadPositionPlaying() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetPlaybackHeadPositionPlaying";
    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);
    byte[] data = new byte[minBuffSize];
    //--------    test        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    track.write(data, 0, data.length);
    track.write(data, 0, data.length);
    track.play();
    assertTrue(TEST_NAME, track.setPlaybackHeadPosition(10) == AudioTrack.ERROR_INVALID_OPERATION);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

AudioTrack (android.media.AudioTrack)280 LargeTest (android.test.suitebuilder.annotation.LargeTest)222 Test (org.junit.Test)10 Config (org.robolectric.annotation.Config)9 ByteBuffer (java.nio.ByteBuffer)7 AudioFormat (android.media.AudioFormat)6 AudioEffect (android.media.audiofx.AudioEffect)6 SystemApi (android.annotation.SystemApi)5 SuppressLint (android.annotation.SuppressLint)3 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 TargetApi (android.annotation.TargetApi)1 AudioManager (android.media.AudioManager)1 ResultReceiver (android.os.ResultReceiver)1 FileNotFoundException (java.io.FileNotFoundException)1 InvalidParameterException (java.security.InvalidParameterException)1 CalledByNative (org.chromium.base.CalledByNative)1 Sonic (org.vinuxproject.sonic.Sonic)1