Loading...
Searching...
No Matches
SoundRecorder.h File Reference
#include <SFML/Audio/Export.h>
#include <SFML/Audio/Types.h>
#include <SFML/System/Time.h>
#include <stddef.h>

Go to the source code of this file.

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

sfSoundRecordersfSoundRecorder_create (sfSoundRecorderStartCallback onStart, sfSoundRecorderProcessCallback onProcess, sfSoundRecorderStopCallback onStop, void *userData)
 Construct a new sound recorder from callback functions.
 
void sfSoundRecorder_destroy (sfSoundRecorder *soundRecorder)
 Destroy a sound recorder.
 
sfBool sfSoundRecorder_start (sfSoundRecorder *soundRecorder, unsigned int sampleRate)
 Start the capture of a sound recorder.
 
void sfSoundRecorder_stop (sfSoundRecorder *soundRecorder)
 Stop the capture of a sound recorder.
 
unsigned int sfSoundRecorder_getSampleRate (const sfSoundRecorder *soundRecorder)
 Get the sample rate of a sound recorder.
 
sfBool sfSoundRecorder_isAvailable (void)
 Check if the system supports audio capture.
 
void sfSoundRecorder_setProcessingInterval (sfSoundRecorder *soundRecorder, sfTime interval)
 Set the processing interval.
 
const char ** sfSoundRecorder_getAvailableDevices (size_t *count)
 Get a list of the names of all available audio capture devices.
 
const char * sfSoundRecorder_getDefaultDevice (void)
 Get the name of the default audio capture device.
 
sfBool sfSoundRecorder_setDevice (sfSoundRecorder *soundRecorder, const char *name)
 Set the audio capture device.
 
const char * sfSoundRecorder_getDevice (sfSoundRecorder *soundRecorder)
 Get 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.
 
unsigned int sfSoundRecorder_getChannelCount (const sfSoundRecorder *soundRecorder)
 Get the number of channels used by this recorder.
 

Typedef Documentation

◆ sfSoundRecorderProcessCallback

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

Type of the callback used to process audio data.

Definition at line 38 of file SoundRecorder.h.

◆ sfSoundRecorderStartCallback

typedef sfBool(* sfSoundRecorderStartCallback) (void *)

Type of the callback used when starting a capture.

Definition at line 37 of file SoundRecorder.h.

◆ sfSoundRecorderStopCallback

typedef void(* sfSoundRecorderStopCallback) (void *)

Type of the callback used when stopping a capture.

Definition at line 39 of file SoundRecorder.h.

Function Documentation

◆ sfSoundRecorder_create()

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

Construct a new sound recorder from callback functions.

Parameters
onStartCallback function which will be called when a new capture starts (can be NULL)
onProcessCallback function which will be called each time there's audio data to process
onStopCallback function which will be called when the current capture stops (can be NULL)
userDataData to pass to the callback function (can be NULL)
Returns
A new sfSoundRecorder object (NULL if failed)

◆ sfSoundRecorder_destroy()

void sfSoundRecorder_destroy ( sfSoundRecorder soundRecorder)

Destroy a sound recorder.

Parameters
soundRecorderSound recorder to destroy

◆ sfSoundRecorder_getAvailableDevices()

const char ** sfSoundRecorder_getAvailableDevices ( size_t *  count)

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

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

Parameters
countPointer to a variable that will be filled with the number of modes in the array
Returns
An array of strings containing the names

◆ sfSoundRecorder_getChannelCount()

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).

Returns
Number of channels
See also
sfSoundRecorder_setChannelCount

◆ sfSoundRecorder_getDefaultDevice()

const char * sfSoundRecorder_getDefaultDevice ( void  )

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)

◆ sfSoundRecorder_getDevice()

const char * sfSoundRecorder_getDevice ( sfSoundRecorder soundRecorder)

Get the name of the current audio capture device.

Parameters
soundRecorderSound recorder object
Returns
The name of the current audio capture device

◆ sfSoundRecorder_getSampleRate()

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
soundRecorderSound recorder object
Returns
Sample rate, in samples per second

◆ sfSoundRecorder_isAvailable()

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

◆ sfSoundRecorder_setChannelCount()

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.

Parameters
channelCountNumber of channels. Currently only mono (1) and stereo (2) are supported.
See also
sfSoundRecorder_getChannelCount

◆ sfSoundRecorder_setDevice()

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
soundRecorderSound recorder object
nameThe name of the audio capture device
Returns
sfTrue, if it was able to set the requested device

◆ sfSoundRecorder_setProcessingInterval()

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
soundRecorderSound recorder object
intervalProcessing interval

◆ sfSoundRecorder_start()

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
soundRecorderSound recorder object
sampleRateDesired capture rate, in number of samples per second
Returns
True, if start of capture was successful

◆ sfSoundRecorder_stop()

void sfSoundRecorder_stop ( sfSoundRecorder soundRecorder)

Stop the capture of a sound recorder.

Parameters
soundRecorderSound recorder object