Skip to content

Commit d7b36bf

Browse files
singalsulgirdwood
authored andcommitted
FIR EQ: Add support for timer based scheduling
This patch adds to copy() function capability to handle any number of frames with circular source and sink buffers. The number of frames to process is retrieved with new helper function comp_get_copy_limits(). Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent ddc383e commit d7b36bf

2 files changed

Lines changed: 47 additions & 51 deletions

File tree

‎src/audio/eq_fir.c‎

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
struct comp_data {
6363
struct fir_state_32x16 fir[PLATFORM_MAX_CHANNELS]; /**< filters state */
6464
struct sof_eq_fir_config *config; /**< pointer to setup blob */
65-
uint32_t period_bytes;
6665
enum sof_ipc_frame source_format; /**< source frame format */
6766
enum sof_ipc_frame sink_format; /**< sink frame format */
6867
int32_t *fir_delay; /**< pointer to allocated RAM */
@@ -173,23 +172,33 @@ static void eq_fir_s16_passthrough(struct fir_state_32x16 fir[],
173172
struct comp_buffer *sink,
174173
int frames, int nch)
175174
{
176-
int16_t *src = (int16_t *)source->r_ptr;
177-
int16_t *dest = (int16_t *)sink->w_ptr;
175+
int16_t *x;
176+
int16_t *y;
177+
int i;
178178
int n = frames * nch;
179179

180-
memcpy(dest, src, n * sizeof(int16_t));
180+
for (i = 0; i < n; i++) {
181+
x = buffer_read_frag_s16(source, i);
182+
y = buffer_write_frag_s16(sink, i);
183+
*y = *x;
184+
}
181185
}
182186

183187
static void eq_fir_s32_passthrough(struct fir_state_32x16 fir[],
184188
struct comp_buffer *source,
185189
struct comp_buffer *sink,
186190
int frames, int nch)
187191
{
188-
int32_t *src = (int32_t *)source->r_ptr;
189-
int32_t *dest = (int32_t *)sink->w_ptr;
192+
int32_t *x;
193+
int32_t *y;
194+
int i;
190195
int n = frames * nch;
191196

192-
memcpy(dest, src, n * sizeof(int32_t));
197+
for (i = 0; i < n; i++) {
198+
x = buffer_read_frag_s32(source, i);
199+
y = buffer_write_frag_s32(sink, i);
200+
*y = *x;
201+
}
193202
}
194203

195204
/* Function to select pass-trough depending on PCM format */
@@ -663,42 +672,32 @@ static int eq_fir_trigger(struct comp_dev *dev, int cmd)
663672
/* copy and process stream data from source to sink buffers */
664673
static int eq_fir_copy(struct comp_dev *dev)
665674
{
666-
struct comp_data *sd = comp_get_drvdata(dev);
667-
struct comp_buffer *source;
668-
struct comp_buffer *sink;
669-
int res;
675+
struct comp_copy_limits cl;
676+
struct comp_data *cd = comp_get_drvdata(dev);
677+
int ret;
678+
struct fir_state_32x16 *fir = cd->fir;
670679
int nch = dev->params.channels;
671-
struct fir_state_32x16 *fir = sd->fir;
672680

673681
tracev_comp("eq_fir_copy()");
674682

675-
/* get source and sink buffers */
676-
source = list_first_item(&dev->bsource_list, struct comp_buffer,
677-
sink_list);
678-
sink = list_first_item(&dev->bsink_list, struct comp_buffer,
679-
source_list);
680-
681-
/* make sure source component buffer has enough data available and that
682-
* the sink component buffer has enough free bytes for copy. Also
683-
* check for XRUNs.
684-
*/
685-
res = comp_buffer_can_copy_bytes(source, sink, sd->period_bytes);
686-
if (res) {
687-
trace_eq_error("eq_fir_copy() error: "
688-
"comp_buffer_can_copy_bytes() failed");
689-
return -EIO; /* xrun */
683+
/* Get source, sink, number of frames etc. to process. */
684+
ret = comp_get_copy_limits(dev, &cl);
685+
if (ret < 0) {
686+
trace_eq_error("eq_fir_copy(): Failed comp_get_copy_limits()");
687+
return ret;
690688
}
691689

692-
if (dev->frames & 1)
693-
sd->eq_fir_func(fir, source, sink, dev->frames, nch);
690+
/* Run EQ function */
691+
if (cl.frames & 1)
692+
cd->eq_fir_func(fir, cl.source, cl.sink, cl.frames, nch);
694693
else
695-
sd->eq_fir_func_even(fir, source, sink, dev->frames, nch);
694+
cd->eq_fir_func_even(fir, cl.source, cl.sink, cl.frames, nch);
696695

697696
/* calc new free and available */
698-
comp_update_buffer_consume(source, sd->period_bytes);
699-
comp_update_buffer_produce(sink, sd->period_bytes);
697+
comp_update_buffer_consume(cl.source, cl.source_bytes);
698+
comp_update_buffer_produce(cl.sink, cl.sink_bytes);
700699

701-
return dev->frames;
700+
return 0;
702701
}
703702

704703
static int eq_fir_prepare(struct comp_dev *dev)

‎src/audio/fir.c‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,22 @@ void eq_fir_s16(struct fir_state_32x16 fir[], struct comp_buffer *source,
8585
struct comp_buffer *sink, int frames, int nch)
8686
{
8787
struct fir_state_32x16 *filter;
88-
int16_t *src = (int16_t *)source->r_ptr;
89-
int16_t *snk = (int16_t *)sink->w_ptr;
9088
int16_t *x;
9189
int16_t *y;
9290
int32_t z;
91+
int idx;
9392
int ch;
9493
int i;
9594

9695
for (ch = 0; ch < nch; ch++) {
9796
filter = &fir[ch];
98-
x = src++;
99-
y = snk++;
97+
idx = ch;
10098
for (i = 0; i < frames; i++) {
99+
x = buffer_read_frag_s16(source, idx);
100+
y = buffer_write_frag_s16(sink, idx);
101101
z = fir_32x16(filter, *x << 16);
102102
*y = sat_int16(Q_SHIFT_RND(z, 31, 15));
103-
x += nch;
104-
y += nch;
103+
idx += nch;
105104
}
106105
}
107106
}
@@ -110,23 +109,22 @@ void eq_fir_s24(struct fir_state_32x16 fir[], struct comp_buffer *source,
110109
struct comp_buffer *sink, int frames, int nch)
111110
{
112111
struct fir_state_32x16 *filter;
113-
int32_t *src = (int32_t *)source->r_ptr;
114-
int32_t *snk = (int32_t *)sink->w_ptr;
115112
int32_t *x;
116113
int32_t *y;
117114
int32_t z;
115+
int idx;
118116
int ch;
119117
int i;
120118

121119
for (ch = 0; ch < nch; ch++) {
122120
filter = &fir[ch];
123-
x = src++;
124-
y = snk++;
121+
idx = ch;
125122
for (i = 0; i < frames; i++) {
123+
x = buffer_read_frag_s32(source, idx);
124+
y = buffer_write_frag_s32(sink, idx);
126125
z = fir_32x16(filter, *x << 8);
127126
*y = sat_int24(Q_SHIFT_RND(z, 31, 23));
128-
x += nch;
129-
y += nch;
127+
idx += nch;
130128
}
131129
}
132130
}
@@ -135,21 +133,20 @@ void eq_fir_s32(struct fir_state_32x16 fir[], struct comp_buffer *source,
135133
struct comp_buffer *sink, int frames, int nch)
136134
{
137135
struct fir_state_32x16 *filter;
138-
int32_t *src = (int32_t *)source->r_ptr;
139-
int32_t *snk = (int32_t *)sink->w_ptr;
140136
int32_t *x;
141137
int32_t *y;
138+
int idx;
142139
int ch;
143140
int i;
144141

145142
for (ch = 0; ch < nch; ch++) {
146143
filter = &fir[ch];
147-
x = src++;
148-
y = snk++;
144+
idx = ch;
149145
for (i = 0; i < frames; i++) {
146+
x = buffer_read_frag_s32(source, idx);
147+
y = buffer_write_frag_s32(sink, idx);
150148
*y = fir_32x16(filter, *x);
151-
x += nch;
152-
y += nch;
149+
idx += nch;
153150
}
154151
}
155152
}

0 commit comments

Comments
 (0)