PvSpeaker
C API
API Reference for the PvSpeaker C SDK.
pv_speaker_t
Struct representing the PvSpeaker object.
pv_speaker_init()
Creates a PvSpeaker instance. When finished with the instance, resources should be cleaned up using the pv_speaker_delete() function.
Parameters
sample_rateint32_t : The sample rate of the audio to be played.bits_per_sampleint16_t : The number of bits per sample.buffer_size_secsint32_t : The size in seconds of the internal buffer used to buffer PCM data i.e. internal circular buffer will be of sizesample_rate*buffer_size_secs.device_indexint32_t : The index of the audio device to use. A value of (-1) will resort to default device.objectpv_speaker_t * * : PvSpeaker object to be initialized.
Returns
- pv_speaker_status_t : Returned status code.
pv_speaker_delete()
Releases resources acquired by PvSpeaker.
Parameters
objectpv_speaker_t * : PvSpeaker object.
pv_speaker_start()
Starts the audio output device. After starting, PCM data can be sent to the audio output device via pv_speaker_write() and/or pv_speaker_flush().
Parameters
objectpv_speaker_t * : PvSpeaker object.
Returns
- pv_speaker_status_t : Returned status code.
pv_speaker_stop()
Stops the audio output device.
Parameters
objectpv_speaker_t * : PvSpeaker object.
Returns
- pv_speaker_status_t : Returned status code.
pv_speaker_write()
Synchronous call to write PCM data to the internal circular buffer for audio playback. Only writes as much PCM data as the internal circular buffer can currently fit.
Parameters
objectpv_speaker_t * : PvSpeaker object.pcmint8_t * : Pointer to the PCM data that will be written.pcm_lengthint32_t * : Number of samples in the PCM data.written_lengthint32_t * : Number of samples that were successfully written. This value may be less than or equal topcm_length, depending on the current state of the internal circular buffer.
Returns
- pv_speaker_status_t : Returned status code.
pv_speaker_flush()
Synchronous call to write PCM data to the internal circular buffer for audio playback. This blocks the thread until all PCM data (including PCM data written in previous calls to pv_speaker_write()) have been successfully written and played.
To simply wait for PCM data written in previous calls to finish playing, call pv_speaker_flush() with pcm set to NULL and pcm_length set to 0.
Parameters
objectpv_speaker_t * : PvSpeaker object.pcmint8_t * : Pointer to the PCM data that will be written.pcm_lengthint32_t * : Number of samples in the PCM data.written_lengthint32_t * : Number of samples that were successfully written. This value should always matchpcm_length, unless an error occurred.
Returns
- pv_speaker_status_t : Returned status code.
pv_speaker_write_to_file()
Writes PCM data passed to PvSpeaker to a specified WAV file. The file will be ready after pv_speaker_stop() or pv_speaker_delete() has been called.
Parameters
objectpv_speaker_t * : PvSpeaker object.output_wav_pathconst char * : Path to the output WAV file where the PCM data will be written.
Returns
- pv_speaker_status_t : Returned status code.
pv_speaker_get_is_started()
Gets whether the given instance of pv_speaker_t has started and is available to receive PCM data.
Parameters
objectpv_speaker_t * : PvSpeaker object.
Returns
- bool : A boolean indicating whether PvSpeaker has started and is available to receive PCM data.
pv_speaker_get_selected_device()
Gets the audio device that the given pv_speaker_t instance is using.
Parameters
objectpv_speaker_t * : PvSpeaker object.
Returns
- const char * : A string containing the name of the device.
pv_speaker_get_available_devices()
Gets the list of available audio devices that can be used for playing audio. Free the returned device_list array using pv_speaker_free_available_devices().
Parameters
device_list_lengthint32_t * : The number of available audio devices.device_listchar * * * : The output array containing the list of available audio devices.
Returns
- pv_speaker_status_t : Returned status code.
pv_speaker_free_available_devices()
Frees the device list initialized by pv_speaker_get_available_devices().
Parameters
device_list_lengthint32_t : The number of audio devices.device_listchar * * : The array containing the list of audio devices.
pv_speaker_status_to_string()
Provides string representations of the given status code.
Parameters
statuspv_speaker_status_t : Status code.
Returns
- const char * : String representation of the status code.
pv_speaker_version()
Getter for the PvSpeaker version.
Returns
- const char * : Version string.
pv_speaker_status_t
Status code enum.