Audio Output
C Quick Start
Platforms
- Linux (x86_64)
- macOS (x86_64, arm64)
- Windows (x86_64)
- Raspberry Pi (3, 4, 5)
Requirements
- CMake 3.4+.
- C99 compatible compiler.
- Windows: MinGW.
Quick Start
Setup
Include the public header files (pv_speaker.h
and pv_circular_buffer.h
).
Usage
- Create a PvSpeaker object:
- Start the audio output device:
- Write PCM data to the speaker:
Note: the pv_speaker_write()
method only writes as much PCM data as the internal circular buffer can currently fit, and returns the number of samples that were successfully written via written_length
.
- When all frames have been written, call
pv_speaker_flush()
to wait for all buffered PCM (i.e. previously buffered viapv_speaker_write()
) to be played:
Note: calling pv_speaker_flush()
with a pcm
pointer to actual PCM data (and corresponding num_samples
) will both write that PCM data and wait for all buffered PCM data to finish.
- Stop the audio output device:
- Release resources used by PvSpeaker:
Selecting an Audio Device
To print a list of available audio devices:
The index of the device in the returned list can be used in pv_speaker_init()
to select that device for playing.
Demo
For the PvSpeaker C SDK, we offer a demo application that demonstrates how to use PvSpeaker to play audio from an audio file (.wav
).
Setup
- Clone the repository:
- Build the project:
The {PV_SPEAKER_PLATFORM}
variable will set the compilation flags for the given platform. Exclude this variable to get a list of possible values.
Usage
To see the usage options for the demo:
Get a list of available audio playback devices:
Play a file with a given audio device index:
Hit Ctrl+C
if you wish to stop playing audio before it completes. If no audio device index (-d
) is provided, the demo will use the system's default audio player device.
For more information about our PvSpeaker demo, head over to our GitHub repository.