Search in sources :

Example 56 with AudioRecord

use of android.media.AudioRecord in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadByteBufferFillsAudioDataByDefault.

@Test
public void nativeReadByteBufferFillsAudioDataByDefault() {
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    assertThat(audioRecord.read(ByteBuffer.allocate(100), 100)).isEqualTo(100);
}
Also used : AudioRecord(android.media.AudioRecord) Test(org.junit.Test)

Example 57 with AudioRecord

use of android.media.AudioRecord in project robolectric by robolectric.

the class ShadowAudioRecordTest method startReturnsSuccess.

@Test
public void startReturnsSuccess() {
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    assertThat(audioRecord.getRecordingState()).isEqualTo(AudioRecord.RECORDSTATE_RECORDING);
}
Also used : AudioRecord(android.media.AudioRecord) Test(org.junit.Test)

Example 58 with AudioRecord

use of android.media.AudioRecord in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadByteBufferCallsAudioRecordSourceWhenSetNonBlockingMOnwards.

@Test
@Config(minSdk = M)
public void nativeReadByteBufferCallsAudioRecordSourceWhenSetNonBlockingMOnwards() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(ByteBuffer.allocate(100), 100, AudioRecord.READ_NON_BLOCKING);
    verify(source).readInDirectBuffer(any(ByteBuffer.class), eq(100), /* isBlocking=*/
    eq(false));
    verifyNoMoreInteractions(source);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 59 with AudioRecord

use of android.media.AudioRecord in project robolectric by robolectric.

the class ShadowAudioRecordTest method nativeReadByteCallsAudioRecordSourceWhenSetNonBlockingMOnwards.

@Test
@Config(minSdk = M)
public void nativeReadByteCallsAudioRecordSourceWhenSetNonBlockingMOnwards() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(new byte[100], 0, 100, AudioRecord.READ_NON_BLOCKING);
    verify(source).readInByteArray(any(byte[].class), eq(0), eq(100), /* isBlocking=*/
    eq(false));
    verifyNoMoreInteractions(source);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 60 with AudioRecord

use of android.media.AudioRecord in project robolectric by robolectric.

the class ShadowAudioRecordTest method setSourceProvider_readBytesSlowly.

@Test
public void setSourceProvider_readBytesSlowly() {
    byte[] audioRecordInput = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
    AudioRecordSource audioRecordSource = createAudioRecordSource(audioRecordInput);
    ShadowAudioRecord.setSourceProvider(audioRecord -> audioRecordSource);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    byte[] audioRecordData = new byte[100];
    int audioRecordBytesFirstRead = audioRecord.read(audioRecordData, 0, 3);
    int audioRecordBytesSecondRead = audioRecord.read(audioRecordData, 3, 3);
    int audioRecordBytesThirdRead = audioRecord.read(audioRecordData, 6, 94);
    audioRecord.stop();
    audioRecord.release();
    assertThat(audioRecordBytesFirstRead).isEqualTo(3);
    assertThat(audioRecordBytesSecondRead).isEqualTo(3);
    assertThat(audioRecordBytesThirdRead).isEqualTo(2);
    assertThat(Arrays.copyOf(audioRecordData, audioRecordInput.length)).isEqualTo(audioRecordInput);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) Test(org.junit.Test)

Aggregations

AudioRecord (android.media.AudioRecord)64 Test (org.junit.Test)22 AudioRecordSource (org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource)13 AssetFileDescriptor (android.content.res.AssetFileDescriptor)12 AudioEffect (android.media.audiofx.AudioEffect)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 Config (org.robolectric.annotation.Config)12 AudioFormat (android.media.AudioFormat)6 SystemApi (android.annotation.SystemApi)5 ByteBuffer (java.nio.ByteBuffer)4 SuppressLint (android.annotation.SuppressLint)1 MediaFormat (android.media.MediaFormat)1 MediaRecorder (android.media.MediaRecorder)1 Handler (android.os.Handler)1 RequiresPermission (androidx.annotation.RequiresPermission)1 AudioDispatcher (be.tarsos.dsp.AudioDispatcher)1 TarsosDSPAudioFormat (be.tarsos.dsp.io.TarsosDSPAudioFormat)1 TarsosDSPAudioInputStream (be.tarsos.dsp.io.TarsosDSPAudioInputStream)1 BufferData (com.libra.sinvoice.Buffer.BufferData)1 ActorCreator (im.actor.runtime.actors.ActorCreator)1