use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadByteBufferFillsAudioDataByDefaultMOnwards.
@Test
@Config(minSdk = M)
public void nativeReadByteBufferFillsAudioDataByDefaultMOnwards() {
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
assertThat(audioRecord.read(ByteBuffer.allocate(100), 100, AudioRecord.READ_BLOCKING)).isEqualTo(100);
}
use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadFloatCallsAudioRecordSourceWhenSetBlocking.
@Test
@Config(minSdk = M)
public void nativeReadFloatCallsAudioRecordSourceWhenSetBlocking() {
AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
ShadowAudioRecord.setSource(source);
AudioRecord audioRecord = new AudioRecord(AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_FLOAT, 1024);
audioRecord.startRecording();
audioRecord.read(new float[100], 0, 100, AudioRecord.READ_BLOCKING);
verify(source).readInFloatArray(any(float[].class), eq(0), eq(100), /* isBlocking=*/
eq(true));
verifyNoMoreInteractions(source);
}
use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadShortFillsAudioDataByDefault.
@Test
public void nativeReadShortFillsAudioDataByDefault() {
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
assertThat(audioRecord.read(new short[100], 0, 100)).isEqualTo(100);
}
use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method setSourceProvider.
@Test
public void setSourceProvider() {
byte[] firstAudioRecordInput = new byte[] { 1, 2, 3 };
AudioRecordSource firstAudioRecordSource = createAudioRecordSource(firstAudioRecordInput);
AudioRecord firstAudioRecord = createAudioRecord();
byte[] secondAudioRecordInput = new byte[] { 4, 5, 6, 7, 8 };
AudioRecordSource subsequentAudioRecordSource = createAudioRecordSource(secondAudioRecordInput);
AudioRecord secondAudioRecord = createAudioRecord();
ShadowAudioRecord.setSourceProvider(audioRecord -> {
if (audioRecord == firstAudioRecord) {
return firstAudioRecordSource;
}
return subsequentAudioRecordSource;
});
firstAudioRecord.startRecording();
byte[] firstAudioRecordData = new byte[100];
int firstAudioRecordBytesRead = firstAudioRecord.read(firstAudioRecordData, 0, 100);
firstAudioRecord.stop();
firstAudioRecord.release();
// Read from second AudioRecord.
secondAudioRecord.startRecording();
byte[] secondAudioRecordData = new byte[100];
int secondAudioRecordBytesRead = secondAudioRecord.read(secondAudioRecordData, 0, 100);
secondAudioRecord.stop();
secondAudioRecord.release();
assertThat(firstAudioRecordBytesRead).isEqualTo(firstAudioRecordInput.length);
assertThat(Arrays.copyOf(firstAudioRecordData, firstAudioRecordInput.length)).isEqualTo(firstAudioRecordInput);
assertThat(secondAudioRecordBytesRead).isEqualTo(secondAudioRecordInput.length);
assertThat(Arrays.copyOf(secondAudioRecordData, secondAudioRecordInput.length)).isEqualTo(secondAudioRecordInput);
}
use of android.media.AudioRecord in project robolectric by robolectric.
the class ShadowAudioRecordTest method nativeReadShortFillsAudioDataByDefaultMOnwards.
@Test
@Config(minSdk = M)
public void nativeReadShortFillsAudioDataByDefaultMOnwards() {
AudioRecord audioRecord = createAudioRecord();
audioRecord.startRecording();
assertThat(audioRecord.read(new short[100], 0, 100, AudioRecord.READ_BLOCKING)).isEqualTo(100);
}
Aggregations