# PulseAudio Source: [https://docs.qualcomm.com/doc/80-70014-16/topic/pulseaudio.html](https://docs.qualcomm.com/doc/80-70014-16/topic/pulseaudio.html) PulseAudio is a general purpose sound server intended to run as middleware between applications and hardware devices. Source code for PulseAudio is located at build-qcom-wayland/workspace/sources/pulseaudio/opensource/pulseaudio. Some of the frequently used PulseAudio APIs are described below. See the [open source PulseAudio documentation](https://freedesktop.org/software/pulseaudio/doxygen/index.html) for a complete description of all APIs . ## pa\_stream\_new Creates a new, unconnected stream with the specified name and sample type. pa_stream* pa_stream_new ( pa_context * c, const char *name, const pa_sample_spec * ss, const pa_channel_map *map) Copy to clipboard **Parameter** | c | Context in which to create the stream | | --- | --- | | name | Name of the stream name | | ss | Sample format | | map | Channel map, or NULL for default | **Return value** [**pa\_stream**](https://freedesktop.org/software/pulseaudio/doxygen/stream_8h.html#a960d798980692a2ff01e5a70553d4f29)\* handle ## pa\_stream\_get\_state Returns the current state of the stream. pa_stream_state_t pa_stream_get_state( const pa_stream *p) Copy to clipboard **Parameters** | p | pa\_stream handle | | --- | --- | **Return value** Returns the [**pa\_stream\_state\_t**](https://freedesktop.org/software/pulseaudio/doxygen/def_8h.html#a750e398d2ce663b858c87d8aa2f81eaa) ## pa\_stream\_get\_device\_name Returns the name of the sink or source this stream is connected to in the server. const char* pa_stream_get_device_name(const pa_stream *s) Copy to clipboard **Parameters** | s | pa\_stream handle | | --- | --- | **Return value** Name of the device ## pa\_stream\_connect\_playback Connects the stream to a sink. int pa_stream_connect_playback ( pa_stream * s, const char * dev, const pa_buffer_attr *attr, pa_stream_flags_t flags, const pa_cvolume *volume, pa_stream *sync_stream) Copy to clipboard **Parameter** | s | Stream to connect to a sink | | --- | --- | | dev | Name of the sink to connect to, or NULL to let the server
decide | | attr | Buffering attributes, or NULL for default | | flags | Additional flags, or 0 for default | | volume | Initial volume, or NULL for default | | sync\_stream | Synchronizes this stream with the specified one, or NULL for a
standalone stream | **Return value** Returns zero on success. ## pa\_stream\_connect\_record Connects the stream to a source. int pa_stream_connect_record( pa_stream *s, const char * dev, const pa_buffer_attr * attr, pa_stream_flags_t flags) Copy to clipboard **Parameters** | s | Stream to connect to a source | | --- | --- | | dev | Name of the source to connect to, or NULL to let the server
decide | | attr | Buffer attributes, or NULL for default | | flags | Additional flags, or 0 for default | **Return value** Returns zero on success. ## pa\_stream\_write Writes data to the server (for playback streams). int pa_stream_write( pa_stream * p, const void * data, size_t nbytes, pa_free_cb_t free_cb, int64_t offset, pa_seek_mode_t seek) Copy to clipboard **Parameters** | p | Stream to use | | --- | --- | | data | Data to write | | nbytes | Length of the data to write in bytes. Must be in multiples of the
stream's sample spec frame size. | | free\_cb | Clean-up routine for the data, or NULL to request an internal
copy | | offset | Offset for seeking. Must be 0 for upload streams. Must be in
multiples of the stream's sample spec frame size. | | seek | Seek mode. Must be PA\_SEEK\_RELATIVE for upload streams. | **Return value** Returns zero on success. ## pa\_stream\_set\_write\_callback Sets the callback function that is called when new data may be written to the stream. void pa_stream_set_write_callback( pa_stream * p, pa_stream_request_cb_t cb, void *userdata) Copy to clipboard **Parameters** | p | The stream to use | | --- | --- | | cb | Callback function to be set | | userdata | User data to be sent to callback | **Return value** None ## pa\_stream\_set\_read\_callback Sets the callback function that is called when new data is available from the stream. void pa_stream_set_read_callback( pa_stream * p, pa_stream_request_cb_t cb, void *userdata) Copy to clipboard **Parameters** | p | Stream to use | | --- | --- | | cb | Callback function to be set | | userdata | User data to be sent to callback | **Return value** None ## pa\_stream\_disconnect Disconnects a stream from a source/sink. int pa_stream_disconnect(pa_stream *s)Copy to clipboard **Parameters** | s | pa\_stream handle | | --- | --- | **Return value** Returns zero on success. For more information, see the [PulseAudio API](https://freedesktop.org/software/pulseaudio/doxygen/stream_8h.html) documentation. ## PulseAudio-based applications The `PAREC` application captures audio from the PulseAudio level. For example: ssh root@ip-addr setenforce 0 #pactl set-source-port regular2 handset-mic #parec -v --rate=48000 --format=s16le --channels=1 --file-format=wav /opt/ test.wav --device=regular2 Copy to clipboard Supported formats are `s16le`, `s24le`, `s32le`, `s24-32le`. The rate can be `8000`, `16000`, `22050`, `24000`, `32000`, `44100`, `48000`, `88200`, `96000`, `17640`, `19200`, `35280`, and `38400`. This example captures 48 kHz, 16-bit mono audio from a regular source and saves it as a wav file at /opt/test.wav. The `paplay` application plays audio from the PulseAudio level. To perform playback, the wav file can be pushed to the device using the following command: scp test.wav root@[ip-addr]:/data/Copy to clipboard For example: setenforce 0 #paplay /opt/test.wav -vCopy to clipboard This example plays the audio file /opt/test.wav with all default configurations. **Parent Topic:** [APIs and Sample Apps](https://docs.qualcomm.com/doc/80-70014-16/topic/apis_and_sample_apps.html) Last Published: Jul 15, 2024 [Previous Topic GStreamer](https://docs.qualcomm.com/bundle/publicresource/80-70014-16/topics/gstreamer.md) [Next Topic Platform Adaptation Layer (PAL)](https://docs.qualcomm.com/bundle/publicresource/80-70014-16/topics/platform_adaptation_layer_pal.md)