Search in sources :

Example 21 with AudioRecord

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

the class ShadowAudioRecordTest method nativeReadShortCallsAudioRecordSourceWhenSet.

@Test
public void nativeReadShortCallsAudioRecordSourceWhenSet() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(new short[100], 0, 100);
    verify(source).readInShortArray(any(short[].class), eq(0), eq(100), /* isBlocking=*/
    eq(true));
    verifyNoMoreInteractions(source);
}
Also used : AudioRecord(android.media.AudioRecord) AudioRecordSource(org.robolectric.shadows.ShadowAudioRecord.AudioRecordSource) Test(org.junit.Test)

Example 22 with AudioRecord

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

the class ShadowAudioRecordTest method nativeReadFloatFillsAudioDataByDefaultMOnwards.

@Test
@Config(minSdk = M)
public void nativeReadFloatFillsAudioDataByDefaultMOnwards() {
    AudioRecord audioRecord = new AudioRecord(AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_FLOAT, 1024);
    audioRecord.startRecording();
    assertThat(audioRecord.read(new float[100], 0, 100, AudioRecord.READ_BLOCKING)).isEqualTo(100);
}
Also used : AudioRecord(android.media.AudioRecord) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 23 with AudioRecord

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

the class ShadowAudioRecordTest method nativeReadByteBufferCallsAudioRecordSourceWhenSet.

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

Example 24 with AudioRecord

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

the class ShadowAudioRecordTest method nativeReadByteFillsAudioDataByDefaultMOnwards.

@Test
@Config(minSdk = M)
public void nativeReadByteFillsAudioDataByDefaultMOnwards() {
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    assertThat(audioRecord.read(new byte[100], 0, 100, AudioRecord.READ_BLOCKING)).isEqualTo(100);
}
Also used : AudioRecord(android.media.AudioRecord) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 25 with AudioRecord

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

the class ShadowAudioRecordTest method nativeReadByteCallsAudioRecordSourceWhenSet.

@Test
public void nativeReadByteCallsAudioRecordSourceWhenSet() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(new byte[100], 0, 100);
    verify(source).readInByteArray(any(byte[].class), eq(0), eq(100), /* isBlocking=*/
    eq(true));
    verifyNoMoreInteractions(source);
}
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