Search in sources :

Example 11 with AudioTrack

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

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 12 with AudioTrack

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

the class MediaAudioTrackTest method testPlaybackHeadPositionAfterInit.

//-----------------------------------------------------------------
//      Playback head position
//----------------------------------
//Test case 1: getPlaybackHeadPosition() at 0 after initialization
@LargeTest
public void testPlaybackHeadPositionAfterInit() throws Exception {
    // constants for test
    final String TEST_NAME = "testPlaybackHeadPositionAfterInit";
    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 --------------
    AudioTrack track = new AudioTrack(TEST_STREAM_TYPE, TEST_SR, TEST_CONF, TEST_FORMAT, AudioTrack.getMinBufferSize(TEST_SR, TEST_CONF, TEST_FORMAT), TEST_MODE);
    //--------    test        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    assertTrue(TEST_NAME, track.getPlaybackHeadPosition() == 0);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 13 with AudioTrack

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

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)

Example 14 with AudioTrack

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

the class MediaAudioTrackTest method testSetStereoVolumeMax.

//-----------------------------------------------------------------
//      Playback properties
//----------------------------------
//Test case 1: setStereoVolume() with max volume returns SUCCESS
@LargeTest
public void testSetStereoVolumeMax() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetStereoVolumeMax";
    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);
    track.play();
    float maxVol = AudioTrack.getMaxVolume();
    assertTrue(TEST_NAME, track.setStereoVolume(maxVol, maxVol) == AudioTrack.SUCCESS);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 15 with AudioTrack

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

the class MediaAudioTrackTest method testSetLoopPointsStream.

//Test case 5: setLoopPoints() fails for MODE_STREAM
@LargeTest
public void testSetLoopPointsStream() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetLoopPointsStream";
    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        --------------
    track.write(data, 0, data.length);
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    assertTrue(TEST_NAME, track.setLoopPoints(2, 50, 2) == 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