From 4329eaae159248de34d9604c6adc6b6f5ca9e7e0 Mon Sep 17 00:00:00 2001 From: heck Date: Mon, 23 Sep 2024 02:27:29 +0200 Subject: [PATCH] sai.h - constexpr `GetSampleRate()` --- src/per/sai.cpp | 14 +++----------- src/per/sai.h | 12 ++++++------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/per/sai.cpp b/src/per/sai.cpp index 869111e24..2e6bd7cc2 100644 --- a/src/per/sai.cpp +++ b/src/per/sai.cpp @@ -27,7 +27,7 @@ class SaiHandle::Impl SaiHandle::Result StopDmaTransfer(); // Utility functions - float GetSampleRate(); + constexpr float GetSampleRate(); size_t GetBlockSize(); float GetBlockRate(); @@ -337,17 +337,9 @@ SaiHandle::Result SaiHandle::Impl::StopDmaTransfer() return Result::OK; } -float SaiHandle::Impl::GetSampleRate() +constexpr float SaiHandle::Impl::GetSampleRate() { - switch(config_.sr) - { - case Config::SampleRate::SAI_8KHZ: return 8000.f; - case Config::SampleRate::SAI_16KHZ: return 16000.f; - case Config::SampleRate::SAI_32KHZ: return 32000.f; - case Config::SampleRate::SAI_48KHZ: return 48000.f; - case Config::SampleRate::SAI_96KHZ: return 96000.f; - default: return 48000.f; - } + return config_.sr; } size_t SaiHandle::Impl::GetBlockSize() { diff --git a/src/per/sai.h b/src/per/sai.h index bec5c06e9..10a3ecd4c 100644 --- a/src/per/sai.h +++ b/src/per/sai.h @@ -53,13 +53,13 @@ class SaiHandle }; /** Rate at which samples will be streaming to/from the device. */ - enum class SampleRate + enum SampleRate : int { - SAI_8KHZ, - SAI_16KHZ, - SAI_32KHZ, - SAI_48KHZ, - SAI_96KHZ, + SAI_8KHZ = 8000, + SAI_16KHZ = 16000, + SAI_32KHZ = 32000, + SAI_48KHZ = 48000, + SAI_96KHZ = 96000, }; /** Bit Depth that the hardware expects to be transferred to/from the device. */