Skip to content

Commit 23c7a52

Browse files
committed
igo_nr: compute circular buffer ends in samples not bytes
The processing buffers' end pointers were computed by adding a byte count to sample-typed pointers, placing the end past the real buffer and letting the wrap check pass too late. Convert the byte sizes to element counts when computing the ends. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 1405669 commit 23c7a52

1 file changed

Lines changed: 36 additions & 21 deletions

File tree

src/audio/igo_nr/igo_nr.c

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ static int igo_nr_capture_s16(struct comp_data *cd,
6969
struct sof_sink *sink,
7070
int32_t frames)
7171
{
72-
int16_t *x, *y1, *y2;
73-
int16_t *x_start, *y_start, *x_end, *y_end;
72+
int16_t const *x, *x_start, *x_end;
73+
int16_t *y1, *y2, *y_start, *y_end;
7474
int16_t sample;
75-
size_t x_size, y_size;
75+
int x_size, y_size;
7676
size_t request_size = frames * source_get_frame_bytes(source);
7777
int sink_samples_without_wrap;
7878
int samples_without_wrap;
@@ -93,12 +93,14 @@ static int igo_nr_capture_s16(struct comp_data *cd,
9393

9494
#endif
9595

96-
ret = source_get_data(source, request_size, (void const **)&x,
97-
(void const **)&x_start, &x_size);
96+
/* use the sample-count source/sink accessors so the returned sizes are
97+
* already in samples and need no byte-to-element conversion
98+
*/
99+
ret = source_get_data_s16(source, request_size, &x, &x_start, &x_size);
98100
if (ret)
99101
return ret;
100102

101-
ret = sink_get_buffer(sink, request_size, (void **)&y1, (void **)&y_start, &y_size);
103+
ret = sink_get_buffer_s16(sink, request_size, &y1, &y_start, &y_size);
102104
if (ret) {
103105
source_release_data(source, 0);
104106
return ret;
@@ -130,7 +132,10 @@ static int igo_nr_capture_s16(struct comp_data *cd,
130132
i++;
131133
}
132134

133-
x = cir_buf_wrap(x, x_start, x_end);
135+
/* x is const (read-only source), so wrap manually instead of
136+
* cir_buf_wrap() which takes a non-const void *
137+
*/
138+
x = (x >= x_end) ? x - x_size : x;
134139
y1 = cir_buf_wrap(y1, y_start, y_end);
135140
samples_left -= samples_without_wrap;
136141
}
@@ -172,9 +177,9 @@ static int igo_nr_capture_s24(struct comp_data *cd,
172177
struct sof_sink *sink,
173178
int32_t frames)
174179
{
175-
int32_t *x, *y1, *y2;
176-
int32_t *x_start, *y_start, *x_end, *y_end;
177-
size_t x_size, y_size;
180+
int32_t const *x, *x_start, *x_end;
181+
int32_t *y1, *y2, *y_start, *y_end;
182+
int x_size, y_size;
178183
size_t request_size = frames * source_get_frame_bytes(source);
179184
int sink_samples_without_wrap;
180185
int samples_without_wrap;
@@ -195,12 +200,14 @@ static int igo_nr_capture_s24(struct comp_data *cd,
195200

196201
#endif
197202

198-
ret = source_get_data(source, request_size, (void const **)&x,
199-
(void const **)&x_start, &x_size);
203+
/* use the sample-count source/sink accessors so the returned sizes are
204+
* already in samples and need no byte-to-element conversion
205+
*/
206+
ret = source_get_data_s32(source, request_size, &x, &x_start, &x_size);
200207
if (ret)
201208
return ret;
202209

203-
ret = sink_get_buffer(sink, request_size, (void **)&y1, (void **)&y_start, &y_size);
210+
ret = sink_get_buffer_s32(sink, request_size, &y1, &y_start, &y_size);
204211
if (ret) {
205212
source_release_data(source, 0);
206213
return ret;
@@ -231,7 +238,10 @@ static int igo_nr_capture_s24(struct comp_data *cd,
231238
i++;
232239
}
233240

234-
x = cir_buf_wrap(x, x_start, x_end);
241+
/* x is const (read-only source), so wrap manually instead of
242+
* cir_buf_wrap() which takes a non-const void *
243+
*/
244+
x = (x >= x_end) ? x - x_size : x;
235245
y1 = cir_buf_wrap(y1, y_start, y_end);
236246
samples_left -= samples_without_wrap;
237247
}
@@ -273,9 +283,9 @@ static int igo_nr_capture_s32(struct comp_data *cd,
273283
struct sof_sink *sink,
274284
int32_t frames)
275285
{
276-
int32_t *x, *y1, *y2;
277-
int32_t *x_start, *y_start, *x_end, *y_end;
278-
size_t x_size, y_size;
286+
int32_t const *x, *x_start, *x_end;
287+
int32_t *y1, *y2, *y_start, *y_end;
288+
int x_size, y_size;
279289
size_t request_size = frames * source_get_frame_bytes(source);
280290
int sink_samples_without_wrap;
281291
int samples_without_wrap;
@@ -296,12 +306,14 @@ static int igo_nr_capture_s32(struct comp_data *cd,
296306

297307
#endif
298308

299-
ret = source_get_data(source, request_size, (void const **)&x,
300-
(void const **)&x_start, &x_size);
309+
/* use the sample-count source/sink accessors so the returned sizes are
310+
* already in samples and need no byte-to-element conversion
311+
*/
312+
ret = source_get_data_s32(source, request_size, &x, &x_start, &x_size);
301313
if (ret)
302314
return ret;
303315

304-
ret = sink_get_buffer(sink, request_size, (void **)&y1, (void **)&y_start, &y_size);
316+
ret = sink_get_buffer_s32(sink, request_size, &y1, &y_start, &y_size);
305317
if (ret) {
306318
source_release_data(source, 0);
307319
return ret;
@@ -332,7 +344,10 @@ static int igo_nr_capture_s32(struct comp_data *cd,
332344
i++;
333345
}
334346

335-
x = cir_buf_wrap(x, x_start, x_end);
347+
/* x is const (read-only source), so wrap manually instead of
348+
* cir_buf_wrap() which takes a non-const void *
349+
*/
350+
x = (x >= x_end) ? x - x_size : x;
336351
y1 = cir_buf_wrap(y1, y_start, y_end);
337352
samples_left -= samples_without_wrap;
338353
}

0 commit comments

Comments
 (0)