summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp/pbe.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/dsp/pbe.c')
-rw-r--r--lib/rbcodec/dsp/pbe.c77
1 files changed, 37 insertions, 40 deletions
diff --git a/lib/rbcodec/dsp/pbe.c b/lib/rbcodec/dsp/pbe.c
index 3656f687fd..3e2183a302 100644
--- a/lib/rbcodec/dsp/pbe.c
+++ b/lib/rbcodec/dsp/pbe.c
@@ -37,7 +37,7 @@
37#define B2_SIZE (B2_DLY+1) 37#define B2_SIZE (B2_DLY+1)
38#define B0_SIZE (B0_DLY+1) 38#define B0_SIZE (B0_DLY+1)
39 39
40static int pbe_strength = 100; 40static int pbe_strength = 0;
41static int pbe_precut = 0; 41static int pbe_precut = 0;
42static int32_t tcoef1, tcoef2, tcoef3; 42static int32_t tcoef1, tcoef2, tcoef3;
43static int32_t *b0[2], *b2[2], *b3[2]; 43static int32_t *b0[2], *b2[2], *b3[2];
@@ -46,20 +46,21 @@ int32_t temp_buffer;
46static struct dsp_filter pbe_filter[5]; 46static struct dsp_filter pbe_filter[5];
47static int handle = -1; 47static int handle = -1;
48 48
49static void pbe_buffer_alloc(void) 49#define PBE_BUFSIZE ((B0_SIZE + B2_SIZE + B3_SIZE)*2*sizeof(int32_t))
50{
51 if (handle > 0)
52 return; /* already-allocated */
53 50
54 unsigned int total_len = (B0_SIZE + B2_SIZE + B3_SIZE) * 2; 51static int pbe_buffer_alloc(void)
55 handle = core_alloc("dsp_pbe_buffer",sizeof(int32_t) * total_len); 52{
53 handle = core_alloc("dsp_pbe_buffer", PBE_BUFSIZE);
54 return handle;
55}
56 56
57static void pbe_buffer_free(void)
58{
57 if (handle < 0) 59 if (handle < 0)
58 {
59 pbe_strength = 0;
60 return; 60 return;
61 } 61
62 memset(core_get_data(handle),0,sizeof(int32_t) * total_len); 62 core_free(handle);
63 handle = -1;
63} 64}
64 65
65static void pbe_buffer_get_data(void) 66static void pbe_buffer_get_data(void)
@@ -76,12 +77,8 @@ static void pbe_buffer_get_data(void)
76 77
77static void dsp_pbe_flush(void) 78static void dsp_pbe_flush(void)
78{ 79{
79 if (pbe_strength == 0) 80 memset(core_get_data(handle), 0, PBE_BUFSIZE);
80 return; /* Not currently enabled */
81 81
82 unsigned int total_len = (B0_SIZE + B2_SIZE + B3_SIZE) * 2;
83 if (handle > 0)
84 memset(core_get_data(handle),0,sizeof(int32_t) * total_len);
85 b0_r[0] = 0; b0_w[0] = 0; 82 b0_r[0] = 0; b0_w[0] = 0;
86 b0_r[1] = 0; b0_w[1] = 0; 83 b0_r[1] = 0; b0_w[1] = 0;
87 b2_r[0] = 0; b2_w[0] = 0; 84 b2_r[0] = 0; b2_w[0] = 0;
@@ -121,35 +118,28 @@ void dsp_pbe_precut(int var)
121 118
122 pbe_precut = var; 119 pbe_precut = var;
123 120
124 if (pbe_strength == 0) 121 struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO);
122
123 if (!dsp_proc_enabled(dsp, DSP_PROC_PBE))
125 return; /* Not currently enabled */ 124 return; /* Not currently enabled */
126 125
127 /* Push more DSP_PROC_INIT messages to force filter updates 126 pbe_update_filter(dsp_get_output_frequency(dsp));
128 (with value = 1) */
129 struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO);
130 dsp_proc_enable(dsp, DSP_PROC_PBE, true);
131} 127}
132 128
133
134void dsp_pbe_enable(int var) 129void dsp_pbe_enable(int var)
135{ 130{
136 if (var == pbe_strength) 131 if (var == pbe_strength)
137 return; /* No change */ 132 return; /* No change */
138 bool was_enabled = pbe_strength > 0; 133
139 pbe_strength = var; 134 pbe_strength = var;
140 135
136 struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO);
137 bool was_enabled = dsp_proc_enabled(dsp, DSP_PROC_PBE);
141 bool now_enabled = var > 0; 138 bool now_enabled = var > 0;
142 139
143 if (now_enabled == was_enabled) 140 if (now_enabled == was_enabled)
144 return; /* No change in enabled status */ 141 return; /* No change in enabled status */
145 142
146 if (now_enabled == false && handle > 0)
147 {
148 core_free(handle);
149 handle = -1;
150 }
151
152 struct dsp_config *dsp = dsp_get_config(CODEC_IDX_AUDIO);
153 dsp_proc_enable(dsp, DSP_PROC_PBE, now_enabled); 143 dsp_proc_enable(dsp, DSP_PROC_PBE, now_enabled);
154} 144}
155 145
@@ -209,21 +199,28 @@ static intptr_t pbe_configure(struct dsp_proc_entry *this,
209 intptr_t value) 199 intptr_t value)
210{ 200{
211 /* This only attaches to the audio (codec) DSP */ 201 /* This only attaches to the audio (codec) DSP */
202 intptr_t retval = 0;
212 203
213 switch (setting) 204 switch (setting)
214 { 205 {
215 case DSP_PROC_INIT: 206 case DSP_PROC_INIT:
216 if (value == 0) 207 /* Coming online; was disabled */
217 { 208 retval = pbe_buffer_alloc();
218 /* Coming online; was disabled */ 209 if (retval < 0)
219 this->process = pbe_process; 210 break;
220 pbe_buffer_alloc(); 211
221 dsp_pbe_flush(); 212 this->process = pbe_process;
222 dsp_proc_activate(dsp, DSP_PROC_PBE, true); 213
223 } 214 dsp_pbe_flush();
224 /* else additional forced messages */
225 215
216 /* Wouldn't have been getting frequency updates */
226 pbe_update_filter(dsp_get_output_frequency(dsp)); 217 pbe_update_filter(dsp_get_output_frequency(dsp));
218 dsp_proc_activate(dsp, DSP_PROC_PBE, true);
219 break;
220
221 case DSP_PROC_CLOSE:
222 /* Being disabled (called also if init fails) */
223 pbe_buffer_free();
227 break; 224 break;
228 225
229 case DSP_FLUSH: 226 case DSP_FLUSH:
@@ -237,7 +234,7 @@ static intptr_t pbe_configure(struct dsp_proc_entry *this,
237 break; 234 break;
238 } 235 }
239 236
240 return 1; 237 return retval;
241} 238}
242 239
243/* Database entry */ 240/* Database entry */