Lines Matching defs:*
2 * This extra small demo sends a random samples to your speakers.
5 #include "../include/asoundlib.h"
7 static char *device = "default"; /* playback device */
9 snd_output_t *output = NULL;
10 unsigned char buffer[16*1024]; /* some random data */
12 int main(void)
14 int err;
15 unsigned int i;
16 snd_pcm_t *handle;
17 snd_pcm_sframes_t frames;
19 for (i = 0; i < sizeof(buffer); i++)
20 buffer[i] = random() & 0xff;
22 if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
23 printf("Playback open error: %s\n", snd_strerror(err));
24 exit(EXIT_FAILURE);
26 if ((err = snd_pcm_set_params(handle,
27 SND_PCM_FORMAT_U8,
28 SND_PCM_ACCESS_RW_INTERLEAVED,
29 1,
30 48000,
31 1,
32 500000)) < 0) { /* 0.5sec */
33 printf("Playback open error: %s\n", snd_strerror(err));
34 exit(EXIT_FAILURE);
37 for (i = 0; i < 16; i++) {
38 frames = snd_pcm_writei(handle, buffer, sizeof(buffer));
39 if (frames < 0)
40 frames = snd_pcm_recover(handle, frames, 0);
41 if (frames < 0) {
42 printf("snd_pcm_writei failed: %s\n", snd_strerror(err));
43 break;
45 if (frames > 0 && frames < (long)sizeof(buffer))
46 printf("Short write (expected %li, wrote %li)\n", (long)sizeof(buffer), frames);
49 snd_pcm_close(handle);
50 return 0;