// compilation: cc easypw_example.c -o easypw_example $(pkg-config --cflags --libs libpipewire-0.3) #include #define EASYPW_IMPLEMENTATION #include "easypw.h" #define NUM_SAMPLES 512 int main(void) { // initialize easypw // 2 channels, 48000Hz sampling rate and signed 16-bit samples struct easypw_ctx pw; easypw_init(&pw, 2, 48000, SPA_AUDIO_FORMAT_S16, NULL); // buffer for samples uint16_t pcm[NUM_SAMPLES]; // read raw PCM data from stdin and push samples to Pipewire // expects 2 channels, signed 16bit samples and 48000Hz rate size_t bytes_read; while ((bytes_read = fread(pcm, sizeof(pcm), 1, stdin)) > 0) { // break from loop if not running if (pw.running == false) break; // last argument is number of frames (= number of samples / channels) //easypw_push_frames(&pw, pcm, NUM_SAMPLES / 2); // this is simpler to use, number of frames calculation is made for user easypw_push_samples(&pw, pcm, NUM_SAMPLES); } // wait for playback thread to finnish sleep(1); // cleanup easypw_destroy(&pw); return 0; }