diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-03 15:15:44 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-12-22 17:20:14 -0500 |
commit | b96b7640de381757c5ceac182e01bc84f668e64a (patch) | |
tree | 28480994531e0e6563c5dec34affd69e2adcdeac | |
parent | 646d5f92ef966bfaae288becd8774953d3703f5f (diff) | |
download | rockbox-b96b7640de381757c5ceac182e01bc84f668e64a.tar.gz rockbox-b96b7640de381757c5ceac182e01bc84f668e64a.zip |
rbcodec dsp: Move dsp_sample_io_configure() to its own file
Makes dsp_sample_input.c a bit less messy, and dependencies
are more explicit. There's possibly a minor loss of inlining
but it isn't a big deal.
Change-Id: I30f923a0ca758f2b113d32852d1f65586dff0cd1
-rw-r--r-- | lib/rbcodec/SOURCES | 1 | ||||
-rw-r--r-- | lib/rbcodec/dsp/dsp_sample_input.c | 106 | ||||
-rw-r--r-- | lib/rbcodec/dsp/dsp_sample_io.c | 116 | ||||
-rw-r--r-- | lib/rbcodec/dsp/dsp_sample_io.h | 4 | ||||
-rw-r--r-- | lib/rbcodec/platform.h | 5 |
5 files changed, 129 insertions, 103 deletions
diff --git a/lib/rbcodec/SOURCES b/lib/rbcodec/SOURCES index b0efebc989..28097e9f49 100644 --- a/lib/rbcodec/SOURCES +++ b/lib/rbcodec/SOURCES | |||
@@ -11,6 +11,7 @@ dsp/afr.c | |||
11 | dsp/surround.c | 11 | dsp/surround.c |
12 | dsp/dsp_filter.c | 12 | dsp/dsp_filter.c |
13 | dsp/dsp_misc.c | 13 | dsp/dsp_misc.c |
14 | dsp/dsp_sample_io.c | ||
14 | dsp/dsp_sample_input.c | 15 | dsp/dsp_sample_input.c |
15 | dsp/dsp_sample_output.c | 16 | dsp/dsp_sample_output.c |
16 | dsp/eq.c | 17 | dsp/eq.c |
diff --git a/lib/rbcodec/dsp/dsp_sample_input.c b/lib/rbcodec/dsp/dsp_sample_input.c index c57f81bb4f..8068ce5097 100644 --- a/lib/rbcodec/dsp/dsp_sample_input.c +++ b/lib/rbcodec/dsp/dsp_sample_input.c | |||
@@ -49,11 +49,6 @@ | |||
49 | * behave. | 49 | * behave. |
50 | */ | 50 | */ |
51 | 51 | ||
52 | extern void dsp_sample_output_init(struct sample_io_data *this); | ||
53 | extern void dsp_sample_output_flush(struct sample_io_data *this); | ||
54 | extern void dsp_sample_output_format_change(struct sample_io_data *this, | ||
55 | struct sample_format *format); | ||
56 | |||
57 | #define SAMPLE_BUF_COUNT 128 /* Per channel, per DSP */ | 52 | #define SAMPLE_BUF_COUNT 128 /* Per channel, per DSP */ |
58 | /* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */ | 53 | /* CODEC_IDX_AUDIO = left and right, CODEC_IDX_VOICE = mono */ |
59 | static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR; | 54 | static int32_t sample_bufs[3][SAMPLE_BUF_COUNT] IBSS_ATTR; |
@@ -241,24 +236,14 @@ void dsp_sample_input_format_change(struct sample_io_data *this, | |||
241 | [this->sample_depth > NATIVE_DEPTH ? 1 : 0]; | 236 | [this->sample_depth > NATIVE_DEPTH ? 1 : 0]; |
242 | } | 237 | } |
243 | 238 | ||
244 | /* increment the format version counter */ | ||
245 | static void format_change_set(struct sample_io_data *this) | ||
246 | { | ||
247 | if (this->format_dirty) | ||
248 | return; | ||
249 | |||
250 | this->format.version = (uint8_t)(this->format.version + 1) ?: 1; | ||
251 | this->format_dirty = 1; | ||
252 | } | ||
253 | |||
254 | /* discard the sample buffer */ | 239 | /* discard the sample buffer */ |
255 | static void dsp_sample_input_flush(struct sample_io_data *this) | 240 | void dsp_sample_input_flush(struct sample_io_data *this) |
256 | { | 241 | { |
257 | this->sample_buf.remcount = 0; | 242 | this->sample_buf.remcount = 0; |
258 | } | 243 | } |
259 | 244 | ||
260 | static void dsp_sample_input_init(struct sample_io_data *this, | 245 | void dsp_sample_input_init(struct sample_io_data *this, |
261 | enum dsp_ids dsp_id) | 246 | enum dsp_ids dsp_id) |
262 | { | 247 | { |
263 | int32_t *lbuf, *rbuf; | 248 | int32_t *lbuf, *rbuf; |
264 | 249 | ||
@@ -282,88 +267,3 @@ static void dsp_sample_input_init(struct sample_io_data *this, | |||
282 | this->sample_buf_p[0] = lbuf; | 267 | this->sample_buf_p[0] = lbuf; |
283 | this->sample_buf_p[1] = rbuf; | 268 | this->sample_buf_p[1] = rbuf; |
284 | } | 269 | } |
285 | |||
286 | static void dsp_sample_io_init(struct sample_io_data *this, | ||
287 | enum dsp_ids dsp_id) | ||
288 | { | ||
289 | this->output_sampr = DSP_OUT_DEFAULT_HZ; | ||
290 | dsp_sample_input_init(this, dsp_id); | ||
291 | dsp_sample_output_init(this); | ||
292 | } | ||
293 | |||
294 | bool dsp_sample_io_configure(struct sample_io_data *this, | ||
295 | unsigned int setting, | ||
296 | intptr_t *value_p) | ||
297 | { | ||
298 | intptr_t value = *value_p; | ||
299 | |||
300 | switch (setting) | ||
301 | { | ||
302 | case DSP_INIT: | ||
303 | dsp_sample_io_init(this, (enum dsp_ids)value); | ||
304 | break; | ||
305 | |||
306 | case DSP_RESET: | ||
307 | /* Reset all sample descriptions to default */ | ||
308 | format_change_set(this); | ||
309 | this->format.num_channels = 2; | ||
310 | this->format.frac_bits = WORD_FRACBITS; | ||
311 | this->format.output_scale = WORD_FRACBITS + 1 - NATIVE_DEPTH; | ||
312 | this->format.frequency = this->output_sampr; | ||
313 | this->format.codec_frequency = this->output_sampr; | ||
314 | this->sample_depth = NATIVE_DEPTH; | ||
315 | this->stereo_mode = STEREO_NONINTERLEAVED; | ||
316 | break; | ||
317 | |||
318 | case DSP_SET_FREQUENCY: | ||
319 | format_change_set(this); | ||
320 | value = value > 0 ? (unsigned int)value : this->output_sampr; | ||
321 | this->format.frequency = value; | ||
322 | this->format.codec_frequency = value; | ||
323 | break; | ||
324 | |||
325 | case DSP_SET_SAMPLE_DEPTH: | ||
326 | format_change_set(this); | ||
327 | this->format.frac_bits = | ||
328 | value <= NATIVE_DEPTH ? WORD_FRACBITS : value; | ||
329 | this->format.output_scale = | ||
330 | this->format.frac_bits + 1 - NATIVE_DEPTH; | ||
331 | this->sample_depth = value; | ||
332 | break; | ||
333 | |||
334 | case DSP_SET_STEREO_MODE: | ||
335 | format_change_set(this); | ||
336 | this->format.num_channels = value == STEREO_MONO ? 1 : 2; | ||
337 | this->stereo_mode = value; | ||
338 | break; | ||
339 | |||
340 | case DSP_FLUSH: | ||
341 | dsp_sample_input_flush(this); | ||
342 | dsp_sample_output_flush(this); | ||
343 | break; | ||
344 | |||
345 | case DSP_SET_PITCH: | ||
346 | format_change_set(this); | ||
347 | value = value > 0 ? value : (1 << 16); | ||
348 | this->format.frequency = | ||
349 | fp_mul(value, this->format.codec_frequency, 16); | ||
350 | break; | ||
351 | |||
352 | case DSP_SET_OUT_FREQUENCY: | ||
353 | value = value > 0 ? value : DSP_OUT_DEFAULT_HZ; | ||
354 | value = MIN(DSP_OUT_MAX_HZ, MAX(DSP_OUT_MIN_HZ, value)); | ||
355 | *value_p = value; | ||
356 | |||
357 | if ((unsigned int)value == this->output_sampr) | ||
358 | return true; /* No change; don't broadcast */ | ||
359 | |||
360 | this->output_sampr = value; | ||
361 | break; | ||
362 | |||
363 | case DSP_GET_OUT_FREQUENCY: | ||
364 | *value_p = this->output_sampr; | ||
365 | return true; /* Only I/O handles it */ | ||
366 | } | ||
367 | |||
368 | return false; | ||
369 | } | ||
diff --git a/lib/rbcodec/dsp/dsp_sample_io.c b/lib/rbcodec/dsp/dsp_sample_io.c new file mode 100644 index 0000000000..637d41a918 --- /dev/null +++ b/lib/rbcodec/dsp/dsp_sample_io.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 Miika Pekkarinen | ||
11 | * Copyright (C) 2012 Michael Sevakis | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | #include "rbcodecconfig.h" | ||
23 | #include "platform.h" | ||
24 | #include "dsp_core.h" | ||
25 | #include "dsp_sample_io.h" | ||
26 | #include "dsp_proc_entry.h" | ||
27 | #include "fixedpoint.h" | ||
28 | |||
29 | /* increment the format version counter */ | ||
30 | static void format_change_set(struct sample_io_data *this) | ||
31 | { | ||
32 | if (this->format_dirty) | ||
33 | return; | ||
34 | |||
35 | this->format.version = (uint8_t)(this->format.version + 1) ?: 1; | ||
36 | this->format_dirty = 1; | ||
37 | } | ||
38 | |||
39 | bool dsp_sample_io_configure(struct sample_io_data *this, | ||
40 | unsigned int setting, | ||
41 | intptr_t *value_p) | ||
42 | { | ||
43 | intptr_t value = *value_p; | ||
44 | |||
45 | switch (setting) | ||
46 | { | ||
47 | case DSP_INIT: | ||
48 | this->output_sampr = DSP_OUT_DEFAULT_HZ; | ||
49 | dsp_sample_input_init(this, (enum dsp_ids)value); | ||
50 | dsp_sample_output_init(this); | ||
51 | break; | ||
52 | |||
53 | case DSP_RESET: | ||
54 | /* Reset all sample descriptions to default */ | ||
55 | format_change_set(this); | ||
56 | this->format.num_channels = 2; | ||
57 | this->format.frac_bits = WORD_FRACBITS; | ||
58 | this->format.output_scale = WORD_FRACBITS + 1 - NATIVE_DEPTH; | ||
59 | this->format.frequency = this->output_sampr; | ||
60 | this->format.codec_frequency = this->output_sampr; | ||
61 | this->sample_depth = NATIVE_DEPTH; | ||
62 | this->stereo_mode = STEREO_NONINTERLEAVED; | ||
63 | break; | ||
64 | |||
65 | case DSP_SET_FREQUENCY: | ||
66 | format_change_set(this); | ||
67 | value = value > 0 ? (unsigned int)value : this->output_sampr; | ||
68 | this->format.frequency = value; | ||
69 | this->format.codec_frequency = value; | ||
70 | break; | ||
71 | |||
72 | case DSP_SET_SAMPLE_DEPTH: | ||
73 | format_change_set(this); | ||
74 | this->format.frac_bits = | ||
75 | value <= NATIVE_DEPTH ? WORD_FRACBITS : value; | ||
76 | this->format.output_scale = | ||
77 | this->format.frac_bits + 1 - NATIVE_DEPTH; | ||
78 | this->sample_depth = value; | ||
79 | break; | ||
80 | |||
81 | case DSP_SET_STEREO_MODE: | ||
82 | format_change_set(this); | ||
83 | this->format.num_channels = value == STEREO_MONO ? 1 : 2; | ||
84 | this->stereo_mode = value; | ||
85 | break; | ||
86 | |||
87 | case DSP_FLUSH: | ||
88 | dsp_sample_input_flush(this); | ||
89 | dsp_sample_output_flush(this); | ||
90 | break; | ||
91 | |||
92 | case DSP_SET_PITCH: | ||
93 | format_change_set(this); | ||
94 | value = value > 0 ? value : (1 << 16); | ||
95 | this->format.frequency = | ||
96 | fp_mul(value, this->format.codec_frequency, 16); | ||
97 | break; | ||
98 | |||
99 | case DSP_SET_OUT_FREQUENCY: | ||
100 | value = value > 0 ? value : DSP_OUT_DEFAULT_HZ; | ||
101 | value = MIN(DSP_OUT_MAX_HZ, MAX(DSP_OUT_MIN_HZ, value)); | ||
102 | *value_p = value; | ||
103 | |||
104 | if ((unsigned int)value == this->output_sampr) | ||
105 | return true; /* No change; don't broadcast */ | ||
106 | |||
107 | this->output_sampr = value; | ||
108 | break; | ||
109 | |||
110 | case DSP_GET_OUT_FREQUENCY: | ||
111 | *value_p = this->output_sampr; | ||
112 | return true; /* Only I/O handles it */ | ||
113 | } | ||
114 | |||
115 | return false; | ||
116 | } | ||
diff --git a/lib/rbcodec/dsp/dsp_sample_io.h b/lib/rbcodec/dsp/dsp_sample_io.h index 5117e04a3e..483f24112c 100644 --- a/lib/rbcodec/dsp/dsp_sample_io.h +++ b/lib/rbcodec/dsp/dsp_sample_io.h | |||
@@ -56,9 +56,13 @@ struct sample_io_data | |||
56 | uint8_t output_version; /* Format version of src buffer at output */ | 56 | uint8_t output_version; /* Format version of src buffer at output */ |
57 | }; | 57 | }; |
58 | 58 | ||
59 | void dsp_sample_input_init(struct sample_io_data *this, enum dsp_ids dsp_id); | ||
60 | void dsp_sample_input_flush(struct sample_io_data *this); | ||
59 | void dsp_sample_input_format_change(struct sample_io_data *this, | 61 | void dsp_sample_input_format_change(struct sample_io_data *this, |
60 | struct sample_format *format); | 62 | struct sample_format *format); |
61 | 63 | ||
64 | void dsp_sample_output_init(struct sample_io_data *this); | ||
65 | void dsp_sample_output_flush(struct sample_io_data *this); | ||
62 | void dsp_sample_output_format_change(struct sample_io_data *this, | 66 | void dsp_sample_output_format_change(struct sample_io_data *this, |
63 | struct sample_format *format); | 67 | struct sample_format *format); |
64 | 68 | ||
diff --git a/lib/rbcodec/platform.h b/lib/rbcodec/platform.h index d13380b795..d6b890599a 100644 --- a/lib/rbcodec/platform.h +++ b/lib/rbcodec/platform.h | |||
@@ -41,6 +41,11 @@ size_t strlcpy(char *dst, const char *src, size_t siz); | |||
41 | #ifndef INIT_ATTR | 41 | #ifndef INIT_ATTR |
42 | # define INIT_ATTR | 42 | # define INIT_ATTR |
43 | #endif | 43 | #endif |
44 | |||
45 | #ifndef INITDATA_ATTR | ||
46 | # define INITDATA_ATTR | ||
47 | #endif | ||
48 | |||
44 | /* | 49 | /* |
45 | #ifdef CODEC | 50 | #ifdef CODEC |
46 | 51 | ||