examples

Toy examples in single C files.
git clone git://henryandlizzy.uk/examples
Log | Files | Refs

pulse-simple-client.c (677B)


      1 #include <pulse/simple.h>
      2 #include <stdio.h>
      3 #include <math.h>
      4 
      5 
      6 int main(int, char* argv[])
      7 {
      8 	pa_sample_spec ss = {
      9 		.format = PA_SAMPLE_S16NE,
     10 		.channels = 1,
     11 		.rate = 44100,
     12 	};
     13 
     14 	pa_simple* s = pa_simple_new(
     15 		NULL,
     16 		argv[0],
     17 		PA_STREAM_PLAYBACK,
     18 		NULL,
     19 		"Music",
     20 		&ss,
     21 		NULL,
     22 		NULL,
     23 		NULL);
     24 
     25 	if (!s)
     26 		perror("pa_simple_new");
     27 
     28 #define BUF_LEN (44100 / 200)
     29 #define pi 3.1415
     30 #define tau (2*pi)
     31 
     32 	signed short buf[BUF_LEN];
     33 
     34 	for (unsigned i = 0; i < BUF_LEN; ++i)
     35 	{
     36 		double t = i * tau / BUF_LEN;
     37 		buf[i] = sin(t) * (1 << 15);
     38 	}
     39 	for (unsigned i = 0; i < 400; ++i)
     40 	{
     41 		if (pa_simple_write(s, buf, sizeof(buf), NULL))
     42 			perror("pa_simple_write");
     43 	}
     44 }