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);
}
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);
}
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();
}
};
}
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);
}
}
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());
}
Aggregations