tv.h: replace time conv macros (+ in alsa)

Replace time conversion macros defined 2 commits ago between msec
and usec.

This is proposed (considered) solution to the todo in tv.h - inconsistent
unit conversion macros. Rather than value, it might be better to use
function-like macros.

The issues is that there will be actaully double the amount - A_TO_B and
B_TO_A. To keep it in a reasonable range, it would be best to remove
the _DBL versions and keep the user typing the arg to double inestead
This commit is contained in:
Martin Pulec
2024-09-10 08:30:57 +02:00
parent 47c13e3968
commit 52ed2fdd22
2 changed files with 13 additions and 15 deletions

View File

@@ -448,7 +448,7 @@ set_device_buffer(snd_pcm_t *handle, playback_mode_t playback_mode,
enum {
REC_MIN_BUF_US = 5000,
};
unsigned int buf_len = 0;
unsigned int buf_len_us = 0;
int buf_dir = -1;
const char *buff_param = get_commandline_param("alsa-playback-buffer");
@@ -456,10 +456,10 @@ set_device_buffer(snd_pcm_t *handle, playback_mode_t playback_mode,
buff_param == NULL) {
// set minimal value from the configuration space
CHECK_OK(snd_pcm_hw_params_set_buffer_time_first(
handle, params, &buf_len, &buf_dir));
handle, params, &buf_len_us, &buf_dir));
MSG(INFO, "ALSA driver buffer len set to: %lf ms\n",
buf_len / US_IN_1MS_DBL);
if (buf_len <= REC_MIN_BUF_US) {
US_TO_MS((double) buf_len_us));
if (buf_len_us <= REC_MIN_BUF_US) {
MSG(WARNING,
"ALSA driver buffer len less than %d usec seem to "
"be too loow, consider using alsa-playback-buffer "
@@ -469,22 +469,19 @@ set_device_buffer(snd_pcm_t *handle, playback_mode_t playback_mode,
return;
}
if (buff_param != NULL) {
buf_len = atoi(buff_param);
} else {
buf_len = (playback_mode == SYNC ? BUF_LEN_DEFAULT_SYNC_MS
: BUF_LEN_DEFAULT_MS) *
US_IN_1MS;
}
buf_len_us = buff_param != NULL ? atoi(buff_param)
: MS_TO_US(playback_mode == SYNC
? BUF_LEN_DEFAULT_SYNC_MS
: BUF_LEN_DEFAULT_MS);
const int rc = snd_pcm_hw_params_set_buffer_time_near(
handle, params, &buf_len, &buf_dir);
handle, params, &buf_len_us, &buf_dir);
if (rc < 0) {
MSG(WARNING, "Warning - unable to set buffer to its size: %s\n",
snd_strerror(rc));
}
MSG(INFO, "ALSA driver buffer len set to: %lf ms\n",
buf_len / US_IN_1MS_DBL);
US_TO_MS((double) buf_len_us));
}
ADD_TO_PARAM("alsa-play-period-size", "* alsa-play-period-size=<frames>\n"

View File

@@ -86,8 +86,6 @@ typedef long long time_ns_t;
#define MS_IN_NS_DBL 1000000.0
#define MS_IN_SEC 1000
#define MS_IN_SEC_DBL 1000.0
#define US_IN_1MS 1000
#define US_IN_1MS_DBL 1000.0
#define US_IN_SEC 1000000LL
#define US_IN_NS 1000LL
#define US_IN_SEC_DBL ((double) US_IN_SEC)
@@ -97,6 +95,9 @@ typedef long long time_ns_t;
#define NS_IN_SEC_DBL ((double) NS_IN_SEC)
#define NS_IN_US (NS_IN_SEC/US_IN_SEC)
#define NS_IN_US_DBL ((double) NS_IN_US)
#define US_TO_MS(val_us) ((val_us) / 1000)
#define MS_TO_US(val_ms) ((val_ms) * 1000)
static inline time_ns_t get_time_in_ns() {
#ifdef HAVE_TIMESPEC_GET
struct timespec ts = { 0, 0 };