summaryrefslogtreecommitdiff
path: root/lib/rbcodec/dsp/tone_controls.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/dsp/tone_controls.c')
-rw-r--r--lib/rbcodec/dsp/tone_controls.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/lib/rbcodec/dsp/tone_controls.c b/lib/rbcodec/dsp/tone_controls.c
new file mode 100644
index 0000000000..0bd4a447d7
--- /dev/null
+++ b/lib/rbcodec/dsp/tone_controls.c
@@ -0,0 +1,118 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Thom Johansen
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 "config.h"
23#include "system.h"
24#include "dsp.h"
25#include <string.h>
26#include "dsp_proc_entry.h"
27#include "dsp_filter.h"
28
29/* These apply to all DSP streams to remain as consistant as possible with
30 * the behavior of hardware tone controls */
31
32/* Cutoffs in HZ - not adjustable for now */
33static const unsigned int tone_bass_cutoff = 200;
34static const unsigned int tone_treble_cutoff = 3500;
35
36/* Current bass and treble gain values */
37static int tone_bass = 0;
38static int tone_treble = 0;
39
40/* Data for each DSP */
41static struct dsp_filter tone_filters[DSP_COUNT] IBSS_ATTR;
42
43/* Update the filters' coefficients based upon the bass/treble settings */
44void tone_set_prescale(int prescale)
45{
46 int bass = tone_bass;
47 int treble = tone_treble;
48
49 struct dsp_filter tone_filter; /* Temp to hold new version */
50 filter_bishelf_coefs(0xffffffff / NATIVE_FREQUENCY * tone_bass_cutoff,
51 0xffffffff / NATIVE_FREQUENCY * tone_treble_cutoff,
52 bass, treble, -prescale, &tone_filter);
53
54 struct dsp_config *dsp;
55 for (int i = 0; (dsp = dsp_get_config(i)); i++)
56 {
57 struct dsp_filter *filter = &tone_filters[i];
58 filter_copy(filter, &tone_filter);
59
60 bool enable = bass != 0 || treble != 0;
61 dsp_proc_enable(dsp, DSP_PROC_TONE_CONTROLS, enable);
62
63 if (!dsp_proc_active(dsp, DSP_PROC_TONE_CONTROLS))
64 {
65 filter_flush(filter); /* Going online */
66 dsp_proc_activate(dsp, DSP_PROC_TONE_CONTROLS, true);
67 }
68 }
69}
70
71/* Prescaler is always set after setting bass/treble, so we wait with
72 * calculating coefs until such time. */
73
74/* Change the bass setting */
75void tone_set_bass(int bass)
76{
77 tone_bass = bass;
78}
79
80/* Change the treble setting */
81void tone_set_treble(int treble)
82{
83 tone_treble = treble;
84}
85
86/* Apply the tone control filter in-place */
87static void tone_process(struct dsp_proc_entry *this,
88 struct dsp_buffer **buf_p)
89{
90 struct dsp_buffer *buf = *buf_p;
91 filter_process((void *)this->data, buf->p32, buf->remcount,
92 buf->format.num_channels);
93}
94
95/* DSP message hook */
96static intptr_t tone_configure(struct dsp_proc_entry *this,
97 struct dsp_config *dsp,
98 unsigned int setting,
99 intptr_t value)
100{
101 switch (setting)
102 {
103 case DSP_PROC_INIT:
104 if (value != 0)
105 break;
106 this->data = (intptr_t)&tone_filters[dsp_get_id(dsp)];
107 this->process[0] = tone_process;
108 case DSP_FLUSH:
109 filter_flush((struct dsp_filter *)this->data);
110 break;
111 }
112
113 return 1;
114}
115
116/* Database entry */
117DSP_PROC_DB_ENTRY(TONE_CONTROLS,
118 tone_configure);