use of android.media.AudioRecord in project android_frameworks_base by crdroidandroid.
the class MediaAudioEffectTest method getAudioRecord.
//-----------------------------------------------------------------
// 1 - constructor
//----------------------------------
private AudioRecord getAudioRecord() {
AudioRecord ar = null;
try {
ar = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, SAMPLING_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(SAMPLING_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 10);
assertNotNull("Could not create AudioRecord", ar);
assertEquals("AudioRecord not initialized", AudioRecord.STATE_INITIALIZED, ar.getState());
} catch (IllegalArgumentException e) {
fail("AudioRecord invalid parameter");
}
return ar;
}
use of android.media.AudioRecord in project android_frameworks_base by crdroidandroid.
the class MediaAudioEffectTest method test1_0ConstructorFromType.
//Test case 1.0: test constructor from effect type and get effect ID
@LargeTest
public void test1_0ConstructorFromType() throws Exception {
boolean result = true;
String msg = "test1_0ConstructorFromType()";
AudioEffect.Descriptor[] desc = AudioEffect.queryEffects();
assertTrue(msg + ": no effects found", (desc.length != 0));
try {
int sessionId;
AudioRecord ar = null;
if (AudioEffect.EFFECT_PRE_PROCESSING.equals(desc[0].connectMode)) {
ar = getAudioRecord();
sessionId = ar.getAudioSessionId();
} else {
sessionId = 0;
}
AudioEffect effect = new AudioEffect(desc[0].type, AudioEffect.EFFECT_TYPE_NULL, 0, sessionId);
assertNotNull(msg + ": could not create AudioEffect", effect);
try {
assertTrue(msg + ": invalid effect ID", (effect.getId() != 0));
} catch (IllegalStateException e) {
msg = msg.concat(": AudioEffect not initialized");
result = false;
} finally {
effect.release();
if (ar != null) {
ar.release();
}
}
} catch (IllegalArgumentException e) {
msg = msg.concat(": Effect not found: " + desc[0].name);
result = false;
} catch (UnsupportedOperationException e) {
msg = msg.concat(": Effect library not loaded");
result = false;
}
assertTrue(msg, result);
}
use of android.media.AudioRecord in project snips-platform-android-demo by snipsco.
the class MainActivity method runStreaming.
private void runStreaming() {
Log.d(TAG, "starting audio streaming");
final int minBufferSizeInBytes = AudioRecord.getMinBufferSize(FREQUENCY, CHANNEL, ENCODING);
Log.d(TAG, "minBufferSizeInBytes: " + minBufferSizeInBytes);
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, FREQUENCY, CHANNEL, ENCODING, minBufferSizeInBytes);
recorder.startRecording();
while (continueStreaming) {
short[] buffer = new short[minBufferSizeInBytes / 2];
recorder.read(buffer, 0, buffer.length);
if (client != null) {
client.sendAudioBuffer(buffer);
}
}
recorder.stop();
Log.d(TAG, "audio streaming stopped");
}
use of android.media.AudioRecord in project summer-android by cn-cerc.
the class AudioRecorderUtils method createDefaultAudio.
public void createDefaultAudio(String fileName) {
this.fileName = fileName;
this.status = Status.STATUS_READY;
// 获得缓冲区字节大小
bufferSizeInBytes = AudioRecord.getMinBufferSize(AUDIO_SAMPLE_RATE, AUDIO_CHANNEL, AUDIO_ENCODING);
audioRecord = new AudioRecord(AUDIO_INPUT, AUDIO_SAMPLE_RATE, AUDIO_CHANNEL, AUDIO_ENCODING, bufferSizeInBytes);
}
use of android.media.AudioRecord in project summer-android by cn-cerc.
the class AudioRecorderUtils method createAudio.
public void createAudio(String fileName, int audioSource, int sampleRateInHz, int channelConfig, int audioFormat) {
this.fileName = fileName;
// 获得缓冲区字节大小
bufferSizeInBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, channelConfig);
audioRecord = new AudioRecord(audioSource, sampleRateInHz, channelConfig, audioFormat, bufferSizeInBytes);
}
Aggregations