summaryrefslogtreecommitdiff
path: root/lib/rbcodec
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-12-03 15:33:15 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-12-23 12:47:10 -0500
commit6e794c9a2d9e91a926f70d0fcc66e255b0bdc221 (patch)
tree3a0d1371a0a259f2ed761e5db871064867b2a7ce /lib/rbcodec
parent34a092a99729dd4de014aa1f76c48660f28a9c97 (diff)
downloadrockbox-6e794c9a2d9e91a926f70d0fcc66e255b0bdc221.tar.gz
rockbox-6e794c9a2d9e91a926f70d0fcc66e255b0bdc221.zip
rbcodec dsp: Refactor DSP init routines, restore INIT_ATTR
Refactor DSP init routines so there is a dedicated init function for the stages that need it. Remove the DSP_INIT configure message. This allows the init code to be safely marked INIT_ATTR, saving a bit of code size, and allowing the linker to verify that there are no unsafe references to the init routines. Change-Id: I1702f0f579bbb300a6fe7d0e67b13aa2e9dd7f8a
Diffstat (limited to 'lib/rbcodec')
-rw-r--r--lib/rbcodec/dsp/dsp_core.c21
-rw-r--r--lib/rbcodec/dsp/dsp_core.h1
-rw-r--r--lib/rbcodec/dsp/dsp_misc.c11
-rw-r--r--lib/rbcodec/dsp/dsp_proc_entry.h2
-rw-r--r--lib/rbcodec/dsp/dsp_sample_io.c13
-rw-r--r--lib/rbcodec/dsp/dsp_sample_io.h5
-rw-r--r--lib/rbcodec/dsp/resample.c7
-rw-r--r--lib/rbcodec/dsp/resample.h26
-rw-r--r--lib/rbcodec/dsp/tdspeed.c10
-rw-r--r--lib/rbcodec/dsp/tdspeed.h1
10 files changed, 62 insertions, 35 deletions
diff --git a/lib/rbcodec/dsp/dsp_core.c b/lib/rbcodec/dsp/dsp_core.c
index 14bf228bd6..5108c9ef47 100644
--- a/lib/rbcodec/dsp/dsp_core.c
+++ b/lib/rbcodec/dsp/dsp_core.c
@@ -24,6 +24,9 @@
24#include "dsp_core.h" 24#include "dsp_core.h"
25#include "dsp_sample_io.h" 25#include "dsp_sample_io.h"
26 26
27#include "tdspeed.h"
28#include "resample.h"
29
27/* Define LOGF_ENABLE to enable logf output in this file */ 30/* Define LOGF_ENABLE to enable logf output in this file */
28/*#define LOGF_ENABLE*/ 31/*#define LOGF_ENABLE*/
29#include "logf.h" 32#include "logf.h"
@@ -70,6 +73,11 @@ dsp_proc_slot_arr[DSP_NUM_PROC_STAGES+DSP_VOICE_NUM_PROC_STAGES] IBSS_ATTR;
70/* General DSP config */ 73/* General DSP config */
71static struct dsp_config dsp_conf[DSP_COUNT] IBSS_ATTR; 74static struct dsp_config dsp_conf[DSP_COUNT] IBSS_ATTR;
72 75
76static const dsp_proc_init_fn_type dsp_init_fn[] INITDATA_ATTR = {
77 &dsp_timestretch_init,
78 &dsp_resample_init,
79};
80
73/** Processing stages support functions **/ 81/** Processing stages support functions **/
74static const struct dsp_proc_db_entry * 82static const struct dsp_proc_db_entry *
75proc_db_entry(const struct dsp_proc_slot *s) 83proc_db_entry(const struct dsp_proc_slot *s)
@@ -517,12 +525,15 @@ void dsp_init(void)
517 count = slot_count[i]; 525 count = slot_count[i];
518 dsp->slot_free_mask = MASK_N(uint32_t, count, shift); 526 dsp->slot_free_mask = MASK_N(uint32_t, count, shift);
519 527
520 intptr_t value = i; 528 dsp_sample_io_init(&dsp->io_data, i);
521 dsp_sample_io_configure(&dsp->io_data, DSP_INIT, &value); 529
530 /* Enable misc handler by default for the audio DSP */
531 if (i == CODEC_IDX_AUDIO)
532 dsp_proc_enable(dsp, DSP_PROC_MISC_HANDLER, true);
522 533
523 /* Notify each db entry of global init for each DSP */ 534 /* Call global init for DSPs that need it */
524 for (unsigned int j = 0; j < DSP_NUM_PROC_STAGES; j++) 535 for (unsigned int j = 0; j < ARRAYLEN(dsp_init_fn); ++j)
525 dsp_proc_database[j]->configure(NULL, dsp, DSP_INIT, i); 536 dsp_init_fn[j](dsp, i);
526 537
527 dsp_configure(dsp, DSP_RESET, 0); 538 dsp_configure(dsp, DSP_RESET, 0);
528 } 539 }
diff --git a/lib/rbcodec/dsp/dsp_core.h b/lib/rbcodec/dsp/dsp_core.h
index 3544084056..9b09d981cc 100644
--- a/lib/rbcodec/dsp/dsp_core.h
+++ b/lib/rbcodec/dsp/dsp_core.h
@@ -32,7 +32,6 @@ enum dsp_ids
32 32
33enum dsp_settings 33enum dsp_settings
34{ 34{
35 DSP_INIT, /* For dsp_init */
36 DSP_RESET, 35 DSP_RESET,
37 DSP_SET_FREQUENCY, 36 DSP_SET_FREQUENCY,
38 DSP_SET_SAMPLE_DEPTH, 37 DSP_SET_SAMPLE_DEPTH,
diff --git a/lib/rbcodec/dsp/dsp_misc.c b/lib/rbcodec/dsp/dsp_misc.c
index 8687abc06a..24ec857e3a 100644
--- a/lib/rbcodec/dsp/dsp_misc.c
+++ b/lib/rbcodec/dsp/dsp_misc.c
@@ -149,13 +149,6 @@ unsigned int dsp_get_output_frequency(struct dsp_config *dsp)
149 return dsp_configure(dsp, DSP_GET_OUT_FREQUENCY, 0); 149 return dsp_configure(dsp, DSP_GET_OUT_FREQUENCY, 0);
150} 150}
151 151
152static void misc_dsp_init(struct dsp_config *dsp, unsigned int dsp_id)
153{
154 /* Enable us for the audio DSP at startup */
155 if (dsp_id == CODEC_IDX_AUDIO)
156 dsp_proc_enable(dsp, DSP_PROC_MISC_HANDLER, true);
157}
158
159/* This is a null-processing stage that monitors as an enabled stage but never 152/* This is a null-processing stage that monitors as an enabled stage but never
160 * becomes active in processing samples. It only hooks messages. */ 153 * becomes active in processing samples. It only hooks messages. */
161 154
@@ -167,10 +160,6 @@ static intptr_t misc_handler_configure(struct dsp_proc_entry *this,
167{ 160{
168 switch (setting) 161 switch (setting)
169 { 162 {
170 case DSP_INIT:
171 misc_dsp_init(dsp, value);
172 break;
173
174 case DSP_PROC_CLOSE: 163 case DSP_PROC_CLOSE:
175 /* This stage should be enabled at all times */ 164 /* This stage should be enabled at all times */
176 DEBUGF("DSP_PROC_MISC_HANDLER - Error: Closing!\n"); 165 DEBUGF("DSP_PROC_MISC_HANDLER - Error: Closing!\n");
diff --git a/lib/rbcodec/dsp/dsp_proc_entry.h b/lib/rbcodec/dsp/dsp_proc_entry.h
index 0a65792207..7a4b8de1c6 100644
--- a/lib/rbcodec/dsp/dsp_proc_entry.h
+++ b/lib/rbcodec/dsp/dsp_proc_entry.h
@@ -127,6 +127,8 @@ typedef intptr_t (*dsp_proc_config_fn_type)(struct dsp_proc_entry *this,
127 struct dsp_config *dsp, 127 struct dsp_config *dsp,
128 unsigned int setting, 128 unsigned int setting,
129 intptr_t value); 129 intptr_t value);
130typedef void (*dsp_proc_init_fn_type)(struct dsp_config *dsp,
131 unsigned int dsp_id);
130 132
131/* Enable/disable a processing stage - not to be called during processing 133/* Enable/disable a processing stage - not to be called during processing
132 * by processing code! */ 134 * by processing code! */
diff --git a/lib/rbcodec/dsp/dsp_sample_io.c b/lib/rbcodec/dsp/dsp_sample_io.c
index af3a424aa0..8a0d5da7cc 100644
--- a/lib/rbcodec/dsp/dsp_sample_io.c
+++ b/lib/rbcodec/dsp/dsp_sample_io.c
@@ -36,6 +36,13 @@ static void format_change_set(struct sample_io_data *this)
36 this->format_dirty = 1; 36 this->format_dirty = 1;
37} 37}
38 38
39void dsp_sample_io_init(struct sample_io_data *this, unsigned int dsp_id)
40{
41 this->output_sampr = DSP_OUT_DEFAULT_HZ;
42 dsp_sample_input_init(this, dsp_id);
43 dsp_sample_output_init(this);
44}
45
39bool dsp_sample_io_configure(struct sample_io_data *this, 46bool dsp_sample_io_configure(struct sample_io_data *this,
40 unsigned int setting, 47 unsigned int setting,
41 intptr_t *value_p) 48 intptr_t *value_p)
@@ -44,12 +51,6 @@ bool dsp_sample_io_configure(struct sample_io_data *this,
44 51
45 switch (setting) 52 switch (setting)
46 { 53 {
47 case DSP_INIT:
48 this->output_sampr = DSP_OUT_DEFAULT_HZ;
49 dsp_sample_input_init(this, value);
50 dsp_sample_output_init(this);
51 break;
52
53 case DSP_RESET: 54 case DSP_RESET:
54 /* Reset all sample descriptions to default */ 55 /* Reset all sample descriptions to default */
55 format_change_set(this); 56 format_change_set(this);
diff --git a/lib/rbcodec/dsp/dsp_sample_io.h b/lib/rbcodec/dsp/dsp_sample_io.h
index 7e41337a5b..095aea3f3a 100644
--- a/lib/rbcodec/dsp/dsp_sample_io.h
+++ b/lib/rbcodec/dsp/dsp_sample_io.h
@@ -56,17 +56,18 @@ 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
59void dsp_sample_input_init(struct sample_io_data *this, unsigned int dsp_id); 59void dsp_sample_input_init(struct sample_io_data *this, unsigned int dsp_id) INIT_ATTR;
60void dsp_sample_input_flush(struct sample_io_data *this); 60void dsp_sample_input_flush(struct sample_io_data *this);
61void dsp_sample_input_format_change(struct sample_io_data *this, 61void dsp_sample_input_format_change(struct sample_io_data *this,
62 struct sample_format *format); 62 struct sample_format *format);
63 63
64void dsp_sample_output_init(struct sample_io_data *this); 64void dsp_sample_output_init(struct sample_io_data *this) INIT_ATTR;
65void dsp_sample_output_flush(struct sample_io_data *this); 65void dsp_sample_output_flush(struct sample_io_data *this);
66void dsp_sample_output_format_change(struct sample_io_data *this, 66void dsp_sample_output_format_change(struct sample_io_data *this,
67 struct sample_format *format); 67 struct sample_format *format);
68 68
69/* Sample IO watches the format setting from the codec */ 69/* Sample IO watches the format setting from the codec */
70void dsp_sample_io_init(struct sample_io_data *this, unsigned int dsp_id) INIT_ATTR;
70bool dsp_sample_io_configure(struct sample_io_data *this, 71bool dsp_sample_io_configure(struct sample_io_data *this,
71 unsigned int setting, 72 unsigned int setting,
72 intptr_t *value_p); 73 intptr_t *value_p);
diff --git a/lib/rbcodec/dsp/resample.c b/lib/rbcodec/dsp/resample.c
index 77e1c5e0e5..bec0de99f0 100644
--- a/lib/rbcodec/dsp/resample.c
+++ b/lib/rbcodec/dsp/resample.c
@@ -26,6 +26,7 @@
26#include "fixedpoint.h" 26#include "fixedpoint.h"
27#include "dsp_proc_entry.h" 27#include "dsp_proc_entry.h"
28#include "dsp_misc.h" 28#include "dsp_misc.h"
29#include "resample.h"
29#include <string.h> 30#include <string.h>
30 31
31/** 32/**
@@ -262,7 +263,7 @@ static intptr_t resample_new_format(struct dsp_proc_entry *this,
262 return PROC_NEW_FORMAT_DEACTIVATED; 263 return PROC_NEW_FORMAT_DEACTIVATED;
263} 264}
264 265
265static void resample_dsp_init(struct dsp_config *dsp, unsigned int dsp_id) 266void dsp_resample_init(struct dsp_config *dsp, unsigned int dsp_id)
266{ 267{
267 int32_t *lbuf, *rbuf; 268 int32_t *lbuf, *rbuf;
268 269
@@ -310,10 +311,6 @@ static intptr_t resample_configure(struct dsp_proc_entry *this,
310 311
311 switch (setting) 312 switch (setting)
312 { 313 {
313 case DSP_INIT:
314 resample_dsp_init(dsp, value);
315 break;
316
317 case DSP_FLUSH: 314 case DSP_FLUSH:
318 resample_flush(this); 315 resample_flush(this);
319 break; 316 break;
diff --git a/lib/rbcodec/dsp/resample.h b/lib/rbcodec/dsp/resample.h
new file mode 100644
index 0000000000..1f6edf00ca
--- /dev/null
+++ b/lib/rbcodec/dsp/resample.h
@@ -0,0 +1,26 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2022 Aidan MacDonald
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _DSP_RESAMPLE_H
22#define _DSP_RESAMPLE_H
23
24void dsp_resample_init(struct dsp_config *dsp, unsigned int dsp_id) INIT_ATTR;
25
26#endif /* _DSP_RESAMPLE_H */
diff --git a/lib/rbcodec/dsp/tdspeed.c b/lib/rbcodec/dsp/tdspeed.c
index 88d057560c..022a8edb6d 100644
--- a/lib/rbcodec/dsp/tdspeed.c
+++ b/lib/rbcodec/dsp/tdspeed.c
@@ -521,8 +521,12 @@ static intptr_t tdspeed_new_format(struct dsp_proc_entry *this,
521 (void)this; 521 (void)this;
522} 522}
523 523
524static void tdspeed_dsp_init(struct tdspeed_state_s *st, unsigned int dsp_id) 524void dsp_timestretch_init(struct dsp_config *dsp, unsigned int dsp_id)
525{ 525{
526 (void)dsp;
527
528 struct tdspeed_state_s *st = &tdspeed_state;
529
526 /* everything is at 100% until dsp_set_timestretch is called with 530 /* everything is at 100% until dsp_set_timestretch is called with
527 some other value and timestretch is enabled at the time */ 531 some other value and timestretch is enabled at the time */
528 if (dsp_id == CODEC_IDX_AUDIO) 532 if (dsp_id == CODEC_IDX_AUDIO)
@@ -541,10 +545,6 @@ static intptr_t tdspeed_configure(struct dsp_proc_entry *this,
541 545
542 switch (setting) 546 switch (setting)
543 { 547 {
544 case DSP_INIT:
545 tdspeed_dsp_init(st, value);
546 break;
547
548 case DSP_FLUSH: 548 case DSP_FLUSH:
549 tdspeed_flush(); 549 tdspeed_flush();
550 break; 550 break;
diff --git a/lib/rbcodec/dsp/tdspeed.h b/lib/rbcodec/dsp/tdspeed.h
index 84920ac7c2..5f35990375 100644
--- a/lib/rbcodec/dsp/tdspeed.h
+++ b/lib/rbcodec/dsp/tdspeed.h
@@ -40,6 +40,7 @@ void dsp_timestretch_enable(bool enable);
40void dsp_set_timestretch(int32_t percent); 40void dsp_set_timestretch(int32_t percent);
41int32_t dsp_get_timestretch(void); 41int32_t dsp_get_timestretch(void);
42bool dsp_timestretch_available(void); 42bool dsp_timestretch_available(void);
43void dsp_timestretch_init(struct dsp_config *dsp, unsigned int dsp_id) INIT_ATTR;
43void tdspeed_move(int i, void* current, void* new); 44void tdspeed_move(int i, void* current, void* new);
44 45
45#endif /* _TDSPEED_H */ 46#endif /* _TDSPEED_H */