xref: /OK3568_Linux_fs/buildroot/package/alsa-lib/0003-add-gain-for-audio-input.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From d967585c6178fab1e1d39c9bfd278e0b2432664d Mon Sep 17 00:00:00 2001
2From: Nyx Zheng <zyh@rock-chips.com>
3Date: Mon, 16 Jul 2018 17:33:30 +0800
4Subject: [PATCH 3/4] add gain for audio input
5
6Signed-off-by: Nyx Zheng <zyh@rock-chips.com>
7---
8 src/pcm/pcm.c | 19 +++++++++++++++++++
9 1 file changed, 19 insertions(+)
10
11diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
12index a2eb529..2720f07 100644
13--- a/src/pcm/pcm.c
14+++ b/src/pcm/pcm.c
15@@ -854,6 +854,24 @@ void DCBDoing(void* pIn, int length, int channels)
16 }
17 #endif
18
19+void add_gain(void* pIn, int length, int channels)
20+{
21+    int i = 0;
22+    int16_t * pInBuf  =  (int16_t *)pIn;
23+    char *alsa_gain_level = getenv("ALSA_LIB_ADD_GAIN");
24+    if(alsa_gain_level) {
25+        int level = atoi(alsa_gain_level);
26+        //printf("gain level:%d\n",level);
27+        for(i = 0; i < length; i ++ ) {
28+            int curChannel = i % channels;
29+            if(curChannel < channels - 2 ) {//audio loopback no need to add gain
30+                (*pInBuf) <<= level;
31+            }
32+            pInBuf++;
33+        }
34+    }
35+}
36+
37 /* check whether the PCM is in the unexpected state */
38 static int bad_pcm_state(snd_pcm_t *pcm, unsigned int supported_states,
39 			 unsigned int noop_states)
40@@ -1813,6 +1831,7 @@ snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t
41 #ifdef DCB_FILTER_16BIT
42 	DCBDoing((void*)buffer, tmp * pcm->frame_bits / 8 / sizeof(int16_t), pcm->channels);
43 #endif
44+	add_gain((void*)buffer, tmp * pcm->frame_bits / 8 / sizeof(int16_t), pcm->channels);
45 	return tmp;
46 }
47
48--
492.20.1
50
51