From dc839639620352c5fa9b63db6679126ec5bcfba8 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Tue, 22 Nov 2022 19:19:01 +0000 Subject: Add helpers for converting to/from normalized (perceptual) volume These routines were taken from alsamixer and converted to fixed point for Rockbox. Change-Id: I64e8bf08da02b1e6e3ef10fdc78254bf8e87ff20 --- apps/misc.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'apps/misc.h') diff --git a/apps/misc.h b/apps/misc.h index 403a8c53ac..72b8735c8a 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -238,4 +238,12 @@ int core_load_bmp(const char *filename, struct bitmap *bm, const int bmformat, ssize_t *buf_reqd, struct buflib_callbacks *ops); #endif +/* Convert a volume (in tenth dB) in the range [min_vol, max_vol] + * to a normalized linear value in the range [0, max_norm]. */ +long to_normalized_volume(long vol, long min_vol, long max_vol, long max_norm); + +/* Inverse of to_normalized_volume(), returns the volume in tenth dB + * for the given normalized volume. */ +long from_normalized_volume(long norm, long min_vol, long max_vol, long max_norm); + #endif /* MISC_H */ -- cgit v1.2.3