Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <alsa/asoundlib.h>
- #define CHECK(x) \
- if ((x) < 0) {\
- printf("Error in line %d", __LINE__);\
- fflush(stdout);\
- }
- int main() {
- int i;
- int err;
- int16_t buf[128];
- int rate = 44100;
- snd_pcm_t* playback_handle;
- snd_pcm_hw_params_t* hw_params;
- CHECK(snd_pcm_open(&playback_handle, "hw:0,0", SND_PCM_STREAM_PLAYBACK, 0));
- CHECK(snd_pcm_hw_params_malloc(&hw_params));
- CHECK(snd_pcm_hw_params_any(playback_handle, hw_params));
- CHECK(snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED));
- CHECK(snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_S16_LE));
- CHECK(snd_pcm_hw_params_set_rate_near(playback_handle, hw_params, &rate, 0));
- CHECK(snd_pcm_hw_params_set_channels(playback_handle, hw_params, 2));
- CHECK(snd_pcm_hw_params(playback_handle, hw_params));
- snd_pcm_hw_params_free(hw_params);
- CHECK(snd_pcm_prepare(playback_handle));
- for (i = 0; i < 1000; ++i) {
- if(snd_pcm_writei(playback_handle, buf, 128) != 128) {
- printf("Ooops, there was something wrong.\n");
- fflush(stdout);
- }
- }
- snd_pcm_close(playback_handle);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement