Recording audio data

You can record audio content in mm-renderer by attaching the input to an audio capture device and directing the output to a file instead of a device.

The following sample program shows how to give mm-renderer an input URL of type snd: to select and configure an audio capture device (microphone), set an output URL type of file: to target a file, and then start and stop playback to record captured audio content to the targetted file. The snd: input URL format works only with the file: output type, so your code must obey this design.

You can record audio content for as long as you like, but you must ensure your client application's output file can hold all the content you want to capture. The size of the generated output depends on many settings, including the sampling rate and number of channels. This sample program records in mono by specifying one channel (nchan=1) in the input URL. Depending on your platform, your microphone device might have two recorders, so you could record in stereo by setting two channels (nchan=2). You could also increase the sampling rate to attain the necessary audio quality, such as using the standard CD sampling rate of 44.1 MHz (frate=44100000). For more information on the available device options, see the list of URL parameters for audio capture devices.

This code sample names an AMR file for the output, but mm-renderer supports other formats, such as wideband AMR (see the list of supported output file formats).

void record_AMR_file() 
  mmr_connection_t *connection;
  mmr_context_t *context;
  const char* context_name = "AnyNameYouWant";
  int output = 0;
  const char* outputFile = "/tmp/testFile.amr";
  int input = 0;

  connection = mmr_connect(NULL);

  if (connection) {
      context = mmr_context_create( connection, 
                                    S_IRWXU );

      if (context) {
          // specify a file output so the audio content is 
          // not played but recorded in a file
          output = mmr_output_attach( context,
                                      "file" );
          // specify the audio device under /dev/snd you want to 
          // use for the recording, and the recording details 
          // (in this case, we use a sampling rate of 8000 Hz and 
          // 1 channel for mono (not stereo) recording)
          input = mmr_input_attach( context,
                                   "track" );

          // start recording

          // delay for the length of time you want to record 
          // (in this case, 30 seconds)

          // stop recording
          // clean up the context
          mmr_output_detach(context, output); 
  } // if (connection)
} // function