~q3cpma/mus

ref: cf29c2237d0c99e5240a55895c07564ef4635392 mus/mus_player/duration.h -rw-r--r-- 967 bytes
cf29c223q3cpma Add a #pragma once to the new xoshiro128plus.h header 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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);