Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This tiny demo sends random samples to your speakers.
- */
- #include <tinyalsa/asoundlib.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #define RATE 44100
- struct pcm *dev;
- struct pcm_config cfg;
- unsigned char buffer[1024]; /* some random data */
- int main(void)
- {
- int err;
- unsigned int i;
- for (i = 0; i < sizeof(buffer); i++) buffer[i] = rand() & 0xff;
- // Set config values, drawing info from:
- // pactl list short sinks
- // 0 alsa_output.pci-0000_00_03.0.hdmi-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
- // 1 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
- cfg.channels = 2;
- cfg.rate = RATE;
- cfg.period_size = 4;
- cfg.period_count = RATE; // 1 sec
- cfg.format = PCM_FORMAT_S16_LE;
- cfg.start_threshold = 0;
- cfg.stop_threshold = 0;
- cfg.silence_threshold = 0;
- printf("errno %d\n", errno); // 0
- dev = pcm_open(1, 0, PCM_OUT, &cfg);
- printf("errno %d\n", errno); // 22
- err = pcm_start(dev);
- printf("errno %d\n", errno); // 9
- err = pcm_write(dev, &buffer, 1024);
- printf("errno %d\n", errno); // 9
- err = pcm_close(dev);
- printf("errno %d\n", errno); // 9
- return 0;
- }
Add Comment
Please, Sign In to add comment