Search in sources :

Example 46 with AudioTrack

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

the class MediaAudioTrackTest method testSetPlaybackHeadPositionTooFar.

//Test case 4: setPlaybackHeadPosition() beyond what has been written
@LargeTest
public void testSetPlaybackHeadPositionTooFar() throws Exception {
    // constants for test
    final String TEST_NAME = "testSetPlaybackHeadPositionTooFar";
    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];
    // make up a frame index that's beyond what has been written: go from buffer size to frame
    //   count (given the audio track properties), and add 77.
    int frameIndexTooFar = (2 * minBuffSize / 2) + 77;
    //--------    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(frameIndexTooFar) == AudioTrack.ERROR_BAD_VALUE);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 47 with AudioTrack

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

the class MediaAudioTrackTest method testPlaybackHeadPositionAfterStop.

//Test case 3: getPlaybackHeadPosition() is 0 after stop();
@LargeTest
public void testPlaybackHeadPositionAfterStop() throws Exception {
    // constants for test
    final String TEST_NAME = "testPlaybackHeadPositionAfterStop";
    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        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    track.write(data, 0, data.length);
    track.write(data, 0, data.length);
    track.play();
    Thread.sleep(100);
    track.stop();
    // TODO: what is a sensible value?
    Thread.sleep(100);
    int pos = track.getPlaybackHeadPosition();
    log(TEST_NAME, "position =" + pos);
    assertTrue(TEST_NAME, pos == 0);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 48 with AudioTrack

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

the class MediaAudioTrackTest method testPlaybackHeadPositionIncrease.

//Test case 2: getPlaybackHeadPosition() increases after play()
@LargeTest
public void testPlaybackHeadPositionIncrease() throws Exception {
    // constants for test
    final String TEST_NAME = "testPlaybackHeadPositionIncrease";
    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        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    track.write(data, 0, data.length);
    track.write(data, 0, data.length);
    track.play();
    Thread.sleep(100);
    log(TEST_NAME, "position =" + track.getPlaybackHeadPosition());
    assertTrue(TEST_NAME, track.getPlaybackHeadPosition() > 0);
    //-------- tear down      --------------
    track.release();
}
Also used : AudioTrack(android.media.AudioTrack) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 49 with AudioTrack

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

the class BlockingAudioTrack method createStreamingAudioTrack.

private AudioTrack createStreamingAudioTrack() {
    final int channelConfig = getChannelConfig(mChannelCount);
    int minBufferSizeInBytes = AudioTrack.getMinBufferSize(mSampleRateInHz, channelConfig, mAudioFormat);
    int bufferSizeInBytes = Math.max(MIN_AUDIO_BUFFER_SIZE, minBufferSizeInBytes);
    AudioFormat audioFormat = (new AudioFormat.Builder()).setChannelMask(channelConfig).setEncoding(mAudioFormat).setSampleRate(mSampleRateInHz).build();
    AudioTrack audioTrack = new AudioTrack(mAudioParams.mAudioAttributes, audioFormat, bufferSizeInBytes, AudioTrack.MODE_STREAM, mAudioParams.mSessionId);
    if (audioTrack.getState() != AudioTrack.STATE_INITIALIZED) {
        Log.w(TAG, "Unable to create audio track.");
        audioTrack.release();
        return null;
    }
    mAudioBufferSize = bufferSizeInBytes;
    setupVolume(audioTrack, mAudioParams.mVolume, mAudioParams.mPan);
    return audioTrack;
}
Also used : AudioTrack(android.media.AudioTrack) AudioFormat(android.media.AudioFormat)

Example 50 with AudioTrack

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

the class MediaAudioTrackTest method testPlaybackHeadPositionIncrease.

//Test case 2: getPlaybackHeadPosition() increases after play()
@LargeTest
public void testPlaybackHeadPositionIncrease() throws Exception {
    // constants for test
    final String TEST_NAME = "testPlaybackHeadPositionIncrease";
    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        --------------
    assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
    track.write(data, 0, data.length);
    track.write(data, 0, data.length);
    track.play();
    Thread.sleep(100);
    log(TEST_NAME, "position =" + track.getPlaybackHeadPosition());
    assertTrue(TEST_NAME, track.getPlaybackHeadPosition() > 0);
    //-------- 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