Skip to content

Commit 2583398

Browse files
ranj063lgirdwood
authored andcommitted
audio_format: Add macro for converting bytes <-> samples
And macros for converting bytes to samples and samples to bytes and use it in all components to avoid duplication. Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent 9d9ba73 commit 2583398

9 files changed

Lines changed: 82 additions & 93 deletions

File tree

src/audio/eq_iir/eq_iir.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ static void eq_iir_s24_default(struct processing_module *mod, struct input_strea
131131
const int samples = frames * nch;
132132
int processed = 0;
133133

134-
bsource->consumed += samples << 2;
135-
bsink->size += samples << 2;
134+
bsource->consumed += S32_SAMPLES_TO_BYTES(samples);
135+
bsink->size += S32_SAMPLES_TO_BYTES(samples);
136136

137137
x = source->r_ptr;
138138
y = sink->w_ptr;
@@ -182,8 +182,8 @@ static void eq_iir_s32_default(struct processing_module *mod, struct input_strea
182182
const int samples = frames * nch;
183183
int processed = 0;
184184

185-
bsource->consumed += samples << 2;
186-
bsink->size += samples << 2;
185+
bsource->consumed += S32_SAMPLES_TO_BYTES(samples);
186+
bsink->size += S32_SAMPLES_TO_BYTES(samples);
187187

188188
x = source->r_ptr;
189189
y = sink->w_ptr;
@@ -233,8 +233,8 @@ static void eq_iir_s32_16_default(struct processing_module *mod,
233233
const int samples = frames * nch;
234234
int processed = 0;
235235

236-
bsource->consumed += samples << 2;
237-
bsink->size += samples << 1;
236+
bsource->consumed += S32_SAMPLES_TO_BYTES(samples);
237+
bsink->size += S16_SAMPLES_TO_BYTES(samples);
238238

239239
x = source->r_ptr;
240240
y = sink->w_ptr;
@@ -284,8 +284,8 @@ static void eq_iir_s32_24_default(struct processing_module *mod,
284284
const int samples = frames * nch;
285285
int processed = 0;
286286

287-
bsource->consumed += samples << 2;
288-
bsink->size += samples << 2;
287+
bsource->consumed += S32_SAMPLES_TO_BYTES(samples);
288+
bsink->size += S32_SAMPLES_TO_BYTES(samples);
289289

290290
x = source->r_ptr;
291291
y = sink->w_ptr;
@@ -319,11 +319,11 @@ static void eq_iir_pass(struct processing_module *mod, struct input_stream_buffe
319319
struct audio_stream __sparse_cache *sink = bsink->data;
320320

321321
if (source->frame_fmt == SOF_IPC_FRAME_S16_LE) {
322-
bsource->consumed += (frames * source->channels) << 1;
323-
bsink->size += (frames * source->channels) << 1;
322+
bsource->consumed += S16_SAMPLES_TO_BYTES(frames * source->channels);
323+
bsink->size += S16_SAMPLES_TO_BYTES(frames * source->channels);
324324
} else {
325-
bsource->consumed += (frames * source->channels) << 2;
326-
bsink->size += (frames * source->channels) << 2;
325+
bsource->consumed += S32_SAMPLES_TO_BYTES(frames * source->channels);
326+
bsink->size += S32_SAMPLES_TO_BYTES(frames * source->channels);
327327
}
328328

329329
audio_stream_copy(source, 0, sink, 0, frames * source->channels);
@@ -342,13 +342,13 @@ static void eq_iir_s32_s16_pass(struct processing_module *mod, struct input_stre
342342
int i;
343343
int remaining_samples = frames * source->channels;
344344

345-
bsource->consumed += remaining_samples << 2;
346-
bsink->size += remaining_samples << 1;
345+
bsource->consumed += S32_SAMPLES_TO_BYTES(remaining_samples);
346+
bsink->size += S16_SAMPLES_TO_BYTES(remaining_samples);
347347

348348
while (remaining_samples) {
349-
nmax = EQ_IIR_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
349+
nmax = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
350350
n = MIN(remaining_samples, nmax);
351-
nmax = EQ_IIR_BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
351+
nmax = BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
352352
n = MIN(n, nmax);
353353
for (i = 0; i < n; i++) {
354354
*y = sat_int16(Q_SHIFT_RND(*x, 31, 15));
@@ -375,13 +375,13 @@ static void eq_iir_s32_s24_pass(struct processing_module *mod, struct input_stre
375375
int i;
376376
int remaining_samples = frames * source->channels;
377377

378-
bsource->consumed += remaining_samples << 2;
379-
bsink->size += remaining_samples << 2;
378+
bsource->consumed += S32_SAMPLES_TO_BYTES(remaining_samples);
379+
bsink->size += S32_SAMPLES_TO_BYTES(remaining_samples);
380380

381381
while (remaining_samples) {
382-
nmax = EQ_IIR_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
382+
nmax = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
383383
n = MIN(remaining_samples, nmax);
384-
nmax = EQ_IIR_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
384+
nmax = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
385385
n = MIN(n, nmax);
386386
for (i = 0; i < n; i++) {
387387
*y = sat_int24(Q_SHIFT_RND(*x, 31, 23));

src/audio/module_adapter/module/volume/volume.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static uint32_t vol_zc_get_s16(const struct audio_stream __sparse_cache *source,
8989
x = audio_stream_wrap(source, x + remaining_samples - 1); /* Go to last channel */
9090
while (remaining_samples) {
9191
bytes = audio_stream_rewind_bytes_without_wrap(source, x);
92-
nmax = VOL_BYTES_TO_S16_SAMPLES(bytes) + 1;
92+
nmax = BYTES_TO_S16_SAMPLES(bytes) + 1;
9393
n = MIN(nmax, remaining_samples);
9494
for (i = 0; i < n; i += nch) {
9595
sum = 0;
@@ -137,7 +137,7 @@ static uint32_t vol_zc_get_s24(const struct audio_stream __sparse_cache *source,
137137
x = audio_stream_wrap(source, x + remaining_samples - 1); /* Go to last channel */
138138
while (remaining_samples) {
139139
bytes = audio_stream_rewind_bytes_without_wrap(source, x);
140-
nmax = VOL_BYTES_TO_S32_SAMPLES(bytes) + 1;
140+
nmax = BYTES_TO_S32_SAMPLES(bytes) + 1;
141141
n = MIN(nmax, remaining_samples);
142142
for (i = 0; i < n; i += nch) {
143143
sum = 0;
@@ -185,7 +185,7 @@ static uint32_t vol_zc_get_s32(const struct audio_stream __sparse_cache *source,
185185
x = audio_stream_wrap(source, x + remaining_samples - 1); /* Go to last channel */
186186
while (remaining_samples) {
187187
bytes = audio_stream_rewind_bytes_without_wrap(source, x);
188-
nmax = VOL_BYTES_TO_S32_SAMPLES(bytes) + 1;
188+
nmax = BYTES_TO_S32_SAMPLES(bytes) + 1;
189189
n = MIN(nmax, remaining_samples);
190190
for (i = 0; i < n; i += nch) {
191191
sum = 0;

src/audio/module_adapter/module/volume/volume_generic.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ static void vol_s24_to_s24(struct processing_module *mod, struct input_stream_bu
7171
x = source->r_ptr;
7272
y = sink->w_ptr;
7373

74-
bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples);
75-
bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples);
74+
bsource->consumed += S32_SAMPLES_TO_BYTES(remaining_samples);
75+
bsink->size += S32_SAMPLES_TO_BYTES(remaining_samples);
7676
while (remaining_samples) {
77-
nmax = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
77+
nmax = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
7878
n = MIN(remaining_samples, nmax);
79-
nmax = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
79+
nmax = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
8080
n = MIN(n, nmax);
8181
for (j = 0; j < nch; j++) {
8282
x0 = x + j;
@@ -133,12 +133,12 @@ static void vol_s32_to_s32(struct processing_module *mod, struct input_stream_bu
133133

134134
x = source->r_ptr;
135135
y = sink->w_ptr;
136-
bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(remaining_samples);
137-
bsink->size += VOL_S32_SAMPLES_TO_BYTES(remaining_samples);
136+
bsource->consumed += S32_SAMPLES_TO_BYTES(remaining_samples);
137+
bsink->size += S32_SAMPLES_TO_BYTES(remaining_samples);
138138
while (remaining_samples) {
139-
nmax = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
139+
nmax = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, x));
140140
n = MIN(remaining_samples, nmax);
141-
nmax = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
141+
nmax = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
142142
n = MIN(n, nmax);
143143
/* Note: on Xtensa processing one channel volume at time performed slightly
144144
* better than simpler interleaved code version (average 19 us vs. 20 us).
@@ -201,12 +201,12 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
201201
x = source->r_ptr;
202202
y = sink->w_ptr;
203203

204-
bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(remaining_samples);
205-
bsink->size += VOL_S16_SAMPLES_TO_BYTES(remaining_samples);
204+
bsource->consumed += S16_SAMPLES_TO_BYTES(remaining_samples);
205+
bsink->size += S16_SAMPLES_TO_BYTES(remaining_samples);
206206
while (remaining_samples) {
207-
nmax = VOL_BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(source, x));
207+
nmax = BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(source, x));
208208
n = MIN(remaining_samples, nmax);
209-
nmax = VOL_BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
209+
nmax = BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(sink, y));
210210
n = MIN(n, nmax);
211211
for (j = 0; j < nch; j++) {
212212
x0 = x + j;

src/audio/module_adapter/module/volume/volume_hifi3.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ static void vol_s24_to_s24_s32(struct processing_module *mod, struct input_strea
9292
AE_SETCBEGIN0(buf);
9393
AE_SETCEND0(buf_end);
9494

95-
bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples);
96-
bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples);
95+
bsource->consumed += S32_SAMPLES_TO_BYTES(samples);
96+
bsink->size += S32_SAMPLES_TO_BYTES(samples);
9797

9898
while (samples) {
99-
m = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, in));
99+
m = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, in));
100100
n = MIN(m, samples);
101-
m = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, out));
101+
m = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, out));
102102
n = MIN(m, n);
103103
inu = AE_LA64_PP(in);
104104
/* process two continuous sample data once */
@@ -183,13 +183,13 @@ static void vol_s32_to_s24_s32(struct processing_module *mod, struct input_strea
183183
AE_SETCBEGIN0(buf);
184184
AE_SETCEND0(buf_end);
185185

186-
bsource->consumed += VOL_S32_SAMPLES_TO_BYTES(samples);
187-
bsink->size += VOL_S32_SAMPLES_TO_BYTES(samples);
186+
bsource->consumed += S32_SAMPLES_TO_BYTES(samples);
187+
bsink->size += S32_SAMPLES_TO_BYTES(samples);
188188

189189
while (samples) {
190-
m = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, in));
190+
m = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(source, in));
191191
n = MIN(m, samples);
192-
m = VOL_BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, out));
192+
m = BYTES_TO_S32_SAMPLES(audio_stream_bytes_without_wrap(sink, out));
193193
n = MIN(m, n);
194194
inu = AE_LA64_PP(in);
195195
/* process two continuous sample data once */
@@ -280,9 +280,9 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
280280
AE_SETCEND0(buf_end);
281281

282282
while (samples) {
283-
m = VOL_BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(source, in));
283+
m = BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(source, in));
284284
n = MIN(m, samples);
285-
m = VOL_BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(sink, out));
285+
m = BYTES_TO_S16_SAMPLES(audio_stream_bytes_without_wrap(sink, out));
286286
n = MIN(m, n);
287287
inu = AE_LA64_PP(in);
288288
for (i = 0; i < n; i += 4) {
@@ -324,8 +324,8 @@ static void vol_s16_to_s16(struct processing_module *mod, struct input_stream_bu
324324
}
325325
AE_SA64POS_FP(outu, out);
326326
samples -= n;
327-
bsource->consumed += VOL_S16_SAMPLES_TO_BYTES(n);
328-
bsink->size += VOL_S16_SAMPLES_TO_BYTES(n);
327+
bsource->consumed += S16_SAMPLES_TO_BYTES(n);
328+
bsink->size += S16_SAMPLES_TO_BYTES(n);
329329
in = audio_stream_wrap(source, in);
330330
out = audio_stream_wrap(sink, out);
331331
}

0 commit comments

Comments
 (0)