#include "alsa_output.h"
#include <alsa/asoundlib.h>
+#include <alsa/error.h>
+#include <alsa/pcm.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
{
if (err < 0) {
fprintf(stderr, "%s: %s\n", func_name, snd_strerror(err));
- exit(1);
+ abort();
}
}
die_on_error("snd_pcm_hw_params_set_rate()", snd_pcm_hw_params_set_rate(pcm_handle, hw_params, sample_rate, 0));
die_on_error("snd_pcm_hw_params_set_channels", snd_pcm_hw_params_set_channels(pcm_handle, hw_params, num_channels));
- // Fragment size of 512 samples. (A frame at 60 fps/48 kHz is 800 samples.)
- // We ask for 16 such periods (~170 ms buffer).
- unsigned int num_periods = 16;
+ // Fragment size of 2048 samples. (A frame at 60 fps/48 kHz is 800 samples.)
+ // We ask for 4 such periods (~170 ms buffer).
+ unsigned int num_periods = 4;
int dir = 0;
die_on_error("snd_pcm_hw_params_set_periods_near()", snd_pcm_hw_params_set_periods_near(pcm_handle, hw_params, &num_periods, &dir));
- period_size = 512;
+ period_size = 2048;
dir = 0;
die_on_error("snd_pcm_hw_params_set_period_size_near()", snd_pcm_hw_params_set_period_size_near(pcm_handle, hw_params, &period_size, &dir));
die_on_error("snd_pcm_hw_params()", snd_pcm_hw_params(pcm_handle, hw_params));
ret = 0;
} else if (ret < 0) {
fprintf(stderr, "error: snd_pcm_writei() returned '%s'\n", snd_strerror(ret));
- exit(1);
+ abort();
} else if (ret > 0) {
buffer.erase(buffer.begin(), buffer.begin() + ret * num_channels);
}