Recording audio content
You can record audio content by attaching an audio capture device (microphone) as the input and a file (instead of a device) as the output.
[plugin]
dll=mmr-mmfrip-routing.so
To ensure the plugin is loaded, this configuration must be defined when you launch mm-renderer.
The following example shows how to give mm-renderer an output URL of type file: to target a file, and an input URL of type snd: to select and configure a microphone, and then start and stop recording captured audio content to the targeted file. An snd: input URL targeting a microphone works only with the file output type, so your code must obey this design.
/* Code to connect to mm-renderer and create a context goes here
(see "Playing audio content" for an example of doing this) */
const mmr_error_info_t* errorInfo;
// Specify a file output so the audio content is recorded to a file
const char* outputPath = "file:/tmp/testFile.amr";
int outputID = mmr_output_attach( ctxt_audiorec, outputPath, "file" );
if (outputID == -1) {
errorInfo = mmr_error_info(ctxt_audiorec);
/* Remaining error-handling code goes here */
return EXIT_FAILURE;
}
- Waveform Audio File Format (.wav)
- Advanced Audio Coding (.aac)
- MPEG-4 Part 14 (MP4) containing only AAC audio (.mp4, .m4a, .m4v, .mov)
- MPEG-2 Transport Stream files containing only AAC audio (.ts)
- Adaptive Multi-Rate Narrow Band and Wide Band (.amr, .awb)
- 3GPP file format (.3gp)
// Specify which audio device under /dev/snd you want to use for
// recording and the recording details, in the input URL
int inputID = mmr_input_attach( ctxt_audiorec,
"snd:/dev/snd/pcmPreferredc?nchan=1&frate=8000",
"track" );
if (inputID == -1) {
/* Error-handling code goes here */
return EXIT_FAILURE;
}
- frate — the sampling rate, in Hertz
- frag_ms — the fragment size, in milliseconds
- nchan — the number of channels (1 for mono, 2 for stereo)
- depth — the number of bits per sample (e.g., 16)
- bsize — the preferred read size, in bytes
With the output and input attached, we can define output parameters; there are no input parameters for audio capture devices.
For file outputs, mm-renderer supports the audio_fourcc and
audio_bitrate parameters, to select an encoder and enable compression.
For more details, see Parameters that affect how the output is delivered
.
if ( mmr_play(ctxt_audiorec) < 0 ) {
/* Error-handling code goes here */
}
sleep(30); // Delay for the length of time you want to record
if ( mmr_stop(ctxt_audiorec) < 0 ) {
/* Error-handling code goes here */
}
