summaryrefslogtreecommitdiff
path: root/firmware/export
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-04-23 03:20:49 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-04-27 06:59:27 +0200
commit08199cd6cb1e2c600eb16ce077cc308fee82de33 (patch)
tree5c33c39092a5f5aa65f6ac104f3fee54c5041519 /firmware/export
parent370ed6de7c7596b2a1f6a2f99c8070bd179b4abd (diff)
downloadrockbox-08199cd6cb1e2c600eb16ce077cc308fee82de33.tar.gz
rockbox-08199cd6cb1e2c600eb16ce077cc308fee82de33.zip
Provide high resolution volume and prescaler to hosted targets.
HAVE_SW_VOLUME_CONTROL is required and at this time only affects the SDL targets using pcm-sdl.c. Enables balance control in SDL targets, unless mono volume is in use. Compiles software volume control as unbuffered when PCM_SW_VOLUME_UNBUFFERED is defined. This avoids the overhead and extra latency introduced by the double buffer when it is not needed. Use this config when the target's PCM driver is buffered and sufficient latency exists to perform safely the volume scaling. Simulated targets that are double-buffered when made as native targets remain so in the sim in order to run the same code. Change-Id: Ifa77d2d3ae7376c65afecdfc785a084478cb5ffb Reviewed-on: http://gerrit.rockbox.org/457 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested-by: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'firmware/export')
-rw-r--r--firmware/export/audiohw.h5
-rw-r--r--firmware/export/config.h18
-rw-r--r--firmware/export/hosted_codec.h5
-rw-r--r--firmware/export/pcm-internal.h39
-rw-r--r--firmware/export/pcm_sw_volume.h6
5 files changed, 60 insertions, 13 deletions
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index 843ac0c0c4..4379c20a79 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -111,11 +111,6 @@ struct sound_settings_info
111#include "hosted_codec.h" 111#include "hosted_codec.h"
112#endif 112#endif
113 113
114#if defined(SIMULATOR) && !defined(HAVE_SW_VOLUME_CONTROL)
115/* For now, without software volume control, sim only supports mono control */
116#define AUDIOHW_HAVE_MONO_VOLUME
117#endif
118
119/* convert caps into defines */ 114/* convert caps into defines */
120#ifdef AUDIOHW_CAPS 115#ifdef AUDIOHW_CAPS
121/* Tone controls */ 116/* Tone controls */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 6a4a4648c8..7d7a18cc23 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -1139,6 +1139,24 @@ Lyre prototype 1 */
1139#define ROCKBOX_HAS_LOGDISKF 1139#define ROCKBOX_HAS_LOGDISKF
1140#endif 1140#endif
1141 1141
1142#if defined(HAVE_SDL_AUDIO) \
1143 && !(CONFIG_PLATFORM & PLATFORM_MAEMO5) \
1144 && !defined(HAVE_SW_VOLUME_CONTROL) \
1145 && CONFIG_CODEC == SWCODEC
1146/* SW volume is needed for accurate control and no double buffering should be
1147 * required. If target uses SW volume, then its definitions are used instead
1148 * so things are as on target. */
1149#define HAVE_SW_VOLUME_CONTROL
1150#define PCM_SW_VOLUME_UNBUFFERED /* pcm driver itself is buffered */
1151#ifdef SIMULATOR
1152/* For sim, nice res for ~ -127dB..+36dB that so far covers all targets */
1153#define PCM_SW_VOLUME_FRACBITS (24)
1154#else
1155/* For app, use fractional-only setup for -79..+0, no large-integer math */
1156#define PCM_SW_VOLUME_FRACBITS (16)
1157#endif /* SIMULATOR */
1158#endif /* default SDL SW volume conditions */
1159
1142/* null audiohw setting macro for when codec header is included for reasons 1160/* null audiohw setting macro for when codec header is included for reasons
1143 other than audio support */ 1161 other than audio support */
1144#define AUDIOHW_SETTING(name, us, nd, st, minv, maxv, defv, expr...) 1162#define AUDIOHW_SETTING(name, us, nd, st, minv, maxv, defv, expr...)
diff --git a/firmware/export/hosted_codec.h b/firmware/export/hosted_codec.h
index 72495709e8..f5e92ed297 100644
--- a/firmware/export/hosted_codec.h
+++ b/firmware/export/hosted_codec.h
@@ -21,8 +21,13 @@
21#ifndef HOSTED_CODEC_H 21#ifndef HOSTED_CODEC_H
22#define HOSTED_CODEC_H 22#define HOSTED_CODEC_H
23 23
24#if defined(HAVE_SDL_AUDIO) \
25 && !(CONFIG_PLATFORM & PLATFORM_MAEMO5)
26AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -80, 0, 0)
27#else
24#define AUDIOHW_CAPS (MONO_VOL_CAP) 28#define AUDIOHW_CAPS (MONO_VOL_CAP)
25AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -99, 0, 0) 29AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -99, 0, 0)
30#endif /* CONFIG_PLATFORM & PLATFORM_SDL */
26 31
27#if (CONFIG_PLATFORM & PLATFORM_ANDROID) 32#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
28/* Bass and treble tone controls */ 33/* Bass and treble tone controls */
diff --git a/firmware/export/pcm-internal.h b/firmware/export/pcm-internal.h
index 03e5c5e6e7..2b73f64ef6 100644
--- a/firmware/export/pcm-internal.h
+++ b/firmware/export/pcm-internal.h
@@ -27,13 +27,36 @@
27#ifdef HAVE_SW_VOLUME_CONTROL 27#ifdef HAVE_SW_VOLUME_CONTROL
28/* Default settings - architecture may have other optimal values */ 28/* Default settings - architecture may have other optimal values */
29 29
30#define PCM_FACTOR_BITS 15 /* Allows -73 to +6dB gain, sans 64-bit math */ 30#ifndef PCM_SW_VOLUME_FRACBITS
31/* Allows -73 to +6dB gain, sans large integer math */
32#define PCM_SW_VOLUME_FRACBITS (15)
33#endif
34
35/* Constants selected based on integer math overflow avoidance */
36#if PCM_SW_VOLUME_FRACBITS <= 16
37#define PCM_FACTOR_MAX 0x00010000u
38#define PCM_FACTOR_UNITY (1u << PCM_SW_VOLUME_FRACBITS)
39#elif PCM_SW_VOLUME_FRACBITS <= 31
40#define PCM_FACTOR_MAX 0x80000000u
41#define PCM_FACTOR_UNITY (1u << PCM_SW_VOLUME_FRACBITS)
42#endif /* PCM_SW_VOLUME_FRACBITS */
43
44#ifdef PCM_SW_VOLUME_UNBUFFERED
45/* Copies buffer with volume scaling applied */
46void pcm_sw_volume_copy_buffer(void *dst, const void *src, size_t size);
47#define pcm_copy_buffer pcm_sw_volume_copy_buffer
48#else /* !PCM_SW_VOLUME_UNBUFFERED */
49#ifdef HAVE_SDL_AUDIO
50#define pcm_copy_buffer memcpy
51#endif
52#ifndef PCM_PLAY_DBL_BUF_SAMPLES
31#define PCM_PLAY_DBL_BUF_SAMPLES 1024 /* Max 4KByte chunks */ 53#define PCM_PLAY_DBL_BUF_SAMPLES 1024 /* Max 4KByte chunks */
54#endif
55#ifndef PCM_DBL_BUF_BSS
32#define PCM_DBL_BUF_BSS /* In DRAM, uncached may be better */ 56#define PCM_DBL_BUF_BSS /* In DRAM, uncached may be better */
33#define PCM_FACTOR_MIN 0x00000 /* Minimum final factor */ 57#endif
34#define PCM_FACTOR_MAX 0x10000 /* Maximum final factor */ 58#endif /* PCM_SW_VOLUME_UNBUFFERED */
35 59
36#define PCM_FACTOR_UNITY (1 << PCM_FACTOR_BITS)
37#endif /* HAVE_SW_VOLUME_CONTROL */ 60#endif /* HAVE_SW_VOLUME_CONTROL */
38 61
39#define PCM_SAMPLE_SIZE (2 * sizeof (int16_t)) 62#define PCM_SAMPLE_SIZE (2 * sizeof (int16_t))
@@ -84,22 +107,22 @@ static FORCE_INLINE enum pcm_dma_status pcm_play_call_status_cb(
84static FORCE_INLINE enum pcm_dma_status 107static FORCE_INLINE enum pcm_dma_status
85pcm_play_dma_status_callback(enum pcm_dma_status status) 108pcm_play_dma_status_callback(enum pcm_dma_status status)
86{ 109{
87#ifdef HAVE_SW_VOLUME_CONTROL 110#if defined(HAVE_SW_VOLUME_CONTROL) && !defined(PCM_SW_VOLUME_UNBUFFERED)
88 extern enum pcm_dma_status 111 extern enum pcm_dma_status
89 pcm_play_dma_status_callback_int(enum pcm_dma_status status); 112 pcm_play_dma_status_callback_int(enum pcm_dma_status status);
90 return pcm_play_dma_status_callback_int(status); 113 return pcm_play_dma_status_callback_int(status);
91#else 114#else
92 return pcm_play_call_status_cb(status); 115 return pcm_play_call_status_cb(status);
93#endif /* HAVE_SW_VOLUME_CONTROL */ 116#endif /* HAVE_SW_VOLUME_CONTROL && !PCM_SW_VOLUME_UNBUFFERED */
94} 117}
95 118
96#ifdef HAVE_SW_VOLUME_CONTROL 119#if defined(HAVE_SW_VOLUME_CONTROL) && !defined(PCM_SW_VOLUME_UNBUFFERED)
97void pcm_play_dma_start_int(const void *addr, size_t size); 120void pcm_play_dma_start_int(const void *addr, size_t size);
98void pcm_play_dma_pause_int(bool pause); 121void pcm_play_dma_pause_int(bool pause);
99void pcm_play_dma_stop_int(void); 122void pcm_play_dma_stop_int(void);
100void pcm_play_stop_int(void); 123void pcm_play_stop_int(void);
101const void *pcm_play_dma_get_peak_buffer_int(int *count); 124const void *pcm_play_dma_get_peak_buffer_int(int *count);
102#endif /* HAVE_SW_VOLUME_CONTROL */ 125#endif /* HAVE_SW_VOLUME_CONTROL && !PCM_SW_VOLUME_UNBUFFERED */
103 126
104/* Called by the bottom layer ISR when more data is needed. Returns true 127/* Called by the bottom layer ISR when more data is needed. Returns true
105 * if a new buffer is available, false otherwise. */ 128 * if a new buffer is available, false otherwise. */
diff --git a/firmware/export/pcm_sw_volume.h b/firmware/export/pcm_sw_volume.h
index b5d70654a1..5088eadeb1 100644
--- a/firmware/export/pcm_sw_volume.h
+++ b/firmware/export/pcm_sw_volume.h
@@ -21,6 +21,12 @@
21#ifndef PCM_SW_VOLUME_H 21#ifndef PCM_SW_VOLUME_H
22#define PCM_SW_VOLUME_H 22#define PCM_SW_VOLUME_H
23 23
24/***
25 ** Note: Only PCM drivers that are themselves buffered should use the
26 ** PCM_SW_VOLUME_UNBUFFERED configuration. This may be part of the platform,
27 ** the library or a hardware necessity. Normally, it shouldn't be used and
28 ** only the port developer can properly decide.
29 **/
24#ifdef HAVE_SW_VOLUME_CONTROL 30#ifdef HAVE_SW_VOLUME_CONTROL
25 31
26#include <audiohw.h> 32#include <audiohw.h>