Search in sources :

Example 26 with AudioRecord

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

the class ShadowAudioRecordTest method nativeReadByteFillsAudioDataByDefault.

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

Example 27 with AudioRecord

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

the class ShadowAudioRecordTest method nativeReadShortCallsAudioRecordSourceWhenSetNonBlockingMOnwards.

@Test
@Config(minSdk = M)
public void nativeReadShortCallsAudioRecordSourceWhenSetNonBlockingMOnwards() {
    AudioRecordSource source = Mockito.mock(AudioRecordSource.class);
    ShadowAudioRecord.setSource(source);
    AudioRecord audioRecord = createAudioRecord();
    audioRecord.startRecording();
    audioRecord.read(new short[100], 0, 100, AudioRecord.READ_NON_BLOCKING);
    verify(source).readInShortArray(any(short[].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 28 with AudioRecord

use of android.media.AudioRecord in project Horizon by Yalantis.

the class DemoActivity method initRecorder.

private void initRecorder() {
    final int bufferSize = 2 * AudioRecord.getMinBufferSize(RECORDER_SAMPLE_RATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING);
    audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, RECORDER_SAMPLE_RATE, RECORDER_CHANNELS, RECORDER_AUDIO_ENCODING, bufferSize);
    AudioUtil.initProcessor(RECORDER_SAMPLE_RATE, RECORDER_CHANNELS, RECORDER_ENCODING_BIT);
    recordingThread = new Thread("recorder") {

        @Override
        public void run() {
            super.run();
            buffer = new byte[bufferSize];
            Looper.prepare();
            audioRecord.setRecordPositionUpdateListener(recordPositionUpdateListener, new Handler(Looper.myLooper()));
            int bytePerSample = RECORDER_ENCODING_BIT / 8;
            float samplesToDraw = bufferSize / bytePerSample;
            audioRecord.setPositionNotificationPeriod((int) samplesToDraw);
            // We need to read first chunk to motivate recordPositionUpdateListener.
            // Mostly, for lower versions - https://code.google.com/p/android/issues/detail?id=53996
            audioRecord.read(buffer, 0, bufferSize);
            Looper.loop();
        }
    };
}
Also used : AudioRecord(android.media.AudioRecord) Handler(android.os.Handler)

Example 29 with AudioRecord

use of android.media.AudioRecord in project actor-platform by actorapp.

the class AudioStreamVolumeValueActor method subscribeForVolume.

private void subscribeForVolume(VolumeValueListener callback) {
    if (audioRecord == null) {
        int minBufferSize = AudioRecord.getMinBufferSize(16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
        int bufferSize = 16 * minBufferSize;
        audioRecord = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
        audioRecord.startRecording();
    }
    callbacks.add(callback);
    if (!inited) {
        inited = true;
        schedule(new Check(), delay);
    }
}
Also used : AudioRecord(android.media.AudioRecord)

Example 30 with AudioRecord

use of android.media.AudioRecord in project actor-platform by actorapp.

the class VoiceCaptureActor method onStartMessage.

protected void onStartMessage(String fileName) {
    if (state == STATE_STARTED) {
        return;
    }
    int minBufferSize = AudioRecord.getMinBufferSize(16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
    bufferSize = 16 * minBufferSize;
    audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
    audioRecord.startRecording();
    opusActor = system().actorOf(Props.create(new ActorCreator() {

        @Override
        public OpusEncoderActor create() {
            return new OpusEncoderActor();
        }
    }), "actor/opus_encoder");
    opusActor.send(new OpusEncoderActor.Start(fileName));
    state = STATE_STARTED;
    playStartTime = SystemClock.uptimeMillis();
    vibrate(context);
    self().send(new Iterate());
}
Also used : AudioRecord(android.media.AudioRecord) ActorCreator(im.actor.runtime.actors.ActorCreator)

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