SoundRecorder#

Typedefs

typedef sfBool (*sfSoundRecorderStartCallback)(void*)#

Type of the callback used when starting a capture.

typedef sfBool (*sfSoundRecorderProcessCallback)(const sfInt16*, size_t, void*)#

Type of the callback used to process audio data.

typedef void (*sfSoundRecorderStopCallback)(void*)#

Type of the callback used when stopping a capture.

Functions

sfSoundRecorder *sfSoundRecorder_create(sfSoundRecorderStartCallback onStart, sfSoundRecorderProcessCallback onProcess, sfSoundRecorderStopCallback onStop, void *userData)#

Construct a new sound recorder from callback functions.

Parameters:
  • onStart – Callback function which will be called when a new capture starts (can be NULL)

  • onProcess – Callback function which will be called each time there’s audio data to process

  • onStop – Callback function which will be called when the current capture stops (can be NULL)

  • userData – Data to pass to the callback function (can be NULL)

Returns:

A new sfSoundRecorder object (NULL if failed)

void sfSoundRecorder_destroy(sfSoundRecorder *soundRecorder)#

Destroy a sound recorder.

Parameters:
  • soundRecorder – Sound recorder to destroy

sfBool sfSoundRecorder_start(sfSoundRecorder *soundRecorder, unsigned int sampleRate)#

Start the capture of a sound recorder.

The sampleRate parameter defines the number of audio samples captured per second. The higher, the better the quality (for example, 44100 samples/sec is CD quality). This function uses its own thread so that it doesn’t block the rest of the program while the capture runs. Please note that only one capture can happen at the same time.

Parameters:
  • soundRecorder – Sound recorder object

  • sampleRate – Desired capture rate, in number of samples per second

Returns:

True, if start of capture was successful

void sfSoundRecorder_stop(sfSoundRecorder *soundRecorder)#

Stop the capture of a sound recorder.

Parameters:
  • soundRecorder – Sound recorder object

unsigned int sfSoundRecorder_getSampleRate(const sfSoundRecorder *soundRecorder)#

Get the sample rate of a sound recorder.

The sample rate defines the number of audio samples captured per second. The higher, the better the quality (for example, 44100 samples/sec is CD quality).

Parameters:
  • soundRecorder – Sound recorder object

Returns:

Sample rate, in samples per second

sfBool sfSoundRecorder_isAvailable(void)#

Check if the system supports audio capture.

This function should always be called before using the audio capture features. If it returns false, then any attempt to use sfSoundRecorder will fail.

Returns:

sfTrue if audio capture is supported, sfFalse otherwise

void sfSoundRecorder_setProcessingInterval(sfSoundRecorder *soundRecorder, sfTime interval)#

Set the processing interval.

The processing interval controls the period between calls to the onProcessSamples function. You may want to use a small interval if you want to process the recorded data in real time, for example.

Note: this is only a hint, the actual period may vary. So don’t rely on this parameter to implement precise timing.

The default processing interval is 100 ms.

Parameters:
  • soundRecorder – Sound recorder object

  • interval – Processing interval

const char **sfSoundRecorder_getAvailableDevices(size_t *count)#

Get a list of the names of all availabe audio capture devices.

This function returns an array of strings (null terminated), containing the names of all availabe audio capture devices. If no devices are available then NULL is returned.

Parameters:
  • count – Pointer to a variable that will be filled with the number of modes in the array

Returns:

An array of strings containing the names

const char *sfSoundRecorder_getDefaultDevice()#

Get the name of the default audio capture device.

This function returns the name of the default audio capture device. If none is available, NULL is returned.

Returns:

The name of the default audio capture device (null terminated)

sfBool sfSoundRecorder_setDevice(sfSoundRecorder *soundRecorder, const char *name)#

Set the audio capture device.

This function sets the audio capture device to the device with the given name. It can be called on the fly (i.e: while recording). If you do so while recording and opening the device fails, it stops the recording.

Parameters:
  • soundRecorder – Sound recorder object

  • name – The name of the audio capture device

Returns:

sfTrue, if it was able to set the requested device

const char *sfSoundRecorder_getDevice(sfSoundRecorder *soundRecorder)#

Get the name of the current audio capture device.

Parameters:
  • soundRecorder – Sound recorder object

Returns:

The name of the current audio capture device

void sfSoundRecorder_setChannelCount(sfSoundRecorder *soundRecorder, unsigned int channelCount)#

Set the channel count of the audio capture device.

This method allows you to specify the number of channels used for recording. Currently only 16-bit mono and 16-bit stereo are supported.

See also

sfSoundRecorder_getChannelCount

Parameters:
  • channelCount – Number of channels. Currently only mono (1) and stereo (2) are supported.

unsigned int sfSoundRecorder_getChannelCount(const sfSoundRecorder *soundRecorder)#

Get the number of channels used by this recorder.

Currently only mono and stereo are supported, so the value is either 1 (for mono) or 2 (for stereo).

See also

sfSoundRecorder_setChannelCount

Returns:

Number of channels