@@ -128,43 +128,70 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
128128 comp_info (dev , "multiband_drc_init_coef(), initializing %i-way crossover" ,
129129 config -> num_bands );
130130
131+ /* Combine memory allocations for crossover, emphasis, and deemphasis filter coefficients
132+ * into a single contiguous block to improve memory efficiency.
133+ * thereby reduces heap fragmentation, improves data locality for better cache
134+ * performance, and reduces overhead from separate memory allocations.
135+ */
136+ size_t total_coefficients_size = sizeof (struct sof_eq_iir_biquad ) *
137+ num_bands * nch * 3 ;
138+
139+ struct sof_eq_iir_biquad * coefficients_block =
140+ rzalloc (SOF_MEM_ZONE_RUNTIME , 0 , SOF_MEM_CAPS_RAM ,
141+ total_coefficients_size );
142+
143+ if (!coefficients_block ) {
144+ comp_err (dev , "multiband_drc_init_coef(), failed to allocate memory for coefficients" );
145+ return - ENOMEM ;
146+ }
147+
148+ /* Assign pointers to respective positions within the allocated memory block.
149+ * crossover starts at the beginning of the block,
150+ * emphasis follows after the crossover coefficients,
151+ * deemphasis is situated after the emphasis coefficients.
152+ * This ensures all filter coefficients are stored contiguously.
153+ */
154+ crossover = coefficients_block ;
155+ emphasis = coefficients_block + num_bands * nch ;
156+ deemphasis = emphasis + num_bands * nch ;
157+
131158 /* Crossover: collect the coef array and assign it to every channel */
132- crossover = config -> crossover_coef ;
133159 for (ch = 0 ; ch < nch ; ch ++ ) {
134160 ret = crossover_init_coef_ch (crossover , & state -> crossover [ch ],
135161 config -> num_bands );
136162 /* Free all previously allocated blocks in case of an error */
137163 if (ret < 0 ) {
138164 comp_err (dev ,
139165 "multiband_drc_init_coef(), could not assign coeffs to ch %d" , ch );
166+ rfree (coefficients_block );
140167 goto err ;
141168 }
142169 }
143170
144171 comp_info (dev , "multiband_drc_init_coef(), initializing emphasis_eq" );
145172
146173 /* Emphasis: collect the coef array and assign it to every channel */
147- emphasis = config -> emp_coef ;
148174 for (ch = 0 ; ch < nch ; ch ++ ) {
149175 ret = multiband_drc_eq_init_coef_ch (emphasis , & state -> emphasis [ch ]);
150176 /* Free all previously allocated blocks in case of an error */
151177 if (ret < 0 ) {
152178 comp_err (dev , "multiband_drc_init_coef(), could not assign coeffs to ch %d" ,
153179 ch );
180+ rfree (coefficients_block );
154181 goto err ;
155182 }
156183 }
157184
158185 comp_info (dev , "multiband_drc_init_coef(), initializing deemphasis_eq" );
159186
160187 /* Deemphasis: collect the coef array and assign it to every channel */
161- deemphasis = config -> deemp_coef ;
162188 for (ch = 0 ; ch < nch ; ch ++ ) {
163189 ret = multiband_drc_eq_init_coef_ch (deemphasis , & state -> deemphasis [ch ]);
164190 /* Free all previously allocated blocks in case of an error */
165191 if (ret < 0 ) {
166192 comp_err (dev , "multiband_drc_init_coef(), could not assign coeffs to ch %d" ,
167193 ch );
194+ rfree (coefficients_block );
168195 goto err ;
169196 }
170197 }
@@ -177,6 +204,7 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
177204 if (ret < 0 ) {
178205 comp_err (dev ,
179206 "multiband_drc_init_coef(), could not init pre delay buffers" );
207+ rfree (coefficients_block );
180208 goto err ;
181209 }
182210
@@ -191,6 +219,10 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
191219 return 0 ;
192220
193221err :
222+ /* Free allocated memory block on error */
223+ if (coefficients_block )
224+ rfree (coefficients_block );
225+
194226 multiband_drc_reset_state (state );
195227 return ret ;
196228}
@@ -220,7 +252,6 @@ static int multiband_drc_init(struct processing_module *mod)
220252 struct module_data * md = & mod -> priv ;
221253 struct comp_dev * dev = mod -> dev ;
222254 struct module_config * cfg = & md -> cfg ;
223- struct multiband_drc_comp_data * cd ;
224255 size_t bs = cfg -> size ;
225256 int ret ;
226257
@@ -235,9 +266,13 @@ static int multiband_drc_init(struct processing_module *mod)
235266 return - EINVAL ;
236267 }
237268
238- cd = rzalloc (SOF_MEM_ZONE_RUNTIME , 0 , SOF_MEM_CAPS_RAM , sizeof (* cd ));
239- if (!cd )
269+ /* Memory allocation for multiband_drc_comp_data */
270+ struct multiband_drc_comp_data * cd = rzalloc (SOF_MEM_ZONE_RUNTIME , 0 ,
271+ SOF_MEM_CAPS_RAM , sizeof (* cd ));
272+ if (!cd ) {
273+ comp_err (dev , "multiband_drc_init(), allocation for multiband_drc_comp_data failed" );
240274 return - ENOMEM ;
275+ }
241276
242277 md -> private = cd ;
243278 cd -> multiband_drc_func = NULL ;
0 commit comments