Search in sources :

Example 86 with AudioTrack

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

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

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

the class MediaAudioTrackTest method constructorTestMultiSampleRate.

//-----------------------------------------------------------------
// generic test methods
public TestResults constructorTestMultiSampleRate(// parameters tested by this method
int _inTest_streamType, int _inTest_mode, int _inTest_config, int _inTest_format, // parameter-dependent expected results
int _expected_stateForMode) {
    int[] testSampleRates = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 };
    String failedRates = "Failure for rate(s): ";
    boolean localRes, finalRes = true;
    for (int i = 0; i < testSampleRates.length; i++) {
        //Log.v("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] testing "+ testSampleRates[i]);
        AudioTrack track = null;
        try {
            track = new AudioTrack(_inTest_streamType, testSampleRates[i], _inTest_config, _inTest_format, AudioTrack.getMinBufferSize(testSampleRates[i], _inTest_config, _inTest_format), _inTest_mode);
        } catch (IllegalArgumentException iae) {
            Log.e("MediaAudioTrackTest", "[ constructorTestMultiSampleRate ] exception at SR " + testSampleRates[i] + ": \n" + iae);
            localRes = false;
        }
        if (track != null) {
            localRes = (track.getState() == _expected_stateForMode);
            track.release();
        } else {
            localRes = false;
        }
        if (!localRes) {
            //log the error for the test runner
            failedRates += Integer.toString(testSampleRates[i]) + "Hz ";
            //log the error for logcat
            log("constructorTestMultiSampleRate", "failed to construct " + "AudioTrack(streamType=" + _inTest_streamType + ", sampleRateInHz=" + testSampleRates[i] + ", channelConfig=" + _inTest_config + ", audioFormat=" + _inTest_format + ", bufferSizeInBytes=" + AudioTrack.getMinBufferSize(testSampleRates[i], _inTest_config, AudioFormat.ENCODING_PCM_16BIT) + ", mode=" + _inTest_mode);
            //mark test as failed
            finalRes = false;
        }
    }
    return new TestResults(finalRes, failedRates);
}
Also used : AudioTrack(android.media.AudioTrack)

Example 88 with AudioTrack

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

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

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

the class MediaAudioTrackTest method testSetPlaybackHeadPositionStopped.

//Test case 2: setPlaybackHeadPosition() on stopped track
@LargeTest
public void testSetPlaybackHeadPositionStopped() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetPlaybackHeadPositionStopped";
    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.stop();
    assumeTrue(TEST_NAME, track.getPlayState() == AudioTrack.PLAYSTATE_STOPPED);
    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 90 with AudioTrack

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

the class MediaAudioTrackTest method testSetStereoVolumeMid.

//Test case 3: setStereoVolume() with mid volume returns SUCCESS
@LargeTest
public void testSetStereoVolumeMid() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetStereoVolumeMid";
    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 midVol = (AudioTrack.getMaxVolume() - AudioTrack.getMinVolume()) / 2;
    assertTrue(TEST_NAME, track.setStereoVolume(midVol, midVol) == AudioTrack.SUCCESS);
    //-------- 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