Skip to content

Commit b793f0c

Browse files
authored
Merge pull request #483 from ranj063/eq
Eq 16/24/32-bit support
2 parents 8998135 + 609d8a4 commit b793f0c

6 files changed

Lines changed: 83 additions & 55 deletions

File tree

src/audio/component.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,31 @@ int comp_set_state(struct comp_dev *dev, int cmd)
187187
return ret;
188188
}
189189

190+
/* set period bytes based on source/sink format */
191+
void comp_set_period_bytes(struct comp_dev *dev, uint32_t frames,
192+
enum sof_ipc_frame *format, uint32_t *period_bytes)
193+
{
194+
struct sof_ipc_comp_config *sconfig;
195+
196+
/* get data format */
197+
switch (dev->comp.type) {
198+
case SOF_COMP_DAI:
199+
case SOF_COMP_SG_DAI:
200+
/* format comes from DAI/comp config */
201+
sconfig = COMP_GET_CONFIG(dev);
202+
*format = sconfig->frame_fmt;
203+
break;
204+
case SOF_COMP_HOST:
205+
case SOF_COMP_SG_HOST:
206+
default:
207+
/* format comes from IPC params */
208+
*format = dev->params.frame_fmt;
209+
break;
210+
}
211+
212+
*period_bytes = frames * comp_frame_bytes(dev);
213+
}
214+
190215
void sys_comp_init(void)
191216
{
192217
cd = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(*cd));

src/audio/eq_fir.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ static inline void set_s32_fir(struct comp_data *cd)
139139
static inline int set_fir_func(struct comp_dev *dev)
140140
{
141141
struct comp_data *cd = comp_get_drvdata(dev);
142-
struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
143142

144-
switch (config->frame_fmt) {
143+
switch (dev->params.frame_fmt) {
145144
case SOF_IPC_FRAME_S16_LE:
146145
trace_eq("f16");
147146
set_s16_fir(cd);
@@ -194,9 +193,8 @@ static void eq_fir_s32_passthrough(struct fir_state_32x16 fir[],
194193
static inline int set_pass_func(struct comp_dev *dev)
195194
{
196195
struct comp_data *cd = comp_get_drvdata(dev);
197-
struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
198196

199-
switch (config->frame_fmt) {
197+
switch (dev->params.frame_fmt) {
200198
case SOF_IPC_FRAME_S16_LE:
201199
trace_eq("p16");
202200
cd->eq_fir_func_even = eq_fir_s16_passthrough;
@@ -515,7 +513,7 @@ static int fir_cmd_set_data(struct comp_dev *dev,
515513
int ret = 0;
516514

517515
/* Check version from ABI header */
518-
if (cdata->data->comp_abi != SOF_EQ_FIR_ABI_VERSION) {
516+
if (cdata->data->comp_abi != SOF_ABI_VERSION) {
519517
trace_eq_error("eab");
520518
return -EINVAL;
521519
}
@@ -671,6 +669,8 @@ static int eq_fir_copy(struct comp_dev *dev)
671669
static int eq_fir_prepare(struct comp_dev *dev)
672670
{
673671
struct comp_data *cd = comp_get_drvdata(dev);
672+
struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
673+
struct comp_buffer *sourceb, *sinkb;
674674
int ret;
675675

676676
trace_eq("pre");
@@ -679,6 +679,26 @@ static int eq_fir_prepare(struct comp_dev *dev)
679679
if (ret < 0)
680680
return ret;
681681

682+
/* EQ components will only ever have 1 source and 1 sink buffer */
683+
sourceb = list_first_item(&dev->bsource_list,
684+
struct comp_buffer, sink_list);
685+
sinkb = list_first_item(&dev->bsink_list,
686+
struct comp_buffer, source_list);
687+
688+
/* set period bytes and frame format */
689+
comp_set_period_bytes(sourceb->source, dev->frames,
690+
&dev->params.frame_fmt, &cd->period_bytes);
691+
692+
/* rewrite frame_bytes for all downstream */
693+
dev->frame_bytes = cd->period_bytes / dev->frames;
694+
695+
/* set downstream buffer size */
696+
ret = buffer_set_size(sinkb, cd->period_bytes * config->periods_sink);
697+
if (ret < 0) {
698+
trace_eq_error("ef0");
699+
return ret;
700+
}
701+
682702
/* Initialize EQ */
683703
if (cd->config) {
684704
ret = eq_fir_setup(cd, dev->params.channels);

src/audio/eq_iir.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static int iir_cmd_set_data(struct comp_dev *dev,
480480
int ret = 0;
481481

482482
/* Check version from ABI header */
483-
if (cdata->data->comp_abi != SOF_EQ_IIR_ABI_VERSION) {
483+
if (cdata->data->comp_abi != SOF_ABI_VERSION) {
484484
trace_eq_error("eab");
485485
return -EINVAL;
486486
}
@@ -635,6 +635,7 @@ static int eq_iir_prepare(struct comp_dev *dev)
635635
{
636636
struct comp_data *cd = comp_get_drvdata(dev);
637637
struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
638+
struct comp_buffer *sourceb, *sinkb;
638639
int ret;
639640

640641
trace_eq("pre");
@@ -643,14 +644,34 @@ static int eq_iir_prepare(struct comp_dev *dev)
643644
if (ret < 0)
644645
return ret;
645646

647+
/* EQ components will only ever have 1 source and 1 sink buffer */
648+
sourceb = list_first_item(&dev->bsource_list,
649+
struct comp_buffer, sink_list);
650+
sinkb = list_first_item(&dev->bsink_list,
651+
struct comp_buffer, source_list);
652+
653+
/* set period bytes and frame format */
654+
comp_set_period_bytes(sourceb->source, dev->frames,
655+
&dev->params.frame_fmt, &cd->period_bytes);
656+
657+
/* rewrite frame_bytes for all downstream */
658+
dev->frame_bytes = cd->period_bytes / dev->frames;
659+
660+
/* set downstream buffer size */
661+
ret = buffer_set_size(sinkb, cd->period_bytes * config->periods_sink);
662+
if (ret < 0) {
663+
trace_eq_error("ef0");
664+
return ret;
665+
}
666+
646667
/* Initialize EQ */
647668
if (cd->config) {
648669
ret = eq_iir_setup(cd, dev->params.channels);
649670
if (ret < 0) {
650671
comp_set_state(dev, COMP_TRIGGER_RESET);
651672
return ret;
652673
}
653-
switch (config->frame_fmt) {
674+
switch (dev->params.frame_fmt) {
654675
case SOF_IPC_FRAME_S16_LE:
655676
trace_eq("i16");
656677
cd->eq_iir_func = eq_iir_s16_default;
@@ -668,7 +689,7 @@ static int eq_iir_prepare(struct comp_dev *dev)
668689
return -EINVAL;
669690
}
670691
} else {
671-
switch (config->frame_fmt) {
692+
switch (dev->params.frame_fmt) {
672693
case SOF_IPC_FRAME_S16_LE:
673694
trace_eq("p16");
674695
cd->eq_iir_func = eq_iir_s16_passthrough;

src/audio/volume.c

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ static int volume_prepare(struct comp_dev *dev)
488488
struct comp_data *cd = comp_get_drvdata(dev);
489489
struct comp_buffer *sinkb;
490490
struct comp_buffer *sourceb;
491-
struct sof_ipc_comp_config *sconfig;
492491
struct sof_ipc_comp_config *config = COMP_GET_CONFIG(dev);
493492
int i;
494493
int ret;
@@ -506,44 +505,13 @@ static int volume_prepare(struct comp_dev *dev)
506505
struct comp_buffer, source_list);
507506

508507
/* get source data format */
509-
switch (sourceb->source->comp.type) {
510-
case SOF_COMP_HOST:
511-
case SOF_COMP_SG_HOST:
512-
/* source format comes from IPC params */
513-
cd->source_format = sourceb->source->params.frame_fmt;
514-
cd->source_period_bytes = dev->frames *
515-
comp_frame_bytes(sourceb->source);
516-
break;
517-
case SOF_COMP_DAI:
518-
case SOF_COMP_SG_DAI:
519-
default:
520-
/* source format comes from DAI/comp config */
521-
sconfig = COMP_GET_CONFIG(sourceb->source);
522-
cd->source_format = sconfig->frame_fmt;
523-
cd->source_period_bytes = dev->frames *
524-
comp_frame_bytes(sourceb->source);
525-
break;
526-
}
508+
comp_set_period_bytes(sourceb->source, dev->frames, &cd->source_format,
509+
&cd->source_period_bytes);
527510

528511
/* get sink data format */
529-
switch (sinkb->sink->comp.type) {
530-
case SOF_COMP_HOST:
531-
case SOF_COMP_SG_HOST:
532-
/* sink format come from IPC params */
533-
cd->sink_format = sinkb->sink->params.frame_fmt;
534-
cd->sink_period_bytes = dev->frames *
535-
comp_frame_bytes(sinkb->sink);
536-
break;
537-
case SOF_COMP_DAI:
538-
case SOF_COMP_SG_DAI:
539-
default:
540-
/* sink format comes from DAI/comp config */
541-
sconfig = COMP_GET_CONFIG(sinkb->sink);
542-
cd->sink_format = sconfig->frame_fmt;
543-
cd->sink_period_bytes = dev->frames *
544-
comp_frame_bytes(sinkb->sink);
545-
break;
546-
}
512+
comp_set_period_bytes(sinkb->sink, dev->frames, &cd->sink_format,
513+
&cd->sink_period_bytes);
514+
547515
/* rewrite params format for all downstream */
548516
dev->params.frame_fmt = cd->sink_format;
549517

src/include/sof/audio/component.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ static inline void comp_free(struct comp_dev *dev)
258258
/* component state set */
259259
int comp_set_state(struct comp_dev *dev, int cmd);
260260

261+
/* component set period bytes */
262+
void comp_set_period_bytes(struct comp_dev *dev, uint32_t frames,
263+
enum sof_ipc_frame *format, uint32_t *period_bytes);
264+
261265
/* component parameter init - mandatory */
262266
static inline int comp_params(struct comp_dev *dev)
263267
{

src/include/uapi/eq.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333

3434
/* FIR EQ type */
3535

36-
/* Component will reject non-matching configuration. The version number need
37-
* to be incremented with any ABI changes in function fir_cmd().
38-
*/
39-
#define SOF_EQ_FIR_ABI_VERSION 1
40-
4136
#define SOF_EQ_FIR_IDX_SWITCH 0
4237

4338
#define SOF_EQ_FIR_MAX_SIZE 4096 /* Max size allowed for coef data in bytes */
@@ -97,11 +92,6 @@ struct sof_eq_fir_coef_data {
9792

9893
/* IIR EQ type */
9994

100-
/* Component will reject non-matching configuration. The version number need
101-
* to be incremented with any ABI changes in function fir_cmd().
102-
*/
103-
#define SOF_EQ_IIR_ABI_VERSION 1
104-
10595
#define SOF_EQ_IIR_IDX_SWITCH 0
10696

10797
#define SOF_EQ_IIR_MAX_SIZE 1024 /* Max size allowed for coef data in bytes */

0 commit comments

Comments
 (0)