PulseAudio  16.0
Sample Cache


The sample cache provides a simple way of overcoming high network latencies and reducing bandwidth. Instead of streaming a sound precisely when it should be played, it is stored on the server and only the command to start playing it needs to be sent.


To create a sample, the normal stream API is used (see Audio Streams). The function pa_stream_connect_upload() will make sure the stream is stored as a sample on the server.

To complete the upload, pa_stream_finish_upload() is called and the sample will receive the same name as the stream. If the upload should be aborted, simply call pa_stream_disconnect().

Playing samples

To play back a sample, simply call pa_context_play_sample():

o = pa_context_play_sample(my_context,
"sample2", // Name of my sample
NULL, // Use default sink
PA_VOLUME_NORM, // Full volume
NULL, // Don't need a callback
if (o)
struct pa_operation pa_operation
An asynchronous operation object.
Definition: operation.h:33
void pa_operation_unref(pa_operation *o)
Decrease the reference count by one.
pa_operation * pa_context_play_sample(pa_context *c, const char *name, const char *dev, pa_volume_t volume, pa_context_success_cb_t cb, void *userdata)
Play a sample from the sample cache to the specified device.
Normal volume (100%, 0 dB)
Definition: volume.h:120

Removing samples

When a sample is no longer needed, it should be removed on the server to save resources. The sample is deleted using pa_context_remove_sample().