summaryrefslogtreecommitdiff
path: root/firmware/export/audiohw.h
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-04-12 23:35:47 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-04-15 12:02:05 -0400
commit0c7b7873984e04941c9f21fa272638018fdb9a16 (patch)
treefb6afca45d2bef0a2c91732a39ffc0b965f5c557 /firmware/export/audiohw.h
parentfd9e2568908f91b5bcf7378dc28f6ec070d6027a (diff)
downloadrockbox-0c7b7873984e04941c9f21fa272638018fdb9a16.tar.gz
rockbox-0c7b7873984e04941c9f21fa272638018fdb9a16.zip
Straighten out the mad twisted state of sound.c and related areas.
This is going right in since it's long overdue. If anything is goofed, drop me a line or just tweak it yourself if you know what's wrong. :-) Make HW/SW codec interface more uniform when emulating HW functionality on SWCODEC for functions such as "audiohw_set_pitch". The firmware-to- DSP plumbing is in firmware/drivers/audiohw-swcodec.c. "sound_XXX" APIs are all in sound.c with none in DSP code any longer. Reduce number of settings definitions needed by each codec by providing defaults for common ones like balance, channels and SW tone controls. Remove need for separate SIM code and tables and add virtual codec header for hosted targets. Change-Id: I3f23702bca054fc9bda40f49824ce681bb7f777b
Diffstat (limited to 'firmware/export/audiohw.h')
-rw-r--r--firmware/export/audiohw.h149
1 files changed, 111 insertions, 38 deletions
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 304c5aa460..e18e996282 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -35,6 +35,35 @@
35#define TREBLE_CUTOFF_CAP (1 << 6) 35#define TREBLE_CUTOFF_CAP (1 << 6)
36#define EQ_CAP (1 << 7) 36#define EQ_CAP (1 << 7)
37#define DEPTH_3D_CAP (1 << 8) 37#define DEPTH_3D_CAP (1 << 8)
38#define LINEOUT_CAP (1 << 9)
39#define MONO_VOL_CAP (1 << 10)
40#define LIN_GAIN_CAP (1 << 11)
41#define MIC_GAIN_CAP (1 << 12)
42
43/* Used by every driver to export its min/max/default values for its audio
44 settings. */
45#ifdef AUDIOHW_IS_SOUND_C
46/* This is the master file with the settings table... */
47struct sound_settings_info
48{
49 const char *unit;
50 char numdecimals;
51 char steps;
52 short minval;
53 short maxval;
54 short defaultval;
55};
56
57#define AUDIOHW_SETTING(name, us, nd, st, minv, maxv, defv, expr...) \
58 static const struct sound_settings_info _audiohw_setting_##name = \
59 { .unit = us, .numdecimals = nd, .steps = st, \
60 .minval = minv, .maxval = maxv, .defaultval = defv }; \
61 static inline int _sound_val2phys_##name(int val) \
62 { return #expr[0] ? expr : val; }
63#else
64/* ...otherwise these produce nothing. */
65#define AUDIOHW_SETTING(name, us, nd, st, minv, maxv, defv, expr...)
66#endif
38 67
39#ifdef HAVE_UDA1380 68#ifdef HAVE_UDA1380
40#include "uda1380.h" 69#include "uda1380.h"
@@ -78,17 +107,25 @@
78#include "imx233-codec.h" 107#include "imx233-codec.h"
79#elif defined(HAVE_DUMMY_CODEC) 108#elif defined(HAVE_DUMMY_CODEC)
80#include "dummy_codec.h" 109#include "dummy_codec.h"
81#endif 110#elif (CONFIG_PLATFORM & (PLATFORM_ANDROID | PLATFORM_MAEMO\
82#if (CONFIG_PLATFORM & (PLATFORM_ANDROID|PLATFORM_MAEMO|PLATFORM_PANDORA|PLATFORM_SDL)) 111 | PLATFORM_PANDORA | PLATFORM_SDL))
83/* #include <SDL_audio.h> gives errors in other code areas, 112#include "hosted_codec.h"
84 * we don't really need it here, so don't. but it should maybe be fixed */
85#ifndef SIMULATOR /* simulator gets values from the target .h files */
86#define VOLUME_MIN -990
87#define VOLUME_MAX 0
88#endif
89#endif 113#endif
90 114
115#if defined(SIMULATOR) && !defined(HAVE_SW_VOLUME_CONTROL)
116/* For now, without software volume control, sim only supports mono control */
117#define AUDIOHW_HAVE_MONO_VOLUME
118#endif
91 119
120/* Some values are the same for every codec and can be defined here one
121 time. */
122#ifdef HAVE_SW_TONE_CONTROLS
123AUDIOHW_SETTING(BASS, "dB", 0, 1, -24, 24, 0)
124AUDIOHW_SETTING(TREBLE, "dB", 0, 1, -24, 24, 0)
125#endif /* HAVE_SW_TONE_CONTROLS */
126AUDIOHW_SETTING(BALANCE, "%", 0, 1, -100, 100, 0)
127AUDIOHW_SETTING(CHANNELS, "", 0, 1, 0, 5, 0)
128AUDIOHW_SETTING(STEREO_WIDTH, "%", 0, 5, 0, 250, 100)
92 129
93#define ONE_DB 10 130#define ONE_DB 10
94 131
@@ -246,7 +283,26 @@ enum AUDIOHW_EQ_SETTINGS
246#if (AUDIOHW_CAPS & DEPTH_3D_CAP) 283#if (AUDIOHW_CAPS & DEPTH_3D_CAP)
247#define AUDIOHW_HAVE_DEPTH_3D 284#define AUDIOHW_HAVE_DEPTH_3D
248#endif 285#endif
249#else 286
287#if (AUDIOHW_CAPS & LINEOUT_CAP)
288#define AUDIOHW_HAVE_LINEOUT
289#endif
290
291#if (AUDIOHW_CAPS & MONO_VOL_CAP)
292#define AUDIOHW_HAVE_MONO_VOLUME
293#endif
294
295#ifdef HAVE_RECORDING
296#if (AUDIOHW_CAPS & LIN_GAIN_CAP)
297#define AUDIOHW_HAVE_LIN_GAIN
298#endif
299
300#if (AUDIOHW_CAPS & MIC_GAIN_CAP)
301#define AUDIOHW_HAVE_MIC_GAIN
302#endif
303#endif /* HAVE_RECORDING */
304
305#else /* ndef AUDIOHW_CAPS */
250#if defined (HAVE_SW_TONE_CONTROLS) 306#if defined (HAVE_SW_TONE_CONTROLS)
251/* Needed for proper sound support */ 307/* Needed for proper sound support */
252#define AUDIOHW_HAVE_BASS 308#define AUDIOHW_HAVE_BASS
@@ -255,6 +311,7 @@ enum AUDIOHW_EQ_SETTINGS
255#endif /* AUDIOHW_CAPS */ 311#endif /* AUDIOHW_CAPS */
256 312
257enum { 313enum {
314 /* TODO: Volume shouldn't be needed if device doesn't have digital control */
258 SOUND_VOLUME = 0, 315 SOUND_VOLUME = 0,
259/* Tone control */ 316/* Tone control */
260#if defined(AUDIOHW_HAVE_BASS) 317#if defined(AUDIOHW_HAVE_BASS)
@@ -276,9 +333,11 @@ enum {
276 SOUND_MDB_ENABLE, 333 SOUND_MDB_ENABLE,
277 SOUND_SUPERBASS, 334 SOUND_SUPERBASS,
278#endif 335#endif
279#if defined(HAVE_RECORDING) 336#if defined(AUDIOHW_HAVE_LIN_GAIN)
280 SOUND_LEFT_GAIN, 337 SOUND_LEFT_GAIN,
281 SOUND_RIGHT_GAIN, 338 SOUND_RIGHT_GAIN,
339#endif
340#if defined(AUDIOHW_HAVE_MIC_GAIN)
282 SOUND_MIC_GAIN, 341 SOUND_MIC_GAIN,
283#endif 342#endif
284/* Bass and treble tone controls */ 343/* Bass and treble tone controls */
@@ -339,7 +398,8 @@ enum {
339 SOUND_LAST_SETTING, /* Keep this last */ 398 SOUND_LAST_SETTING, /* Keep this last */
340}; 399};
341 400
342enum Channel { 401enum Channel
402{
343 SOUND_CHAN_STEREO, 403 SOUND_CHAN_STEREO,
344 SOUND_CHAN_MONO, 404 SOUND_CHAN_MONO,
345 SOUND_CHAN_CUSTOM, 405 SOUND_CHAN_CUSTOM,
@@ -349,19 +409,6 @@ enum Channel {
349 SOUND_CHAN_NUM_MODES, 409 SOUND_CHAN_NUM_MODES,
350}; 410};
351 411
352struct sound_settings_info {
353 const char *unit;
354 char numdecimals;
355 char steps;
356 short minval;
357 short maxval;
358 short defaultval;
359};
360
361/* This struct is used by every driver to export its min/max/default values for
362 * its audio settings. Keep in mind that the order must be correct! */
363extern const struct sound_settings_info audiohw_settings[];
364
365/* All usable functions implemented by a audio codec drivers. Most of 412/* All usable functions implemented by a audio codec drivers. Most of
366 * the function in sound settings are only called, when in audio codecs 413 * the function in sound settings are only called, when in audio codecs
367 * .h file suitable defines are added. 414 * .h file suitable defines are added.
@@ -390,17 +437,35 @@ void audiohw_postinit(void);
390 */ 437 */
391void audiohw_close(void); 438void audiohw_close(void);
392 439
393#if defined(AUDIOHW_HAVE_CLIPPING) || defined(HAVE_SDL_AUDIO) || defined(ANDROID) 440#ifdef AUDIOHW_HAVE_MONO_VOLUME
394 /** 441 /**
395 * Set new volume value 442 * Set new volume value
396 * @param val to set. 443 * @param val to set.
397 * NOTE: AUDIOHW_CAPS need to contain 444 * NOTE: AUDIOHW_CAPS need to contain
398 * CLIPPING_CAP 445 * CLIPPING_CAP
399 */ 446 */
400void audiohw_set_volume(int val); 447void audiohw_set_volume(int val);
448#else /* Stereo volume */
449/**
450 * Set new voluem value for each channel
451 * @param vol_l sets left channel volume
452 * @param vol_r sets right channel volume
453 */
454void audiohw_set_volume(int vol_l, int vol_r);
455#endif /* AUDIOHW_HAVE_MONO_VOLUME */
456
457#ifdef AUDIOHW_HAVE_LINEOUT
458 /**
459 * Set new voluem value for each channel
460 * @param vol_l sets left channel volume
461 * @param vol_r sets right channel volume
462 */
463void audiohw_set_lineout_volume(int vol_l, int vol_r);
401#endif 464#endif
402 465
403#ifdef AUDIOHW_HAVE_PRESCALER 466#ifndef AUDIOHW_HAVE_CLIPPING
467#if defined(AUDIOHW_HAVE_BASS) || defined(AUDIOHW_HAVE_TREBLE) \
468 || defined(AUDIOHW_HAVE_EQ)
404/** 469/**
405 * Set new prescaler value. 470 * Set new prescaler value.
406 * @param val to set. 471 * @param val to set.
@@ -409,6 +474,7 @@ void audiohw_set_volume(int val);
409 */ 474 */
410void audiohw_set_prescaler(int val); 475void audiohw_set_prescaler(int val);
411#endif 476#endif
477#endif /* !AUDIOHW_HAVE_CLIPPING */
412 478
413#ifdef AUDIOHW_HAVE_BALANCE 479#ifdef AUDIOHW_HAVE_BALANCE
414/** 480/**
@@ -552,31 +618,38 @@ void audiohw_set_recvol(int left, int right, int type);
552void audiohw_set_monitor(bool enable); 618void audiohw_set_monitor(bool enable);
553#endif 619#endif
554 620
555
556
557#if CONFIG_CODEC != SWCODEC
558
559/* functions which are only used by mas35xx codecs, but are also
560 aviable on SWCODECS through dsp */
561
562/** 621/**
563 * Set channel configuration. 622 * Set channel configuration.
564 * @param val new channel value (see enum Channel). 623 * @param val new channel value (see enum Channel).
565 */ 624 */
566void audiohw_set_channel(int val); 625void audiohw_set_channel(int val);
567 626
627#ifdef HAVE_PITCHCONTROL
628/**
629 * Set the pitch ratio
630 * @param ratio to set in .01% units
631 */
632void audiohw_set_pitch(int32_t val);
633
634/**
635 * Return the set pitch ratio
636 */
637int32_t audiohw_get_pitch(void);
638#endif /* HAVE_PITCHCONTROL */
639
568/** 640/**
569 * Set stereo width. 641 * Set stereo width.
570 * @param val new stereo width value. 642 * @param val new stereo width value.
571 */ 643 */
572void audiohw_set_stereo_width(int val); 644void audiohw_set_stereo_width(int val);
573 645
574#endif /* CONFIG_CODEC != SWCODEC */
575
576#ifdef HAVE_SPEAKER 646#ifdef HAVE_SPEAKER
577
578void audiohw_enable_speaker(bool on); 647void audiohw_enable_speaker(bool on);
579
580#endif /* HAVE_SPEAKER */ 648#endif /* HAVE_SPEAKER */
581 649
650#if CONFIG_CODEC == SWCODEC
651typedef int (*audiohw_swcodec_cb_type)(int msg, intptr_t param);
652void audiohw_swcodec_set_callback(audiohw_swcodec_cb_type func);
653#endif /* CONFIG_CODEC == SWCODEC */
654
582#endif /* _AUDIOHW_H_ */ 655#endif /* _AUDIOHW_H_ */