blob: a19cc15c4131834a142dc87f286674ebaa49054c [file] [log] [blame]
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
Christian Gmeinercdbf33a2007-05-22 15:56:05 +000011 * Copyright (C) 2007 by Christian Gmeiner
Michael Sevakis0c7b7872013-04-12 23:35:47 -040012 * Copyright (C) 2013 by Michael Sevakis
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000013 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000014 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000018 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
Michael Sevakis0c7b7872013-04-12 23:35:47 -040023 /* Indicate it's the sound.c file which affects compilation of audiohw.h */
24#define AUDIOHW_IS_SOUND_C
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000025#include "config.h"
Nils Wallménius74e245b2009-01-02 11:21:58 +000026#include "system.h"
Michael Sevakis0c7b7872013-04-12 23:35:47 -040027#include "sound.h"
Michael Sevakisf5a5b942013-04-05 04:36:05 -040028#ifdef HAVE_SW_VOLUME_CONTROL
29#include "pcm_sw_volume.h"
30#endif /* HAVE_SW_VOLUME_CONTROL */
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000031
Michael Sevakis0c7b7872013-04-12 23:35:47 -040032/* Define sound_setting_entries table */
33#define AUDIOHW_SOUND_SETTINGS_ENTRIES
34#include "audiohw_settings.h"
35
36/* Implements sound_val2phys */
37#define AUDIOHW_SOUND_SETTINGS_VAL2PHYS
38#include "audiohw_settings.h"
Christian Gmeinera6100fb2008-04-28 22:15:52 +000039
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000040extern bool audio_is_initialized;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000041
Michael Sevakis0c7b7872013-04-12 23:35:47 -040042static const struct sound_setting_entry * get_setting_entry(int setting)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000043{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040044 static const struct sound_settings_info default_info =
45 { "", 0, 0, 0, 0, 0 };
46
47 static const struct sound_setting_entry default_entry =
48 { &default_info, NULL };
49
50 if ((unsigned)setting >= ARRAYLEN(sound_setting_entries))
51 return &default_entry;
52
53 const struct sound_setting_entry *e = &sound_setting_entries[setting];
54 return e->info ? e : &default_entry; /* setting valid but not in table? */
55}
56
57static const struct sound_settings_info * get_settings_info(int setting)
58{
59 return get_setting_entry(setting)->info;
60}
61
62const char * sound_unit(int setting)
63{
64 return get_settings_info(setting)->unit;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000065}
66
67int sound_numdecimals(int setting)
68{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040069 return get_settings_info(setting)->numdecimals;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000070}
71
72int sound_steps(int setting)
73{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040074 return get_settings_info(setting)->steps;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000075}
76
77int sound_min(int setting)
78{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040079 return get_settings_info(setting)->minval;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000080}
81
82int sound_max(int setting)
83{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040084 return get_settings_info(setting)->maxval;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000085}
86
87int sound_default(int setting)
88{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040089 return get_settings_info(setting)->defaultval;
Jens Arnold8051a0b2005-11-06 23:12:11 +000090}
91
Michael Sevakis0c7b7872013-04-12 23:35:47 -040092sound_set_type * sound_get_fn(int setting)
Nils Wallménius74e245b2009-01-02 11:21:58 +000093{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040094 return get_setting_entry(setting)->function;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000095}
96
Michael Sevakis0c7b7872013-04-12 23:35:47 -040097void sound_set(int setting, int value)
Thom Johansena7fabf02007-02-26 00:41:26 +000098{
Michael Sevakis0c7b7872013-04-12 23:35:47 -040099 sound_set_type *sound_set_val = sound_get_fn(setting);
100
101 if (sound_set_val)
102 sound_set_val(value);
Thom Johansena7fabf02007-02-26 00:41:26 +0000103}
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400104
Christian Gmeiner785e7762008-05-13 06:19:16 +0000105#if !defined(AUDIOHW_HAVE_CLIPPING)
Christian Gmeiner83915262008-04-28 08:37:18 +0000106/*
107 * The prescaler compensates for any kind of boosts, to prevent clipping.
108 *
109 * It's basically just a measure to make sure that audio does not clip during
110 * tone controls processing, like if i want to boost bass 12 dB, i can decrease
111 * the audio amplitude by -12 dB before processing, then increase master gain
112 * by 12 dB after processing.
113 */
Jens Arnold12a0e222005-06-19 23:33:23 +0000114
Michael Sevakisbbd991a2013-04-15 13:24:29 -0400115/* Return the sound value scaled to centibels (tenth-decibels) */
116static int sound_value_to_cb(int setting, int value)
117{
Michael Sevakis540e5d12013-04-15 16:11:28 -0400118 int shift = 1 - sound_numdecimals(setting);
119 if (shift < 0) do { value /= 10; } while (++shift);
120 if (shift > 0) do { value *= 10; } while (--shift);
121 return value;
Michael Sevakisbbd991a2013-04-15 13:24:29 -0400122}
123
Michael Sevakise61e9c62013-04-20 04:06:13 -0400124static struct
125{
126 int volume; /* tenth dB */
127 int balance; /* percent */
128#if defined(AUDIOHW_HAVE_BASS)
129 int bass; /* tenth dB */
130#endif
131#if defined(AUDIOHW_HAVE_TREBLE)
132 int treble; /* tenth dB */
133#endif
134#if defined(AUDIOHW_HAVE_EQ)
135 int eq_gain[AUDIOHW_EQ_BAND_NUM]; /* tenth dB */
136#endif
137} sound_prescaler;
138
139#if defined(AUDIOHW_HAVE_BASS) || defined (AUDIOHW_HAVE_TREBLE) \
140 || defined(AUDIOHW_HAVE_EQ)
141#define TONE_PRESCALER
142#endif
143
Jens Arnold4c7da882005-06-18 01:25:47 +0000144static void set_prescaled_volume(void)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000145{
Michael Sevakise61e9c62013-04-20 04:06:13 -0400146#if defined(TONE_PRESCALER) || !defined(AUDIOHW_HAVE_MONO_VOLUME)
147 const int minvol = sound_value_to_cb(SOUND_VOLUME, sound_min(SOUND_VOLUME));
148#endif
149 int volume = sound_prescaler.volume;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000150
Michael Sevakise61e9c62013-04-20 04:06:13 -0400151#if defined(TONE_PRESCALER)
152 int prescale = 0;
Thom Johansen2d7bb99c2007-03-07 15:00:29 +0000153
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400154 /* Note: Having Tone + EQ isn't prohibited */
Michael Sevakis80d0d152010-05-15 13:09:45 +0000155#if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE)
Michael Sevakise61e9c62013-04-20 04:06:13 -0400156 prescale = MAX(sound_prescaler.bass, sound_prescaler.treble);
Michael Sevakis80d0d152010-05-15 13:09:45 +0000157#endif
Michael Sevakise61e9c62013-04-20 04:06:13 -0400158
Michael Sevakis80d0d152010-05-15 13:09:45 +0000159#if defined(AUDIOHW_HAVE_EQ)
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400160 for (int i = 0; i < AUDIOHW_EQ_BAND_NUM; i++)
Michael Sevakise61e9c62013-04-20 04:06:13 -0400161 prescale = MAX(sound_prescaler.eq_gain[i], prescale);
Michael Sevakis80d0d152010-05-15 13:09:45 +0000162#endif
163
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000164 if (prescale < 0)
165 prescale = 0; /* no need to prescale if we don't boost
Michael Sevakis80d0d152010-05-15 13:09:45 +0000166 bass, treble or eq band */
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000167
Jens Arnold2993ae62005-12-07 23:07:07 +0000168 /* Gain up the analog volume to compensate the prescale gain reduction,
169 * but if this would push the volume over the top, reduce prescaling
170 * instead (might cause clipping). */
Michael Sevakise61e9c62013-04-20 04:06:13 -0400171 const int maxvol = sound_value_to_cb(SOUND_VOLUME, sound_max(SOUND_VOLUME));
172
173 if (volume + prescale > maxvol)
174 prescale = maxvol - volume;
Thom Johansen2d7bb99c2007-03-07 15:00:29 +0000175
Christian Gmeiner05e84882008-05-14 21:35:19 +0000176 audiohw_set_prescaler(prescale);
Jens Arnold2993ae62005-12-07 23:07:07 +0000177
Michael Sevakise61e9c62013-04-20 04:06:13 -0400178 if (volume <= minvol)
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400179 prescale = 0; /* Make sure the audio gets muted */
Michael Sevakise61e9c62013-04-20 04:06:13 -0400180
181#ifndef AUDIOHW_HAVE_MONO_VOLUME
182 /* At the moment, such targets have lousy volume resolution and so minute
183 boost won't work how we'd like */
184 volume += prescale;
185#endif
186#endif /* TONE_PRESCALER */
Jens Arnold2993ae62005-12-07 23:07:07 +0000187
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400188#if defined(AUDIOHW_HAVE_MONO_VOLUME)
Michael Sevakise61e9c62013-04-20 04:06:13 -0400189 audiohw_set_volume(volume);
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400190#else /* Stereo volume */
Michael Sevakise61e9c62013-04-20 04:06:13 -0400191 int l = volume, r = volume;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000192
Michael Sevakise61e9c62013-04-20 04:06:13 -0400193 /* Balance the channels scaled by the current volume and min volume */
194 int balance = sound_prescaler.balance; /* percent */
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400195
Michael Sevakise61e9c62013-04-20 04:06:13 -0400196 if (balance > 0)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000197 {
Michael Sevakise61e9c62013-04-20 04:06:13 -0400198 l -= (l - minvol) * balance / 100;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000199 }
Michael Sevakise61e9c62013-04-20 04:06:13 -0400200 else if (balance < 0)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000201 {
Michael Sevakise61e9c62013-04-20 04:06:13 -0400202 r += (r - minvol) * balance / 100;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000203 }
204
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400205 audiohw_set_volume(l, r);
206#endif /* AUDIOHW_HAVE_MONO_VOLUME */
Thom Johansen473fc2b2006-03-22 13:04:49 +0000207
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400208#if defined(AUDIOHW_HAVE_LINEOUT)
209 /* For now, lineout stays at unity */
210 audiohw_set_lineout_volume(0, 0);
211#endif /* AUDIOHW_HAVE_LINEOUT */
Anton Oleynikov2654d912005-12-04 14:33:10 +0000212}
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400213#endif /* AUDIOIHW_HAVE_CLIPPING */
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000214
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000215void sound_set_volume(int value)
216{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400217 if (!audio_is_initialized)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000218 return;
Christian Gmeiner785e7762008-05-13 06:19:16 +0000219
220#if defined(AUDIOHW_HAVE_CLIPPING)
221 audiohw_set_volume(value);
Christian Gmeiner785e7762008-05-13 06:19:16 +0000222#else
Michael Sevakise61e9c62013-04-20 04:06:13 -0400223 sound_prescaler.volume = sound_value_to_cb(SOUND_VOLUME, value);
Christian Gmeiner785e7762008-05-13 06:19:16 +0000224 set_prescaled_volume();
Jens Arnold2993ae62005-12-07 23:07:07 +0000225#endif
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000226}
227
228void sound_set_balance(int value)
229{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400230 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000231 return;
Christian Gmeiner785e7762008-05-13 06:19:16 +0000232
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400233#if defined(AUDIOHW_HAVE_BALANCE)
Christian Gmeiner785e7762008-05-13 06:19:16 +0000234 audiohw_set_balance(value);
235#else
Michael Sevakise61e9c62013-04-20 04:06:13 -0400236 sound_prescaler.balance = value;
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000237 set_prescaled_volume();
Jens Arnold2993ae62005-12-07 23:07:07 +0000238#endif
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000239}
240
Michael Sevakise61e9c62013-04-20 04:06:13 -0400241#if defined(AUDIOHW_HAVE_BASS)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000242void sound_set_bass(int value)
243{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400244 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000245 return;
Christian Gmeiner83915262008-04-28 08:37:18 +0000246
Michael Sevakis80d0d152010-05-15 13:09:45 +0000247 audiohw_set_bass(value);
Christian Gmeiner83915262008-04-28 08:37:18 +0000248
Christian Gmeiner785e7762008-05-13 06:19:16 +0000249#if !defined(AUDIOHW_HAVE_CLIPPING)
Michael Sevakise61e9c62013-04-20 04:06:13 -0400250 sound_prescaler.bass = sound_value_to_cb(SOUND_BASS, value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000251 set_prescaled_volume();
Christian Gmeiner83915262008-04-28 08:37:18 +0000252#endif
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000253}
Michael Sevakis80d0d152010-05-15 13:09:45 +0000254#endif /* AUDIOHW_HAVE_BASS */
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000255
Michael Sevakise61e9c62013-04-20 04:06:13 -0400256#if defined(AUDIOHW_HAVE_TREBLE)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000257void sound_set_treble(int value)
258{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400259 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000260 return;
Christian Gmeiner83915262008-04-28 08:37:18 +0000261
Michael Sevakis80d0d152010-05-15 13:09:45 +0000262 audiohw_set_treble(value);
Christian Gmeiner83915262008-04-28 08:37:18 +0000263
Christian Gmeiner785e7762008-05-13 06:19:16 +0000264#if !defined(AUDIOHW_HAVE_CLIPPING)
Michael Sevakise61e9c62013-04-20 04:06:13 -0400265 sound_prescaler.treble = sound_value_to_cb(SOUND_TREBLE, value);
Christian Gmeiner83915262008-04-28 08:37:18 +0000266 set_prescaled_volume();
267#endif
Jens Arnold8051a0b2005-11-06 23:12:11 +0000268}
Michael Sevakis80d0d152010-05-15 13:09:45 +0000269#endif /* AUDIOHW_HAVE_TREBLE */
270
271#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
272void sound_set_bass_cutoff(int value)
273{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400274 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000275 return;
276
277 audiohw_set_bass_cutoff(value);
278}
Michael Sevakise61e9c62013-04-20 04:06:13 -0400279#endif /* AUDIOHW_HAVE_BASS_CUTOFF */
Michael Sevakis80d0d152010-05-15 13:09:45 +0000280
281#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
282void sound_set_treble_cutoff(int value)
283{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400284 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000285 return;
286
287 audiohw_set_treble_cutoff(value);
288}
Michael Sevakise61e9c62013-04-20 04:06:13 -0400289#endif /* AUDIOHW_HAVE_TREBLE_CUTOFF */
Jens Arnold8051a0b2005-11-06 23:12:11 +0000290
291void sound_set_channels(int value)
292{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400293 if (!audio_is_initialized)
Christian Gmeinerb1806b22008-04-22 13:43:01 +0000294 return;
295
Christian Gmeinerb1806b22008-04-22 13:43:01 +0000296 audiohw_set_channel(value);
Jens Arnold8051a0b2005-11-06 23:12:11 +0000297}
298
299void sound_set_stereo_width(int value)
300{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400301 if (!audio_is_initialized)
Christian Gmeinerb1806b22008-04-22 13:43:01 +0000302 return;
303
Christian Gmeinerb1806b22008-04-22 13:43:01 +0000304 audiohw_set_stereo_width(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000305}
306
Michael Sevakis80d0d152010-05-15 13:09:45 +0000307#if defined(AUDIOHW_HAVE_DEPTH_3D)
308void sound_set_depth_3d(int value)
Dan Evertond7e1f772007-11-24 07:51:00 +0000309{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400310 if (!audio_is_initialized)
Dan Evertond7e1f772007-11-24 07:51:00 +0000311 return;
312
Michael Sevakis80d0d152010-05-15 13:09:45 +0000313 audiohw_set_depth_3d(value);
Dan Evertond7e1f772007-11-24 07:51:00 +0000314}
Michael Sevakise61e9c62013-04-20 04:06:13 -0400315#endif /* AUDIOHW_HAVE_DEPTH_3D */
Dan Evertond7e1f772007-11-24 07:51:00 +0000316
Andrew Ryabinin0519f7e2013-05-12 23:23:45 +0400317#if defined(AUDIOHW_HAVE_FILTER_ROLL_OFF)
318void sound_set_filter_roll_off(int value)
319{
320 if (!audio_is_initialized)
321 return;
322
323 audiohw_set_filter_roll_off(value);
324}
325#endif
326
Michael Sevakis80d0d152010-05-15 13:09:45 +0000327#if defined(AUDIOHW_HAVE_EQ)
328int sound_enum_hw_eq_band_setting(unsigned int band,
329 unsigned int band_setting)
330{
331 static const int8_t
332 sound_hw_eq_band_setting[AUDIOHW_EQ_SETTING_NUM][AUDIOHW_EQ_BAND_NUM] =
333 {
334 [AUDIOHW_EQ_GAIN] =
335 {
336 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
337 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_GAIN,
338 #ifdef AUDIOHW_HAVE_EQ_BAND2
339 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_GAIN,
340 #endif
341 #ifdef AUDIOHW_HAVE_EQ_BAND3
342 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_GAIN,
343 #endif
344 #ifdef AUDIOHW_HAVE_EQ_BAND4
345 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_GAIN,
346 #endif
347 #ifdef AUDIOHW_HAVE_EQ_BAND5
348 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_GAIN,
349 #endif
350 },
351#ifdef AUDIOHW_HAVE_EQ_FREQUENCY
352 [AUDIOHW_EQ_FREQUENCY] =
353 {
354 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
355 #ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
356 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_FREQUENCY,
357 #endif
358 #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
359 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_FREQUENCY,
360 #endif
361 #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
362 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_FREQUENCY,
363 #endif
364 #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
365 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_FREQUENCY,
366 #endif
367 #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
368 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_FREQUENCY,
369 #endif
370 },
371#endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
372#ifdef AUDIOHW_HAVE_EQ_WIDTH
373 [AUDIOHW_EQ_WIDTH] =
374 {
375 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
376 #ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
377 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_WIDTH,
378 #endif
379 #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
380 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_WIDTH,
381 #endif
382 #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
383 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_WIDTH,
384 #endif
385 },
386#endif /* AUDIOHW_HAVE_EQ_WIDTH */
387 };
388
389 if (band < AUDIOHW_EQ_BAND_NUM && band_setting < AUDIOHW_EQ_SETTING_NUM)
390 return sound_hw_eq_band_setting[band_setting][band];
391
392 return -1;
393}
394
395static void sound_set_hw_eq_band_gain(unsigned int band, int value)
Dan Evertond7e1f772007-11-24 07:51:00 +0000396{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400397 if (!audio_is_initialized)
Dan Evertond7e1f772007-11-24 07:51:00 +0000398 return;
399
Michael Sevakis80d0d152010-05-15 13:09:45 +0000400 audiohw_set_eq_band_gain(band, value);
Michael Sevakise61e9c62013-04-20 04:06:13 -0400401
402#if !defined (AUDIOHW_HAVE_CLIPPING)
403 int setting = sound_enum_hw_eq_band_setting(band, AUDIOHW_EQ_GAIN);
404 sound_prescaler.eq_gain[band] = sound_value_to_cb(setting, value);
Michael Sevakis80d0d152010-05-15 13:09:45 +0000405 set_prescaled_volume();
Michael Sevakise61e9c62013-04-20 04:06:13 -0400406#endif /* AUDIOHW_HAVE_CLIPPING */
Michael Sevakis80d0d152010-05-15 13:09:45 +0000407}
408
409void sound_set_hw_eq_band1_gain(int value)
410{
411 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1, value);
412}
413
414#if defined(AUDIOHW_HAVE_EQ_BAND2)
415void sound_set_hw_eq_band2_gain(int value)
416{
417 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2, value);
Dan Evertond7e1f772007-11-24 07:51:00 +0000418}
419#endif
420
Michael Sevakis80d0d152010-05-15 13:09:45 +0000421#if defined(AUDIOHW_HAVE_EQ_BAND3)
422void sound_set_hw_eq_band3_gain(int value)
423{
424 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3, value);
425}
426#endif
427
428#if defined(AUDIOHW_HAVE_EQ_BAND4)
429void sound_set_hw_eq_band4_gain(int value)
430{
431 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4, value);
432}
433#endif
434
435#if defined(AUDIOHW_HAVE_EQ_BAND5)
436void sound_set_hw_eq_band5_gain(int value)
437{
438 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5, value);
439}
440#endif
441
442#if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
443void sound_set_hw_eq_band1_frequency(int value)
444{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400445 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000446 return;
447
448 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value);
449}
450#endif
451
452#if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
453void sound_set_hw_eq_band2_frequency(int value)
454{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400455 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000456 return;
457
458 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value);
459}
460#endif
461
462#if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
463void sound_set_hw_eq_band3_frequency(int value)
464{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400465 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000466 return;
467
468 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value);
469}
470#endif
471
472#if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
473void sound_set_hw_eq_band4_frequency(int value)
474{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400475 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000476 return;
477
478 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value);
479}
480#endif
481
482#if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
483void sound_set_hw_eq_band5_frequency(int value)
484{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400485 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000486 return;
487
488 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value);
489}
490#endif
491
492#if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
493void sound_set_hw_eq_band2_width(int value)
494{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400495 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000496 return;
497
498 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value);
499}
500#endif
501
502#if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
503void sound_set_hw_eq_band3_width(int value)
504{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400505 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000506 return;
507
508 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value);
509}
510#endif
511
512#if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
513void sound_set_hw_eq_band4_width(int value)
514{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400515 if (!audio_is_initialized)
Michael Sevakis80d0d152010-05-15 13:09:45 +0000516 return;
517
518 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value);
519}
520#endif
521#endif /* AUDIOHW_HAVE_EQ */
522
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400523#if CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000524void sound_set_loudness(int value)
525{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400526 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000527 return;
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000528
529 audiohw_set_loudness(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000530}
531
532void sound_set_avc(int value)
533{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400534 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000535 return;
Nils Wallménius74e245b2009-01-02 11:21:58 +0000536
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000537 audiohw_set_avc(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000538}
539
540void sound_set_mdb_strength(int value)
541{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400542 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000543 return;
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000544
545 audiohw_set_mdb_strength(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000546}
547
548void sound_set_mdb_harmonics(int value)
549{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400550 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000551 return;
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000552
553 audiohw_set_mdb_harmonics(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000554}
555
556void sound_set_mdb_center(int value)
557{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400558 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000559 return;
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000560
561 audiohw_set_mdb_center(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000562}
563
564void sound_set_mdb_shape(int value)
565{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400566 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000567 return;
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000568
569 audiohw_set_mdb_shape(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000570}
571
572void sound_set_mdb_enable(int value)
573{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400574 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000575 return;
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000576
577 audiohw_set_mdb_enable(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000578}
579
580void sound_set_superbass(int value)
581{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400582 if (!audio_is_initialized)
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000583 return;
Marcin Bukat56c4e9f2010-10-31 21:09:34 +0000584
585 audiohw_set_superbass(value);
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000586}
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400587#endif /* CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F */
Kevin Ferrare9b5264d2005-11-06 03:18:34 +0000588
Michael Sevakise61e9c62013-04-20 04:06:13 -0400589#if defined(HAVE_PITCHCONTROL)
Alexander Levincc7c6652009-07-11 16:46:19 +0000590void sound_set_pitch(int32_t pitch)
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000591{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400592 if (!audio_is_initialized)
593 return;
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000594
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400595 audiohw_set_pitch(pitch);
Jens Arnoldb9ebe6a2005-05-22 12:45:35 +0000596}
597
Alexander Levincc7c6652009-07-11 16:46:19 +0000598int32_t sound_get_pitch(void)
Jens Arnoldb9ebe6a2005-05-22 12:45:35 +0000599{
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400600 if (!audio_is_initialized)
601 return PITCH_SPEED_100;
602
603 return audiohw_get_pitch();
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +0000604}
Michael Sevakis0c7b7872013-04-12 23:35:47 -0400605#endif /* HAVE_PITCHCONTROL */