#pragma once
#include <stdint.h>
/* Max possible duration: UINT64_MAX / (60 * 60) hours
-> "5124095576030431:xx:xx", length 22 */
#define MAX_FORMATTED_DURATION_LENGTH 22
/* Structure to hold a track duration, in total samples / sampling rate to
avoid loss of precision.
The value formatted for printing (HH:MM:SS) is cached in `formatted`. That
cache is considered empty when `formatted[0] == '\0'` */
typedef struct
{
uint64_t sample_rate;
_Atomic uint64_t nb_samples;
char formatted[MAX_FORMATTED_DURATION_LENGTH + 1];
} Duration;
Duration * duration_init(uint64_t nb_samples, uint64_t sample_rate);
void duration_free(const Duration *dur);
/* Empty the formatted value cache so that it is recomputed during the next
call to duration_get_formatted() */
void duration_invalid_formatted_cache(Duration *dur);
/* Get the formatte value of `dur`, compute it if its cached value is empty */
const char * duration_get_formatted(Duration *dur);