Search in sources :

Example 51 with AudioTrack

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

the class MediaAudioTrackTest method testWriteShort8bit.

//Test case 12: write() succeeds and returns the size that was written for 8bit
@LargeTest
public void testWriteShort8bit() throws Exception {
    // constants for test
    final String TEST_NAME = "testWriteShort8bit";
    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);
    short[] data = new short[minBuffSize / 2];
    //--------    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 52 with AudioTrack

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

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

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

the class MediaAudioTrackTest method testWriteByteNegativeOffset.

//Test case 5: write() fails with negative offset
@LargeTest
public void testWriteByteNegativeOffset() throws Exception {
    // constants for test
    final String TEST_NAME = "testWriteByteNegativeOffset";
    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, -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 54 with AudioTrack

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

the class MediaAudioTrackTest method testSetStereoVolumeMin.

//Test case 2: setStereoVolume() with min volume returns SUCCESS
@LargeTest
public void testSetStereoVolumeMin() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetStereoVolumeMin";
    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 minVol = AudioTrack.getMinVolume();
    assertTrue(TEST_NAME, track.setStereoVolume(minVol, minVol) == AudioTrack.SUCCESS);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 55 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)

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