wip
This commit is contained in:
parent
5995b5e619
commit
592de3d5a9
34
src/beep.c
34
src/beep.c
|
@ -200,10 +200,11 @@ int beep_test(void)
|
||||||
* This extra small demo sends sinusoidal samples to your speakers.
|
* This extra small demo sends sinusoidal samples to your speakers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// https://www.raspberrypi.org/forums/viewtopic.php?t=84485&p=603451
|
||||||
|
|
||||||
static char *device = "hw:0,0"; /* playback device */
|
static char *device = "hw:0,0"; /* playback device */
|
||||||
snd_output_t *output = NULL;
|
snd_output_t *output = NULL;
|
||||||
|
|
||||||
|
|
||||||
int beep_test(void)
|
int beep_test(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -212,20 +213,6 @@ int beep_test(void)
|
||||||
snd_pcm_t *handle;
|
snd_pcm_t *handle;
|
||||||
snd_pcm_sframes_t frames;
|
snd_pcm_sframes_t frames;
|
||||||
|
|
||||||
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
|
|
||||||
printf("Playback open error: %s\n", snd_strerror(err));
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if ((err = snd_pcm_set_params(handle,
|
|
||||||
SND_PCM_FORMAT_S16_LE,
|
|
||||||
SND_PCM_ACCESS_RW_INTERLEAVED,
|
|
||||||
2,
|
|
||||||
48000,
|
|
||||||
1,
|
|
||||||
500000)) < 0) { /* 0.5sec */
|
|
||||||
printf("Playback open error: %s\n", snd_strerror(err));
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
f1 = 0.02;
|
f1 = 0.02;
|
||||||
f2 = 0.02;
|
f2 = 0.02;
|
||||||
|
@ -262,6 +249,23 @@ int beep(double freq_hz, double duration_sec)
|
||||||
}
|
}
|
||||||
int beep_init()
|
int beep_init()
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
|
||||||
|
printf("Playback open error: %s\n", snd_strerror(err));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if ((err = snd_pcm_set_params(handle,
|
||||||
|
SND_PCM_FORMAT_S16_LE,
|
||||||
|
SND_PCM_ACCESS_RW_INTERLEAVED,
|
||||||
|
2,
|
||||||
|
48000,
|
||||||
|
1,
|
||||||
|
500000)) < 0) { /* 0.5sec */
|
||||||
|
printf("Playback open error: %s\n", snd_strerror(err));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
int beep_close()
|
int beep_close()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue