Created
July 10, 2022 22:23
-
-
Save felix-lipski/39e417cc8999c60a6500867735eccddc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
#include <alsa/asoundlib.h> | |
int main() { | |
snd_pcm_t *pcm; | |
snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, 0); | |
snd_pcm_hw_params_t *hw_params; | |
snd_pcm_hw_params_alloca(&hw_params); | |
snd_pcm_hw_params_any(pcm, hw_params); | |
snd_pcm_hw_params_set_access(pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); | |
snd_pcm_hw_params_set_format(pcm, hw_params, SND_PCM_FORMAT_S16_LE); | |
snd_pcm_hw_params_set_channels(pcm, hw_params, 1); | |
snd_pcm_hw_params_set_rate(pcm, hw_params, 48000, 0); | |
snd_pcm_hw_params_set_periods(pcm, hw_params, 10, 0); | |
snd_pcm_hw_params_set_period_time(pcm, hw_params, 100000, 0); // 0.1 seconds | |
snd_pcm_hw_params(pcm, hw_params); | |
short samples[48000] = {0}; | |
for (int i=0; i < 48000; i++) { | |
samples[i] = 10000 * sinf(2 * 3.14 * 200 * ((float)i / 48000)); | |
}; | |
snd_pcm_writei(pcm, samples, 48000); | |
snd_pcm_drain(pcm); | |
snd_pcm_close(pcm); | |
return 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment