Search in sources :

Example 11 with AudioRecord

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);
}
Also used : AudioRecord(android.media.AudioRecord) AssetFileDescriptor(android.content.res.AssetFileDescriptor) AudioEffect(android.media.audiofx.AudioEffect) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 12 with AudioRecord

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;
}
Also used : AudioRecord(android.media.AudioRecord)

Example 13 with AudioRecord

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;
}
Also used : AudioRecord(android.media.AudioRecord)

Example 14 with AudioRecord

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
    }
}
Also used : AudioRecord(android.media.AudioRecord)

Example 15 with AudioRecord

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();
    }
}
Also used : AudioRecord(android.media.AudioRecord)

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