Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void startRecording(){
- int recordingBufferSize = AudioRecord.getMinBufferSize(AUDIO_SAMPLE_FREQUENCY_Hz, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT) * 4;
- if (mAudioFile.exists())// Delete any previous recording.
- mAudioFile.delete();
- try {
- mAudioFile.createNewFile();
- } catch (IOException e) {
- throw new IllegalStateException("Failed to create " + mAudioFile.toString());
- }
- try {
- // Create a new AudioRecord object to record the audio.
- audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
- AUDIO_SAMPLE_FREQUENCY_Hz, AudioFormat.CHANNEL_CONFIGURATION_STEREO,
- AudioFormat.ENCODING_PCM_16BIT, recordingBufferSize);
- audioRecord.startRecording();
- FileOutputStream fos = new FileOutputStream(mAudioFile);
- FileChannel fchannel = fos.getChannel();
- ByteBuffer recordingBuffer = ByteBuffer.allocateDirect(recordingBufferSize);
- recordingBuffer.order(ByteOrder.LITTLE_ENDIAN);
- //Log.w("SoundTouchJNI", "Native Byte Order is "+ sampleBuffer.order());
- while (isRecording) {
- int bufferReadResult = audioRecord.read(recordingBuffer, recordingBufferSize);
- Log.w("SoundTouchJNI", "Writing bytes "+ String.valueOf(bufferReadResult));
- fchannel.write(recordingBuffer);
- recordingBuffer.rewind();
- }
- fchannel.close();
- audioRecord.stop();
- fos.close();
- }catch (Throwable t) {
- Log.e("AudioRecord","---------------- " + t.getMessage());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement