Skip to content

Recording pcm audio

Davis Silverman edited this page Sep 15, 2013 · 2 revisions

You can access PCM data from the microphone on a PC or Android phone via the AudioRecorder (code) interface. To create an instance of that interface use:

AudioRecorder recorder = Gdx.audio.newAudioRecorder(22050, true);

This will create an AudioRecorder with a sampling rate of 22.05khz, in mono mode. If the recorder couldn't be created, a GdxRuntimeException will be thrown.

Samples can be read as 16-bit signed PCM:

short[] shortPCM = new float[1024]; // 1024 samples
recorder.readSamples(shortPCM, 0, shortPCM.length);

Stereo samples are interleaved as usual (first sample -> left channel, second sample -> right channel).

An AudioRecorder is a native resource and needs to be disposed of if no longer in use:

recorder.dispose();

Audio recording is not supported in the JavaScript/WebGL backend.

Table of Contents

a note from the translation

Wiki Style Guide

Clone this wiki locally