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

Go to the source code of this file.

Typedefs

typedef bool(* sfSoundRecorderStartCallback) (void *)
 Type of the callback used when starting a capture.
 
typedef bool(* sfSoundRecorderProcessCallback) (const int16_t *, 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 (const sfSoundRecorder *soundRecorder)
 Destroy a sound recorder.
 
bool 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.
 
bool sfSoundRecorder_isAvailable (void)
 Check if the system supports audio capture.
 
const char *const * 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.
 
bool 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.
 
sfSoundChannelsfSoundRecorder_getChannelMap (const sfSoundRecorder *soundRecorder, size_t *count)
 Get the map of position in sample frame to sound channel.
 

Typedef Documentation

◆ sfSoundRecorderProcessCallback

typedef bool(* sfSoundRecorderProcessCallback) (const int16_t *, size_t, void *)

Type of the callback used to process audio data.

Definition at line 40 of file SoundRecorder.h.

◆ sfSoundRecorderStartCallback

typedef bool(* sfSoundRecorderStartCallback) (void *)

Type of the callback used when starting a capture.

Definition at line 39 of file SoundRecorder.h.

◆ sfSoundRecorderStopCallback

typedef void(* sfSoundRecorderStopCallback) (void *)

Type of the callback used when stopping a capture.

Definition at line 41 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 ( const sfSoundRecorder soundRecorder)

Destroy a sound recorder.

Parameters
soundRecorderSound recorder to destroy

◆ sfSoundRecorder_getAvailableDevices()

const char *const * 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_getChannelMap()

sfSoundChannel * sfSoundRecorder_getChannelMap ( const sfSoundRecorder soundRecorder,
size_t *  count 
)

Get the map of position in sample frame to sound channel.

This is used to map a sample in the sample stream to a position during spatialization.

Parameters
soundRecorderSound recorder object
countPointer to a variable that will be filled with the number of channels in the map
Returns
Map of position in sample frame to sound channel

◆ 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()

bool 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
true if audio capture is supported, false 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
soundRecorderSound recorder object
channelCountNumber of channels. Currently only mono (1) and stereo (2) are supported.
See also
sfSoundRecorder_getChannelCount

◆ sfSoundRecorder_setDevice()

bool 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
true, if it was able to set the requested device

◆ sfSoundRecorder_start()

bool 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