Search in sources :

Example 36 with AudioTrack

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

the class MediaAudioTrackTest method testWriteByteSizeTooBig.

//Test case 3: write() fails when supplying less data (bytes) than declared
@LargeTest
public void testWriteByteSizeTooBig() throws Exception {
    // constants for test
    final String TEST_NAME = "testWriteByteSizeTooBig";
    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 + 10) == AudioTrack.ERROR_BAD_VALUE);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 37 with AudioTrack

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

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

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

the class MediaAudioTrackTest method testWriteShortNegativeOffset.

//Test case 6: write() fails with negative offset
@LargeTest
public void testWriteShortNegativeOffset() throws Exception {
    // constants for test
    final String TEST_NAME = "testWriteShortNegativeOffset";
    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, -10, data.length - 10) == AudioTrack.ERROR_BAD_VALUE);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 39 with AudioTrack

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

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)

Example 40 with AudioTrack

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

the class MediaAudioTrackTest method testWriteByte8bit.

//Test case 11: write() succeeds and returns the size that was written for 8bit
@LargeTest
public void testWriteByte8bit() throws Exception {
    // constants for test
    final String TEST_NAME = "testWriteByte8bit";
    final int TEST_SR = 22050;
    final int TEST_CONF = AudioFormat.CHANNEL_OUT_MONO;
    final int TEST_FORMAT = AudioFormat.ENCODING_PCM_8BIT;
    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)

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