use of android.media.AudioTrack in project android_frameworks_base by ParanoidAndroid.
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);
}
use of android.media.AudioTrack in project android_frameworks_base by ParanoidAndroid.
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();
}
use of android.media.AudioTrack in project android_frameworks_base by ParanoidAndroid.
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();
}
use of android.media.AudioTrack in project android_frameworks_base by ParanoidAndroid.
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 ParanoidAndroid.
the class MediaAudioTrackTest method testSetLoopPointsStartAfterEnd.
//Test case 6: setLoopPoints() fails start > end
@LargeTest
public void testSetLoopPointsStartAfterEnd() throws Exception {
// constants for test
final String TEST_NAME = "testSetLoopPointsStartAfterEnd";
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];
//-------- test --------------
track.write(data, 0, data.length);
assumeTrue(TEST_NAME, track.getState() == AudioTrack.STATE_INITIALIZED);
assertTrue(TEST_NAME, track.setLoopPoints(50, 0, 2) == AudioTrack.ERROR_BAD_VALUE);
//-------- tear down --------------
track.release();
}
Aggregations