From 2a4f40495335f5acb3392685294bef8fd19665c5 Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Sat, 3 Oct 2015 21:33:10 +0100 Subject: [PATCH] Disable using linear mixer scale for the time being. --- audio_alsa.c | 5 ++++- player.c | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/audio_alsa.c b/audio_alsa.c index 7a3fe45e..e050e88a 100644 --- a/audio_alsa.c +++ b/audio_alsa.c @@ -236,7 +236,8 @@ static int init(int argc, char **argv) { (1.0 * alsa_mix_maxdb) / 100.0); } else { // use the linear scale and do the db conversion ourselves - debug(1, "note: the hardware mixer specified -- \"%s\" -- does not have dB volume -- using the [hopefully] linear settings.",alsa_mix_ctrl); + debug(1, "note: the hardware mixer specified -- \"%s\" -- does not have a dB volume scale, so it can't be used.",alsa_mix_ctrl); + /* debug(1, "Min and max volumes are %d and %d.",alsa_mix_minv,alsa_mix_maxv); alsa_mix_maxdb = 0; if ((alsa_mix_maxv!=0) && (alsa_mix_minv!=0)) @@ -246,6 +247,7 @@ static int init(int argc, char **argv) { audio_alsa.volume = &linear_volume; // insert the linear volume function audio_alsa.parameters = ¶meters; // likewise the parameters stuff debug(1,"Max and min dB calculated are %d and %d.",alsa_mix_maxdb,alsa_mix_mindb); + */ } } if (snd_mixer_selem_has_playback_switch(alsa_mix_elem)) { @@ -409,6 +411,7 @@ static void parameters(audio_parameters *info) { } static void volume(double vol) { + // debug(1,"Volume called %f.",vol); set_volume = vol; double vol_setting = vol2attn(vol, alsa_mix_maxdb, alsa_mix_mindb); // debug(1,"Setting volume db to %f, for volume input of %f.",vol_setting/100,vol); diff --git a/player.c b/player.c index b7224e5e..c28ad726 100644 --- a/player.c +++ b/player.c @@ -492,12 +492,12 @@ static abuf_t *buffer_get_frame(void) { if (curframe->ready) { if (ab_buffering) { // if we are getting packets but not yet forwarding them to the player + uint32_t reference_timestamp; + uint64_t reference_timestamp_time,remote_reference_timestamp_time; + get_reference_timestamp_stuff(&reference_timestamp, &reference_timestamp_time, &remote_reference_timestamp_time); if (first_packet_timestamp == 0) { // if this is the very first packet // debug(1,"First frame seen, time %u, with %d // frames...",curframe->timestamp,seq_diff(ab_read, ab_write)); - uint32_t reference_timestamp; - uint64_t reference_timestamp_time,remote_reference_timestamp_time; - get_reference_timestamp_stuff(&reference_timestamp, &reference_timestamp_time, &remote_reference_timestamp_time); if (reference_timestamp) { // if we have a reference time // debug(1,"First frame seen with timestamp..."); first_packet_timestamp = curframe->timestamp; // we will keep buffering until we are @@ -527,7 +527,6 @@ static abuf_t *buffer_get_frame(void) { // -4410 frames. int64_t delta = ((int64_t)first_packet_timestamp - (int64_t)reference_timestamp); - first_packet_time_to_play = reference_timestamp_time + ((delta + (int64_t)config.latency + (int64_t)config.audio_backend_latency_offset) @@ -544,6 +543,13 @@ static abuf_t *buffer_get_frame(void) { } if (first_packet_time_to_play != 0) { + // recalculate first_packet_time_to_play -- the latency might change + int64_t delta = ((int64_t)first_packet_timestamp - (int64_t)reference_timestamp); + first_packet_time_to_play = + reference_timestamp_time + + ((delta + (int64_t)config.latency + (int64_t)config.audio_backend_latency_offset) + << 32) / + 44100; uint32_t filler_size = frame_size; uint32_t max_dac_delay = 4410; @@ -1210,12 +1216,13 @@ void player_volume(double f) { // it back to a number. double scaled_volume = vol2attn(f, 0, -9630); - double linear_volume = pow(10, scaled_volume / 20*100); + double linear_volume = pow(10, scaled_volume / 2000); if (f == -144.0) linear_volume = 0.0; if (config.output->volume) { + // debug(1,"Set volume to %f.",f); config.output->volume(f); // volume will be sent as metadata by the config.output device linear_volume = 1.0; // no attenuation needed -- this value is used as a flag to avoid calculations } @@ -1231,6 +1238,7 @@ void player_volume(double f) { audio_information.is_muted = 0; } audio_information.valid = 1; + // debug(1,"Software volume set to %f on scale with a %f dB",f,linear_volume); pthread_mutex_lock(&vol_mutex); software_mixer_volume = linear_volume; fix_volume = 65536.0 * software_mixer_volume;