use of android.media.AudioRecord in project android_frameworks_base by crdroidandroid.
the class MediaAudioEffectTest method test1_1ConstructorFromUuid.
//Test case 1.1: test constructor from effect uuid
@LargeTest
public void test1_1ConstructorFromUuid() throws Exception {
boolean result = true;
String msg = "test1_1ConstructorFromUuid()";
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(AudioEffect.EFFECT_TYPE_NULL, desc[0].uuid, 0, sessionId);
assertNotNull(msg + ": could not create AudioEffect", effect);
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 android_frameworks_base by AOSPA.
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 natural-voice-mobile-sdk-android by aimmatic.
the class VoiceRecorder method createAudioRecord.
/**
* Creates a new {@link AudioRecord}.
*
* @return A newly created {@link AudioRecord}, or null if it cannot be created due to no permission
* or no microphone available.
*/
private AudioRecord createAudioRecord() {
for (int sampleRate : SAMPLE_RATE_CANDIDATES) {
final int sizeInBytes = AudioRecord.getMinBufferSize(sampleRate, CHANNEL, ENCODING);
if (sizeInBytes == AudioRecord.ERROR_BAD_VALUE) {
continue;
}
final AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, CHANNEL, ENCODING, sizeInBytes);
if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
if (encodingType == VOICE_ENCODE_AS_FLAC) {
// 1 CHANNEL mono
// 16 ENCODING_PCM_16BIT
this.samplreRate = sampleRate;
this.sizeInBytes = sizeInBytes;
}
return audioRecord;
} else {
audioRecord.release();
}
}
return null;
}
use of android.media.AudioRecord in project magstripereader by brandonlw.
the class MagstripeReaderActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_data = getString(R.string.data_default);
_SetText(false, _data);
try {
_bufferSize = AudioRecord.getMinBufferSize(_frequency, _channelConfig, _audioEncoding) * 8;
_audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC, _frequency, _channelConfig, _audioEncoding, _bufferSize);
} catch (Exception ex) {
// Do nothing
}
}
use of android.media.AudioRecord in project haven by guardianproject.
the class AudioCodec method start.
/**
* Configures the recorder and starts it
* @throws IOException
* @throws IllegalStateException
*/
public void start() throws IllegalStateException, IOException {
if (recorder == null) {
minSize = AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_DEFAULT, AudioFormat.ENCODING_PCM_16BIT);
Log.e("AudioCodec", "Minimum size is " + minSize);
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_IN_DEFAULT, AudioFormat.ENCODING_PCM_16BIT, minSize);
recorder.startRecording();
}
}
Aggregations