diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2013-04-05 04:36:05 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2013-04-11 22:55:16 +0200 |
commit | f5a5b946867677de76c405ee72e2ea47e36e4c83 (patch) | |
tree | 8fb97a35059a16681b726973b4a5e13d41f96a35 /firmware/export/pcm-internal.h | |
parent | a9049a79d706dba61837ad02c7d7e3475cb6c193 (diff) | |
download | rockbox-f5a5b946867677de76c405ee72e2ea47e36e4c83.tar.gz rockbox-f5a5b946867677de76c405ee72e2ea47e36e4c83.zip |
Implement universal in-PCM-driver software volume control.
Implements double-buffered volume, balance and prescaling control in
the main PCM driver when HAVE_SW_VOLUME_CONTROL is defined ensuring
that all PCM is volume controlled and level changes are low in latency.
Supports -73 to +6 dB using a 15-bit factor so that no large-integer
math is needed.
Low-level hardware drivers do not have to implement it themselves but
parameters can be changed (currently defined in pcm-internal.h) to work
best with a particular SoC or to provide different volume ranges.
Volume and prescale calls should be made in the codec driver. It should
appear as a normal hardware interface. PCM volume calls expect .1 dB
units.
Change-Id: Idf6316a64ef4fb8abcede10707e1e6c6d01d57db
Reviewed-on: http://gerrit.rockbox.org/423
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested-by: Michael Sevakis <jethead71@rockbox.org>
Diffstat (limited to 'firmware/export/pcm-internal.h')
-rw-r--r-- | firmware/export/pcm-internal.h | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/firmware/export/pcm-internal.h b/firmware/export/pcm-internal.h index 397cf6832f..03e5c5e6e7 100644 --- a/firmware/export/pcm-internal.h +++ b/firmware/export/pcm-internal.h | |||
@@ -24,6 +24,19 @@ | |||
24 | 24 | ||
25 | #include "config.h" | 25 | #include "config.h" |
26 | 26 | ||
27 | #ifdef HAVE_SW_VOLUME_CONTROL | ||
28 | /* Default settings - architecture may have other optimal values */ | ||
29 | |||
30 | #define PCM_FACTOR_BITS 15 /* Allows -73 to +6dB gain, sans 64-bit math */ | ||
31 | #define PCM_PLAY_DBL_BUF_SAMPLES 1024 /* Max 4KByte chunks */ | ||
32 | #define PCM_DBL_BUF_BSS /* In DRAM, uncached may be better */ | ||
33 | #define PCM_FACTOR_MIN 0x00000 /* Minimum final factor */ | ||
34 | #define PCM_FACTOR_MAX 0x10000 /* Maximum final factor */ | ||
35 | |||
36 | #define PCM_FACTOR_UNITY (1 << PCM_FACTOR_BITS) | ||
37 | #endif /* HAVE_SW_VOLUME_CONTROL */ | ||
38 | |||
39 | #define PCM_SAMPLE_SIZE (2 * sizeof (int16_t)) | ||
27 | /* Cheapo buffer align macro to align to the 16-16 PCM size */ | 40 | /* Cheapo buffer align macro to align to the 16-16 PCM size */ |
28 | #define ALIGN_AUDIOBUF(start, size) \ | 41 | #define ALIGN_AUDIOBUF(start, size) \ |
29 | ({ (start) = (void *)(((uintptr_t)(start) + 3) & ~3); \ | 42 | ({ (start) = (void *)(((uintptr_t)(start) + 3) & ~3); \ |
@@ -34,6 +47,23 @@ void pcm_do_peak_calculation(struct pcm_peaks *peaks, bool active, | |||
34 | 47 | ||
35 | /** The following are for internal use between pcm.c and target- | 48 | /** The following are for internal use between pcm.c and target- |
36 | specific portion **/ | 49 | specific portion **/ |
50 | /* Call registered callback to obtain next buffer */ | ||
51 | static inline bool pcm_get_more_int(const void **addr, size_t *size) | ||
52 | { | ||
53 | extern volatile pcm_play_callback_type pcm_callback_for_more; | ||
54 | pcm_play_callback_type get_more = pcm_callback_for_more; | ||
55 | |||
56 | if (UNLIKELY(!get_more)) | ||
57 | return false; | ||
58 | |||
59 | *addr = NULL; | ||
60 | *size = 0; | ||
61 | get_more(addr, size); | ||
62 | ALIGN_AUDIOBUF(*addr, *size); | ||
63 | |||
64 | return *addr && *size; | ||
65 | } | ||
66 | |||
37 | static FORCE_INLINE enum pcm_dma_status pcm_call_status_cb( | 67 | static FORCE_INLINE enum pcm_dma_status pcm_call_status_cb( |
38 | pcm_status_callback_type callback, enum pcm_dma_status status) | 68 | pcm_status_callback_type callback, enum pcm_dma_status status) |
39 | { | 69 | { |
@@ -43,14 +73,34 @@ static FORCE_INLINE enum pcm_dma_status pcm_call_status_cb( | |||
43 | return callback(status); | 73 | return callback(status); |
44 | } | 74 | } |
45 | 75 | ||
46 | static FORCE_INLINE enum pcm_dma_status | 76 | static FORCE_INLINE enum pcm_dma_status pcm_play_call_status_cb( |
47 | pcm_play_dma_status_callback(enum pcm_dma_status status) | 77 | enum pcm_dma_status status) |
48 | { | 78 | { |
49 | extern enum pcm_dma_status | 79 | extern enum pcm_dma_status |
50 | (* volatile pcm_play_status_callback)(enum pcm_dma_status); | 80 | (* volatile pcm_play_status_callback)(enum pcm_dma_status); |
51 | return pcm_call_status_cb(pcm_play_status_callback, status); | 81 | return pcm_call_status_cb(pcm_play_status_callback, status); |
52 | } | 82 | } |
53 | 83 | ||
84 | static FORCE_INLINE enum pcm_dma_status | ||
85 | pcm_play_dma_status_callback(enum pcm_dma_status status) | ||
86 | { | ||
87 | #ifdef HAVE_SW_VOLUME_CONTROL | ||
88 | extern enum pcm_dma_status | ||
89 | pcm_play_dma_status_callback_int(enum pcm_dma_status status); | ||
90 | return pcm_play_dma_status_callback_int(status); | ||
91 | #else | ||
92 | return pcm_play_call_status_cb(status); | ||
93 | #endif /* HAVE_SW_VOLUME_CONTROL */ | ||
94 | } | ||
95 | |||
96 | #ifdef HAVE_SW_VOLUME_CONTROL | ||
97 | void pcm_play_dma_start_int(const void *addr, size_t size); | ||
98 | void pcm_play_dma_pause_int(bool pause); | ||
99 | void pcm_play_dma_stop_int(void); | ||
100 | void pcm_play_stop_int(void); | ||
101 | const void *pcm_play_dma_get_peak_buffer_int(int *count); | ||
102 | #endif /* HAVE_SW_VOLUME_CONTROL */ | ||
103 | |||
54 | /* Called by the bottom layer ISR when more data is needed. Returns true | 104 | /* Called by the bottom layer ISR when more data is needed. Returns true |
55 | * if a new buffer is available, false otherwise. */ | 105 | * if a new buffer is available, false otherwise. */ |
56 | bool pcm_play_dma_complete_callback(enum pcm_dma_status status, | 106 | bool pcm_play_dma_complete_callback(enum pcm_dma_status status, |