From f5a5b946867677de76c405ee72e2ea47e36e4c83 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Fri, 5 Apr 2013 04:36:05 -0400 Subject: 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 Tested-by: Michael Sevakis --- firmware/export/pcm-internal.h | 54 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'firmware/export/pcm-internal.h') 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 @@ #include "config.h" +#ifdef HAVE_SW_VOLUME_CONTROL +/* Default settings - architecture may have other optimal values */ + +#define PCM_FACTOR_BITS 15 /* Allows -73 to +6dB gain, sans 64-bit math */ +#define PCM_PLAY_DBL_BUF_SAMPLES 1024 /* Max 4KByte chunks */ +#define PCM_DBL_BUF_BSS /* In DRAM, uncached may be better */ +#define PCM_FACTOR_MIN 0x00000 /* Minimum final factor */ +#define PCM_FACTOR_MAX 0x10000 /* Maximum final factor */ + +#define PCM_FACTOR_UNITY (1 << PCM_FACTOR_BITS) +#endif /* HAVE_SW_VOLUME_CONTROL */ + +#define PCM_SAMPLE_SIZE (2 * sizeof (int16_t)) /* Cheapo buffer align macro to align to the 16-16 PCM size */ #define ALIGN_AUDIOBUF(start, size) \ ({ (start) = (void *)(((uintptr_t)(start) + 3) & ~3); \ @@ -34,6 +47,23 @@ void pcm_do_peak_calculation(struct pcm_peaks *peaks, bool active, /** The following are for internal use between pcm.c and target- specific portion **/ +/* Call registered callback to obtain next buffer */ +static inline bool pcm_get_more_int(const void **addr, size_t *size) +{ + extern volatile pcm_play_callback_type pcm_callback_for_more; + pcm_play_callback_type get_more = pcm_callback_for_more; + + if (UNLIKELY(!get_more)) + return false; + + *addr = NULL; + *size = 0; + get_more(addr, size); + ALIGN_AUDIOBUF(*addr, *size); + + return *addr && *size; +} + static FORCE_INLINE enum pcm_dma_status pcm_call_status_cb( pcm_status_callback_type callback, enum pcm_dma_status status) { @@ -43,14 +73,34 @@ static FORCE_INLINE enum pcm_dma_status pcm_call_status_cb( return callback(status); } -static FORCE_INLINE enum pcm_dma_status -pcm_play_dma_status_callback(enum pcm_dma_status status) +static FORCE_INLINE enum pcm_dma_status pcm_play_call_status_cb( + enum pcm_dma_status status) { extern enum pcm_dma_status (* volatile pcm_play_status_callback)(enum pcm_dma_status); return pcm_call_status_cb(pcm_play_status_callback, status); } +static FORCE_INLINE enum pcm_dma_status +pcm_play_dma_status_callback(enum pcm_dma_status status) +{ +#ifdef HAVE_SW_VOLUME_CONTROL + extern enum pcm_dma_status + pcm_play_dma_status_callback_int(enum pcm_dma_status status); + return pcm_play_dma_status_callback_int(status); +#else + return pcm_play_call_status_cb(status); +#endif /* HAVE_SW_VOLUME_CONTROL */ +} + +#ifdef HAVE_SW_VOLUME_CONTROL +void pcm_play_dma_start_int(const void *addr, size_t size); +void pcm_play_dma_pause_int(bool pause); +void pcm_play_dma_stop_int(void); +void pcm_play_stop_int(void); +const void *pcm_play_dma_get_peak_buffer_int(int *count); +#endif /* HAVE_SW_VOLUME_CONTROL */ + /* Called by the bottom layer ISR when more data is needed. Returns true * if a new buffer is available, false otherwise. */ bool pcm_play_dma_complete_callback(enum pcm_dma_status status, -- cgit v1.2.3