Game Development Reference
In-Depth Information
Exploring the AudioRecorder interface
The AudioRecorder interface allows you to record samples in a 16-bit PCM format
using a connected microphone. New instances of AudioRecorder can be requested
using LibGDX's Gdx.audio module and by calling its newAudioRecorder() method
as follows:
AudioRecorder audioRecordedr =
Gdx.audio.newAudioRecorder(44100, false);
Basically, AudioRecorder works nearly the same as AudioDevice except that it
captures samples. As always, the unused instances need to be disposed in order to
avoid memory leaks, as shown here:
audioRecorder.dispose(); // free allocated memory
To record samples with the audio recorder, all that is needed is an array into which
the captured samples will be stored:
void read(short[] samples, int offset, int numSamples);
The offset (start) and numSamples (length) parameters are used to define which
samples in the samples target array will be overwritten with new data.
Using sound generators
Until now, you learned about direct access to the audio device in LibGDX, and you
now know how to write audio samples to it. Sure enough, you could now (try to)
write your own sound generator class from here and feed one of LibGDX's audio
device instances with the resulting audio samples. However, audio programming is
beyond the scope of this topic, and it is also a very advanced topic even for seasoned
programmers.
A viable solution to get hold of some nice sound effects is to use one of the existing
sound generators, which are free and open source. One of these sound generators is
sfxr , which was originally developed by Tomas "DrPetter" Pettersson in 2007. Over
the time, several sfxr variants, such as bfxr , cfxr , and as3sfxr , have emerged.
 
Search WWH ::




Custom Search