use of android.media.AudioTrack in project android_frameworks_base by ResurrectionRemix.
the class MediaAudioTrackTest method testWriteByteOffsetTooBig.
//-----------------------------------------------------------------
// Audio data supply
//----------------------------------
//Test case 1: write() fails when supplying less data (bytes) than declared
@LargeTest
public void testWriteByteOffsetTooBig() throws Exception {
// constants for test
final String TEST_NAME = "testWriteByteOffsetTooBig";
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) == AudioTrack.ERROR_BAD_VALUE);
//-------- tear down --------------
track.release();
}
use of android.media.AudioTrack in project android_frameworks_base by ResurrectionRemix.
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();
}
use of android.media.AudioTrack in project android_frameworks_base by ResurrectionRemix.
the class MediaAudioTrackTest method testWriteByteNegativeSize.
//Test case 7: write() fails with negative size
@LargeTest
public void testWriteByteNegativeSize() throws Exception {
// constants for test
final String TEST_NAME = "testWriteByteNegativeSize";
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, -10) == AudioTrack.ERROR_BAD_VALUE);
//-------- tear down --------------
track.release();
}
use of android.media.AudioTrack in project android_frameworks_base by ResurrectionRemix.
the class AudioPolicy method createAudioTrackSource.
/**
* Create an {@link AudioTrack} instance that is associated with the given {@link AudioMix}.
* Audio buffers played through the created instance will be sent to the given mix
* to be recorded through the recording APIs.
* @param mix a non-null {@link AudioMix} instance whose routing flags was defined with
* {@link AudioMix#ROUTE_FLAG_LOOP_BACK}, previously added to this policy.
* @return a new {@link AudioTrack} instance whose data format is the one defined in the
* {@link AudioMix}, or null if this policy was not successfully registered
* with {@link AudioManager#registerAudioPolicy(AudioPolicy)}.
* @throws IllegalArgumentException
*/
@SystemApi
public AudioTrack createAudioTrackSource(AudioMix mix) throws IllegalArgumentException {
if (!policyReadyToUse()) {
Log.e(TAG, "Cannot create AudioTrack source for AudioMix");
return null;
}
checkMixReadyToUse(mix, true);
// create the AudioTrack, configured for loop back, using the same format as the mix
AudioTrack at = new AudioTrack(new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_VIRTUAL_SOURCE).addTag(addressForTag(mix)).build(), mix.getFormat(), AudioTrack.getMinBufferSize(mix.getFormat().getSampleRate(), mix.getFormat().getChannelMask(), mix.getFormat().getEncoding()), AudioTrack.MODE_STREAM, AudioManager.AUDIO_SESSION_ID_GENERATE);
return at;
}
use of android.media.AudioTrack in project android_frameworks_base by DirtyUnicorns.
the class AudioPolicy method createAudioTrackSource.
/**
* Create an {@link AudioTrack} instance that is associated with the given {@link AudioMix}.
* Audio buffers played through the created instance will be sent to the given mix
* to be recorded through the recording APIs.
* @param mix a non-null {@link AudioMix} instance whose routing flags was defined with
* {@link AudioMix#ROUTE_FLAG_LOOP_BACK}, previously added to this policy.
* @return a new {@link AudioTrack} instance whose data format is the one defined in the
* {@link AudioMix}, or null if this policy was not successfully registered
* with {@link AudioManager#registerAudioPolicy(AudioPolicy)}.
* @throws IllegalArgumentException
*/
@SystemApi
public AudioTrack createAudioTrackSource(AudioMix mix) throws IllegalArgumentException {
if (!policyReadyToUse()) {
Log.e(TAG, "Cannot create AudioTrack source for AudioMix");
return null;
}
checkMixReadyToUse(mix, true);
// create the AudioTrack, configured for loop back, using the same format as the mix
AudioTrack at = new AudioTrack(new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_VIRTUAL_SOURCE).addTag(addressForTag(mix)).build(), mix.getFormat(), AudioTrack.getMinBufferSize(mix.getFormat().getSampleRate(), mix.getFormat().getChannelMask(), mix.getFormat().getEncoding()), AudioTrack.MODE_STREAM, AudioManager.AUDIO_SESSION_ID_GENERATE);
return at;
}
Aggregations