From eb36aa68d0d1fad9e108ad95bc9f38534e9939b0 Mon Sep 17 00:00:00 2001 From: Lars Immisch Date: Tue, 21 Nov 2023 21:48:53 +0100 Subject: [PATCH] Use aufmt_sample_size instead of switch. --- rem/aufile/aufile.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/rem/aufile/aufile.c b/rem/aufile/aufile.c index 13f2cd26b..8902f4670 100644 --- a/rem/aufile/aufile.c +++ b/rem/aufile/aufile.c @@ -257,26 +257,13 @@ size_t aufile_get_length(struct aufile *af, const struct aufile_prm *prm) if (!af || !prm) return 0; - switch (prm->fmt) { - case AUFMT_PCMA: - case AUFMT_PCMU: - return af->datasize * 1000 / - (prm->channels * prm->srate); - case AUFMT_S16LE: - return af->datasize * 1000 / - (prm->channels * prm->srate * 2); - case AUFMT_S24_3LE: - return af->datasize * 1000 / - (prm->channels * prm->srate * 3); - case AUFMT_S32LE: - case AUFMT_FLOAT: - return af->datasize * 1000 / - (prm->channels * prm->srate * 4); - default: - return 0; - } + int sample_size = aufmt_sample_size(prm->fmt); - return 0; + if (sample_size == 0) + return 0; + + return af->datasize * 1000 / (sample_size * + prm->channels * prm->srate); } /**