[Sound-open-firmware] [PATCH 2/2] volume: update volume to use the new q_mult functions

Ranjani Sridharan ranjani.sridharan at linux.intel.com
Mon Mar 19 22:16:23 CET 2018


This patch updates the volume comp to use the updates q_mult functions
for volume scaling

Signed-off-by: Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
---
 src/audio/volume.c | 86 ++++++++++++++++++++++++++++++------------------------
 1 file changed, 48 insertions(+), 38 deletions(-)

diff --git a/src/audio/volume.c b/src/audio/volume.c
index 0620e18..27f897d 100644
--- a/src/audio/volume.c
+++ b/src/audio/volume.c
@@ -120,10 +120,12 @@ static void vol_s32_to_s16(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.31 --> Q1.15 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = (int16_t)q_multsr_sat_32x32(
-			src[i], cd->volume[0], Q_SHIFT_BITS_64(31, 16, 15));
-		dest[i + 1] = (int16_t)q_multsr_sat_32x32(
-			src[i + 1], cd->volume[1], Q_SHIFT_BITS_64(31, 16, 15));
+		q_multsr_sat_32x32_16(src, cd->volume[0],
+				      Q_SHIFT_BITS_64(31, 16, 15), dest,
+				      i, 0);
+		q_multsr_sat_32x32_16(src, cd->volume[1],
+				      Q_SHIFT_BITS_64(31, 16, 15), dest,
+				      i + 1, 0);
 	}
 }
 
@@ -139,10 +141,12 @@ static void vol_s32_to_s32(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.31 --> Q1.31 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = q_multsr_sat_32x32(
-			src[i], cd->volume[0], Q_SHIFT_BITS_64(31, 16, 31));
-		dest[i + 1] = q_multsr_sat_32x32(
-			src[i + 1], cd->volume[1], Q_SHIFT_BITS_64(31, 16, 31));
+		q_multsr_sat_32x32_32(src, cd->volume[0],
+				      Q_SHIFT_BITS_64(31, 16, 31), dest,
+				      i, 0);
+		q_multsr_sat_32x32_32(src, cd->volume[1],
+				      Q_SHIFT_BITS_64(31, 16, 31), dest,
+				      i + 1, 0);
 	}
 }
 
@@ -158,10 +162,12 @@ static void vol_s16_to_s16(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.15 --> Q1.15 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = q_multsr_sat_16x16(
-			src[i], cd->volume[0], Q_SHIFT_BITS_32(15, 16, 15));
-		dest[i + 1] = q_multsr_sat_16x16(
-			src[i + 1], cd->volume[1], Q_SHIFT_BITS_32(15, 16, 15));
+		q_multsr_sat_16x16_16(src, cd->volume[0],
+				      Q_SHIFT_BITS_32(15, 16, 15), dest,
+				      i, 0);
+		q_multsr_sat_16x16_16(src, cd->volume[1],
+				      Q_SHIFT_BITS_32(15, 16, 15), dest,
+				      i + 1, 0);
 	}
 }
 
@@ -177,10 +183,12 @@ static void vol_s16_to_s24(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.15 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = q_multsr_sat_32x32(
-			src[i], cd->volume[0], Q_SHIFT_BITS_64(15, 16, 23));
-		dest[i + 1] = q_multsr_sat_32x32(
-			src[i + 1], cd->volume[1], Q_SHIFT_BITS_64(15, 16, 23));
+		q_multsr_sat_16x32_32(src, cd->volume[0],
+				      Q_SHIFT_BITS_64(15, 16, 23), dest,
+				      i, 0);
+		q_multsr_sat_16x32_32(src, cd->volume[1],
+				      Q_SHIFT_BITS_64(15, 16, 23), dest,
+				      i + 1, 0);
 	}
 }
 
@@ -196,12 +204,12 @@ static void vol_s24_to_s16(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.23 --> Q1.15 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = (int16_t)q_multsr_sat_32x32(
-			sign_extend_s24(src[i]), cd->volume[0],
-			Q_SHIFT_BITS_64(23, 16, 15));
-		dest[i + 1] = (int16_t)q_multsr_sat_32x32(
-			sign_extend_s24(src[i + 1]), cd->volume[1],
-			Q_SHIFT_BITS_64(23, 16, 15));
+		q_multsr_sat_32x32_16(src, cd->volume[0],
+				      Q_SHIFT_BITS_64(23, 16, 15), dest,
+				      i, 1);
+		q_multsr_sat_32x32_16(src, cd->volume[1],
+				      Q_SHIFT_BITS_64(23, 16, 15), dest,
+				      i + 1, 1);
 	}
 }
 
@@ -217,10 +225,12 @@ static void vol_s32_to_s24(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.31 --> Q1.23 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = q_multsr_sat_32x32(
-			src[i], cd->volume[0], Q_SHIFT_BITS_64(31, 16, 23));
-		dest[i + 1] = q_multsr_sat_32x32(
-			src[i + 1], cd->volume[1], Q_SHIFT_BITS_64(31, 16, 23));
+		q_multsr_sat_32x32_32(src, cd->volume[0],
+				      Q_SHIFT_BITS_64(31, 16, 23), dest,
+				      i, 0);
+		q_multsr_sat_32x32_32(src, cd->volume[1],
+				      Q_SHIFT_BITS_64(31, 16, 23), dest,
+				      i + 1, 0);
 	}
 }
 
@@ -236,12 +246,12 @@ static void vol_s24_to_s32(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.23 --> Q1.31 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = q_multsr_sat_32x32(
-			sign_extend_s24(src[i]), cd->volume[0],
-			Q_SHIFT_BITS_64(23, 16, 31));
-		dest[i + 1] = q_multsr_sat_32x32(
-			sign_extend_s24(src[i + 1]), cd->volume[1],
-			Q_SHIFT_BITS_64(23, 16, 31));
+		q_multsr_sat_32x32_32(src, cd->volume[0],
+				      Q_SHIFT_BITS_64(23, 16, 31), dest,
+				      i, 1);
+		q_multsr_sat_32x32_32(src, cd->volume[1],
+				      Q_SHIFT_BITS_64(23, 16, 31), dest,
+				      i + 1, 1);
 	}
 }
 
@@ -258,12 +268,12 @@ static void vol_s24_to_s24(struct comp_dev *dev, struct comp_buffer *sink,
 	/* buffer sizes are always divisible by period frames */
 	/* Samples are Q1.23 --> Q1.23 and volume is Q1.16 */
 	for (i = 0; i < frames * 2; i += 2) {
-		dest[i] = q_multsr_sat_32x32(
-			sign_extend_s24(src[i]), cd->volume[0],
-			Q_SHIFT_BITS_64(23, 16, 23));
-		dest[i + 1] = q_multsr_sat_32x32(
-			sign_extend_s24(src[i + 1]), cd->volume[1],
-			Q_SHIFT_BITS_64(23, 16, 23));
+		q_multsr_sat_32x32_32(src, cd->volume[0],
+				      Q_SHIFT_BITS_64(23, 16, 23), dest,
+				      i, 1);
+		q_multsr_sat_32x32_32(src, cd->volume[1],
+				      Q_SHIFT_BITS_64(23, 16, 23), dest,
+				      i + 1, 1);
 	}
 }
 
-- 
2.14.1



More information about the Sound-open-firmware mailing list