[PATCH 2/2] sbc: Add sbc_get_delay API to retrieve codec delay

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Most audio codecs introduce intrinsic codec delay. SBC codec introduces
encode/decode delay which is not constant but depends on the number of
subbunds used. Providing API for that will simplify library usage in
case when precise delay calculation is required.
---
 sbc/sbc.c | 20 ++++++++++++++++++++
 sbc/sbc.h |  3 +++
 2 files changed, 23 insertions(+)

diff --git a/sbc/sbc.c b/sbc/sbc.c
index 428c8ee..869f367 100644
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -1470,6 +1470,26 @@ SBC_EXPORT size_t sbc_get_codesize(const sbc_t *sbc)
 	return subbands * blocks * channels * 2;
 }
 
+SBC_EXPORT unsigned sbc_get_delay(const sbc_t *sbc)
+{
+	uint16_t subbands;
+	struct sbc_priv *priv;
+
+	priv = sbc->priv;
+	if (!priv->init) {
+		subbands = sbc->subbands ? 8 : 4;
+	} else {
+		subbands = priv->frame.subbands;
+	}
+
+	/*
+	 * The delay is caused by the processing function which analyzes
+	 * old samples to encode the current frame. The amount of that
+	 * samples depends on the number of subbands.
+	 */
+	return subbands * 9 + 1;
+}
+
 SBC_EXPORT const char *sbc_get_implementation_info(const sbc_t *sbc)
 {
 	struct sbc_priv *priv;
diff --git a/sbc/sbc.h b/sbc/sbc.h
index b7323e8..829b161 100644
--- a/sbc/sbc.h
+++ b/sbc/sbc.h
@@ -94,6 +94,9 @@ unsigned sbc_get_frame_duration(const sbc_t *sbc);
 /* Returns the uncompressed block size in bytes */
 size_t sbc_get_codesize(const sbc_t *sbc);
 
+/* Returns the delay introduced by the codec in frames */
+unsigned sbc_get_delay(const sbc_t *sbc);
+
 const char *sbc_get_implementation_info(const sbc_t *sbc);
 void sbc_finish(sbc_t *sbc);
 
-- 
2.39.5





[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux