From 38ab363275a8dd70988eadab7c84071d69a740fc Mon Sep 17 00:00:00 2001 From: Christian Spielberger Date: Wed, 27 Apr 2022 17:05:34 +0200 Subject: [PATCH] au: add util function calc_nsamp() (#42) --- CMakeLists.txt | 1 + include/rem_au.h | 2 ++ src/au/mod.mk | 2 +- src/au/util.c | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/au/util.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 49a8311..043bab9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,7 @@ add_definitions(-DVERSION="${PROJECT_VERSION}") add_library(${PROJECT_NAME} src/aac/aac.c src/au/fmt.c + src/au/util.c src/aubuf/aubuf.c src/aubuf/ajb.c src/auconv/auconv.c diff --git a/include/rem_au.h b/include/rem_au.h index 47c7836..8174acb 100644 --- a/include/rem_au.h +++ b/include/rem_au.h @@ -18,3 +18,5 @@ enum aufmt { size_t aufmt_sample_size(enum aufmt fmt); const char *aufmt_name(enum aufmt fmt); + +uint32_t calc_nsamp(uint32_t srate, uint8_t channels, uint16_t ptime); diff --git a/src/au/mod.mk b/src/au/mod.mk index d300f31..5e86454 100644 --- a/src/au/mod.mk +++ b/src/au/mod.mk @@ -4,4 +4,4 @@ # Copyright (C) 2010 Creytiv.com # -SRCS += au/fmt.c +SRCS += au/fmt.c au/util.c diff --git a/src/au/util.c b/src/au/util.c new file mode 100644 index 0000000..dddf19c --- /dev/null +++ b/src/au/util.c @@ -0,0 +1,23 @@ +/** + * @file util.c Audio utility functions + * + * Copyright (C) 2022 Commend.com - c.spielberger@commend.com + */ + +#include +#include + + +/** + * Calculate number of samples from sample rate, channels and packet time + * + * @param srate Sample rate in [Hz] + * @param channels Number of channels + * @param ptime Packet time in [ms] + * + * @return Number of samples + */ +uint32_t calc_nsamp(uint32_t srate, uint8_t channels, uint16_t ptime) +{ + return srate * channels * ptime / 1000; +}