nuttx/libs/libc/audio/libsrc/0001-add-audio-quality-options.patch
Alin Jerpelea 48e6f2051d audio: libsamplerate: add initial audio Sample Rate Converter
Add audio sample rate conversion library from
http://www.mega-nerd.com/SRC/index.html

Source:
https://github.com/libsndfile/libsamplerate

Add needed patches for NuttX OS and embedded boards.

NOTE:
We must use master branch until next stable release
2020-11-19 18:05:47 -08:00

83 lines
2.8 KiB
Diff

From 8d709a69b23efc52030824ae21db889589467d8c Mon Sep 17 00:00:00 2001
From: Alin Jerpelea <alin.jerpelea@sony.com>
Date: Mon, 16 Nov 2020 09:44:17 +0100
Subject: [PATCH] add audio quality options
Many NuttX boards have limited rerources and will have to use
compile time quality options to reduce resource usage
Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
---
src/src_sinc.c | 30 +++++++++++++++++++++++++-----
1 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/src_sinc.c b/src/src_sinc.c
index 0a22708..b81326e 100644
--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -40,9 +40,17 @@ typedef int32_t increment_t ;
typedef float coeff_t ;
typedef int _CHECK_SHIFT_BITS[2 * (SHIFT_BITS < sizeof (increment_t) * 8 - 1) - 1]; /* sanity check. */
-#include "fastest_coeffs.h"
-#include "mid_qual_coeffs.h"
-#include "high_qual_coeffs.h"
+#if CONFIG_AUDIO_SRC_QUALITY == 2
+ #include "fastest_coeffs.h"
+#elif CONFIG_AUDIO_SRC_QUALITY == 1
+ #include "mid_qual_coeffs.h"
+#elif if CONFIG_AUDIO_SRC_QUALITY == 0
+ #include "high_qual_coeffs.h"
+#else
+ #include "fastest_coeffs.h"
+ #include "mid_qual_coeffs.h"
+ #include "high_qual_coeffs.h"
+#endif
typedef struct
{ int sinc_magic_marker ;
@@ -206,6 +214,19 @@ sinc_filter_new (int converter_type, int channels)
if (priv)
{
priv->sinc_magic_marker = SINC_MAGIC_MARKER ;
+#if CONFIG_AUDIO_SRC_QUALITY == 2
+ priv->coeffs = fastest_coeffs.coeffs ;
+ priv->coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 2 ;
+ priv->index_inc = fastest_coeffs.increment ;
+#elif CONFIG_AUDIO_SRC_QUALITY == 1
+ priv->coeffs = slow_mid_qual_coeffs.coeffs ;
+ priv->coeff_half_len = ARRAY_LEN (slow_mid_qual_coeffs.coeffs) - 2 ;
+ priv->index_inc = slow_mid_qual_coeffs.increment ;
+#elif CONFIG_AUDIO_SRC_QUALITY == 0
+ priv->coeffs = slow_high_qual_coeffs.coeffs ;
+ priv->coeff_half_len = ARRAY_LEN (slow_high_qual_coeffs.coeffs) - 2 ;
+ priv->index_inc = slow_high_qual_coeffs.increment ;
+#else
switch (converter_type)
{
case SRC_SINC_FASTEST :
@@ -213,19 +234,18 @@ sinc_filter_new (int converter_type, int channels)
priv->coeff_half_len = ARRAY_LEN (fastest_coeffs.coeffs) - 2 ;
priv->index_inc = fastest_coeffs.increment ;
break ;
-
case SRC_SINC_MEDIUM_QUALITY :
priv->coeffs = slow_mid_qual_coeffs.coeffs ;
priv->coeff_half_len = ARRAY_LEN (slow_mid_qual_coeffs.coeffs) - 2 ;
priv->index_inc = slow_mid_qual_coeffs.increment ;
break ;
-
case SRC_SINC_BEST_QUALITY :
priv->coeffs = slow_high_qual_coeffs.coeffs ;
priv->coeff_half_len = ARRAY_LEN (slow_high_qual_coeffs.coeffs) - 2 ;
priv->index_inc = slow_high_qual_coeffs.increment ;
break ;
}
+#endif
priv->b_len = 3 * (int) lrint ((priv->coeff_half_len + 2.0) / priv->index_inc * SRC_MAX_RATIO + 1) ;
priv->b_len = MAX (priv->b_len, 4096) ;
--
2.17.1