summaryrefslogtreecommitdiff
path: root/audio_alsa.c
diff options
context:
space:
mode:
authorMike Brady <mikebrady@eircom.net>2018-11-08 14:43:52 +0000
committerMike Brady <mikebrady@eircom.net>2018-11-08 14:43:52 +0000
commite7f70fba328bdcc88994b1963c1e85ffaba29af7 (patch)
tree80a410aceeaa0d23a5aefe1d4f539f7e21934b5d /audio_alsa.c
parentcfd10647aad65314cbbde1ef5d959a57221d3090 (diff)
Tidy up with clang-format
Diffstat (limited to 'audio_alsa.c')
-rw-r--r--audio_alsa.c89
1 files changed, 46 insertions, 43 deletions
diff --git a/audio_alsa.c b/audio_alsa.c
index 815f342..0a03957 100644
--- a/audio_alsa.c
+++ b/audio_alsa.c
@@ -198,7 +198,6 @@ void do_snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *mix_elem, double v
static int init(int argc, char **argv) {
snd_output_stdio_attach(&output, stdout, 0);
-
// debug(2,"audio_alsa init called.");
int response = 0; // this will be what we return to the caller.
const char *str;
@@ -507,7 +506,6 @@ static int init(int argc, char **argv) {
static void deinit(void) {
// debug(2,"audio_alsa deinit called.");
stop();
-
}
int open_alsa_device(void) {
@@ -543,7 +541,7 @@ int open_alsa_device(void) {
snd_pcm_hw_params_alloca(&alsa_params);
snd_pcm_sw_params_alloca(&alsa_swparams);
-
+
ret = snd_pcm_hw_params_any(alsa_handle, alsa_params);
if (ret < 0) {
warn("audio_alsa: Broken configuration for device \"%s\": no configurations "
@@ -698,7 +696,7 @@ int open_alsa_device(void) {
snd_strerror(ret));
return -9;
}
-
+
ret = snd_pcm_sw_params_current(alsa_handle, alsa_swparams);
if (ret < 0) {
warn("audio_alsa: Unable to get current sw parameters for device \"%s\": %s.", alsa_out_dev,
@@ -712,15 +710,15 @@ int open_alsa_device(void) {
snd_strerror(ret));
return -11;
}
-
+
/* write the sw parameters */
ret = snd_pcm_sw_params(alsa_handle, alsa_swparams);
if (ret < 0) {
warn("audio_alsa: Unable to set software parameters of device: \"%s\": %s.", alsa_out_dev,
- snd_strerror(ret));
+ snd_strerror(ret));
return -12;
}
-
+
if (actual_buffer_length < config.audio_backend_buffer_desired_length + minimal_buffer_headroom) {
/*
// the dac buffer is too small, so let's try to set it
@@ -748,7 +746,7 @@ int open_alsa_device(void) {
"length (%ld) you have chosen.",
actual_buffer_length, config.audio_backend_buffer_desired_length);
}
-
+
if (alsa_characteristics_already_listed == 0) {
alsa_characteristics_already_listed = 1;
int log_level = 2; // the level at which debug information should be output
@@ -896,38 +894,40 @@ static void start(int i_sample_rate, int i_sample_format) {
measurement_data_is_valid = 0;
}
-int my_snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) {
- int ret;
+int my_snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) {
+ int ret;
snd_pcm_status_t *alsa_snd_pcm_status;
snd_pcm_status_alloca(&alsa_snd_pcm_status);
- struct timespec tn; // time now
- snd_htimestamp_t update_timestamp; //actually a struct timespec
+ struct timespec tn; // time now
+ snd_htimestamp_t update_timestamp; // actually a struct timespec
ret = snd_pcm_status(pcm, alsa_snd_pcm_status);
if (ret) {
*delayp = 0;
- return ret;
+ return ret;
}
-
+
snd_pcm_state_t state = snd_pcm_status_get_state(alsa_snd_pcm_status);
if (state != SND_PCM_STATE_RUNNING) {
*delayp = 0;
- return -EIO; // might be a better code than this...
+ return -EIO; // might be a better code than this...
}
-
+
clock_gettime(CLOCK_MONOTONIC, &tn);
snd_pcm_status_get_htstamp(alsa_snd_pcm_status, &update_timestamp);
-
- uint64_t t1 = tn.tv_sec * (uint64_t)1000000000 + tn.tv_nsec;
- uint64_t t2 = update_timestamp.tv_sec * (uint64_t)1000000000 + update_timestamp.tv_nsec;
+
+ uint64_t t1 = tn.tv_sec * (uint64_t)1000000000 + tn.tv_nsec;
+ uint64_t t2 = update_timestamp.tv_sec * (uint64_t)1000000000 + update_timestamp.tv_nsec;
uint64_t delta = t1 - t2;
-
- uint64_t frames_played_since_last_interrupt = ((uint64_t)desired_sample_rate * delta)/1000000000;
+
+ uint64_t frames_played_since_last_interrupt =
+ ((uint64_t)desired_sample_rate * delta) / 1000000000;
snd_pcm_sframes_t frames_played_since_last_interrupt_sized = frames_played_since_last_interrupt;
-
- *delayp = snd_pcm_status_get_delay(alsa_snd_pcm_status) - frames_played_since_last_interrupt_sized;
- return 0;
+
+ *delayp =
+ snd_pcm_status_get_delay(alsa_snd_pcm_status) - frames_played_since_last_interrupt_sized;
+ return 0;
}
int delay(long *the_delay) {
@@ -947,9 +947,9 @@ int delay(long *the_delay) {
debug(1, "Error %d in delay(): \"%s\". Delay reported is %d frames.", reply,
snd_strerror(reply), *the_delay);
derr = snd_pcm_recover(alsa_handle, reply, 1);
- if (derr < 0)
- warn("Error %d -- could not clear an error after attempting delay(): \"%s\".", derr,
- snd_strerror(derr));
+ if (derr < 0)
+ warn("Error %d -- could not clear an error after attempting delay(): \"%s\".", derr,
+ snd_strerror(derr));
frame_index = 0;
measurement_data_is_valid = 0;
@@ -977,9 +977,10 @@ int delay(long *the_delay) {
if ((derr = snd_pcm_prepare(alsa_handle))) {
debug(1, "Error preparing after delay error: \"%s\".", snd_strerror(derr));
derr = snd_pcm_recover(alsa_handle, derr, 1);
- if (derr < 0)
- warn("Error %d -- could not clear an error after attempting to recover following a delay(): \"%s\".", derr,
- snd_strerror(derr));
+ if (derr < 0)
+ warn("Error %d -- could not clear an error after attempting to recover following a "
+ "delay(): \"%s\".",
+ derr, snd_strerror(derr));
}
}
}
@@ -1028,10 +1029,10 @@ static int play(void *buf, int samples) {
if (snd_pcm_state(alsa_handle) == SND_PCM_STATE_XRUN) {
if ((err = snd_pcm_prepare(alsa_handle))) {
debug(1, "Error preparing after underrun: \"%s\".", snd_strerror(err));
- err = snd_pcm_recover(alsa_handle, err, 1);
- if (err < 0)
- warn("Error %d -- could not clear an error after detecting underrun in play(): \"%s\".", err,
- snd_strerror(err));
+ err = snd_pcm_recover(alsa_handle, err, 1);
+ if (err < 0)
+ warn("Error %d -- could not clear an error after detecting underrun in play(): \"%s\".",
+ err, snd_strerror(err));
}
frame_index = 0; // we'll be starting over
measurement_data_is_valid = 0;
@@ -1049,9 +1050,10 @@ static int play(void *buf, int samples) {
debug(1, "Error %d writing %d samples in play(): \"%s\".", err, samples,
snd_strerror(err));
err = snd_pcm_recover(alsa_handle, err, 1);
- if (err < 0)
- warn("Error %d -- could not clear an error after attempting to write %d samples in play(): \"%s\".", err, samples,
- snd_strerror(err));
+ if (err < 0)
+ warn("Error %d -- could not clear an error after attempting to write %d samples in "
+ "play(): \"%s\".",
+ err, samples, snd_strerror(err));
}
if (frame_index == 0) {
frames_sent_for_playing = samples;
@@ -1068,9 +1070,9 @@ static int play(void *buf, int samples) {
debug(1, "Error %d in delay in play(): \"%s\". Delay reported is %d frames.", err2,
snd_strerror(err2), fl);
err2 = snd_pcm_recover(alsa_handle, err2, 1);
- if (err2 < 0)
- warn("Error %d -- could not clear an error after checking delay in play(): \"%s\".", err2,
- snd_strerror(err2));
+ if (err2 < 0)
+ warn("Error %d -- could not clear an error after checking delay in play(): \"%s\".",
+ err2, snd_strerror(err2));
frame_index = 0;
measurement_data_is_valid = 0;
} else {
@@ -1097,9 +1099,10 @@ static int play(void *buf, int samples) {
if ((err = snd_pcm_prepare(alsa_handle))) {
debug(1, "Error preparing after play error: \"%s\".", snd_strerror(err));
err2 = snd_pcm_recover(alsa_handle, err, 1);
- if (err2 < 0)
- warn("Error %d -- could not clear an error after reporting ALSA device in incorrect state for play: \"%s\".", err2,
- snd_strerror(err2));
+ if (err2 < 0)
+ warn("Error %d -- could not clear an error after reporting ALSA device in incorrect "
+ "state for play: \"%s\".",
+ err2, snd_strerror(err2));
}
frame_index = 0;
measurement_data_is_valid = 0;