From 16fba41d5079aec39d299dbf5481758320443dab Mon Sep 17 00:00:00 2001 From: inmarket Date: Mon, 23 Jun 2014 18:44:50 +1000 Subject: Added support for playing arbitrary format audio files with an intelligent audio processor like the VS1053 codec. Demo added. --- drivers/gaudio/vs1053/gaudio_play_config.h | 15 ++++++++++++- drivers/gaudio/vs1053/gaudio_play_lld.c | 34 ++++++++++++++++-------------- drivers/gaudio/vs1053/readme.txt | 14 ++++++++++-- 3 files changed, 44 insertions(+), 19 deletions(-) (limited to 'drivers') diff --git a/drivers/gaudio/vs1053/gaudio_play_config.h b/drivers/gaudio/vs1053/gaudio_play_config.h index bd2af503..51a3d273 100644 --- a/drivers/gaudio/vs1053/gaudio_play_config.h +++ b/drivers/gaudio/vs1053/gaudio_play_config.h @@ -14,10 +14,23 @@ /* Driver hardware support. */ /*===========================================================================*/ +/* Note: + * The VS1053 has an internal processor which can decode many file formats directly. + * If you want to use anything other than raw PCM then you should use GAUDIO_PLAY_FORMAT_FILE and pipe + * the entire file as if it was sound data. It doesn't matter if you choose the mono or stereo channel + * as the codec chip automatically detects the real format itself. + * No testing is made of the file format - if there is an error it can only be detected by the codec chip + * and its behaviour is undefined (we haven't tested). + * Note that some formats require a firmware patch to be installed to play correctly. + * In this case define VS1053_FIRMWARE_PATCH as TRUE in your gfxconf.h file and include the patch file + * in your project directory. The patch file MUST be called "vs1053_patch.plg". + */ #define GAUDIO_PLAY_MAX_SAMPLE_FREQUENCY 48000 -#define GAUDIO_PLAY_NUM_FORMATS 2 +#define GAUDIO_PLAY_NUM_FORMATS 3 #define GAUDIO_PLAY_FORMAT1 ARRAY_DATA_16BITSIGNED #define GAUDIO_PLAY_FORMAT2 ARRAY_DATA_8BITUNSIGNED +#define GAUDIO_PLAY_FORMAT3 ARRAY_DATA_UNKNOWN +#define GAUDIO_PLAY_FORMAT_FILE ARRAY_DATA_UNKNOWN #define GAUDIO_PLAY_NUM_CHANNELS 2 #define GAUDIO_PLAY_CHANNEL0_IS_STEREO FALSE #define GAUDIO_PLAY_CHANNEL1_IS_STEREO TRUE diff --git a/drivers/gaudio/vs1053/gaudio_play_lld.c b/drivers/gaudio/vs1053/gaudio_play_lld.c index fc62fea2..e6c66043 100644 --- a/drivers/gaudio/vs1053/gaudio_play_lld.c +++ b/drivers/gaudio/vs1053/gaudio_play_lld.c @@ -242,7 +242,7 @@ bool_t gaudio_play_lld_init(uint16_t channel, uint32_t frequency, ArrayDataForma 0xFF, 0xFF, 0xFF, 0xFF, }; - if (format != ARRAY_DATA_8BITUNSIGNED && format != ARRAY_DATA_16BITSIGNED) + if (format != ARRAY_DATA_8BITUNSIGNED && format != ARRAY_DATA_16BITSIGNED && format != ARRAY_DATA_UNKNOWN) return FALSE; if (frequency > VS1053_MAX_SAMPLE_RATE) return FALSE; @@ -254,21 +254,23 @@ bool_t gaudio_play_lld_init(uint16_t channel, uint32_t frequency, ArrayDataForma } // Setup - bps = (gfxSampleFormatBits(format)+7)/8; - if (channel == GAUDIO_PLAY_STEREO) - bps *= 2; - brate = frequency * bps; - - // Write the RIFF header - waitforready(); - data_write(hdr1, sizeof(hdr1)); - buf[0] = channel == GAUDIO_PLAY_STEREO ? 2 : 1; buf[1] = 0; data_write(buf, 2); - buf[0] = frequency; buf[1] = frequency>>8; buf[2] = frequency>>16; buf[3] = frequency>>24; data_write(buf, 4); - buf[0] = brate; buf[1] = brate>>8; buf[2] = brate>>16; buf[3] = brate>>24; data_write(buf, 4); - waitforready(); // 32 bytes max before checking - buf[0] = bps; buf[1] = 0; data_write(buf, 2); - buf[0] = gfxSampleFormatBits(format); buf[1] = 0; data_write(buf, 2); - data_write(hdr2, sizeof(hdr2)); + if (format == ARRAY_DATA_8BITUNSIGNED || format == ARRAY_DATA_16BITSIGNED) { + bps = (gfxSampleFormatBits(format)+7)/8; + if (channel == GAUDIO_PLAY_STEREO) + bps *= 2; + brate = frequency * bps; + + // Write the RIFF header + waitforready(); + data_write(hdr1, sizeof(hdr1)); + buf[0] = channel == GAUDIO_PLAY_STEREO ? 2 : 1; buf[1] = 0; data_write(buf, 2); + buf[0] = frequency; buf[1] = frequency>>8; buf[2] = frequency>>16; buf[3] = frequency>>24; data_write(buf, 4); + buf[0] = brate; buf[1] = brate>>8; buf[2] = brate>>16; buf[3] = brate>>24; data_write(buf, 4); + waitforready(); // 32 bytes max before checking + buf[0] = bps; buf[1] = 0; data_write(buf, 2); + buf[0] = gfxSampleFormatBits(format); buf[1] = 0; data_write(buf, 2); + data_write(hdr2, sizeof(hdr2)); + } return TRUE; } diff --git a/drivers/gaudio/vs1053/readme.txt b/drivers/gaudio/vs1053/readme.txt index 6e99e56f..d5d10145 100644 --- a/drivers/gaudio/vs1053/readme.txt +++ b/drivers/gaudio/vs1053/readme.txt @@ -1,4 +1,14 @@ This chip supports playing in many formats including MP3 etc. -For this driver however we only support PCM in 8 bit unisgned and 16 bit signed formats. +For this driver we support the standard PCM in 8 bit unsigned and 16 bit signed formats. -Requires GFX_USE_GTIMER \ No newline at end of file +Requires GFX_USE_GTIMER + + * The VS1053 has an internal processor which can decode many file formats directly. + * If you want to use anything other than raw PCM then you should use GAUDIO_PLAY_FORMAT_FILE and pipe + * the entire file as if it was sound data. It doesn't matter if you choose the mono or stereo channel + * as the codec chip automatically detects the real format itself. + * No testing is made of the file format - if there is an error it can only be detected by the codec chip + * and its behaviour is undefined (we haven't tested). + * Note that some formats require a firmware patch to be installed to play correctly. + * In this case define VS1053_FIRMWARE_PATCH as TRUE in your gfxconf.h file and include the patch file + * in your project directory. The patch file MUST be called "vs1053_patch.plg". -- cgit v1.2.3 From 7481e82dfc63c5f60533405268246d5d7d6450f2 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 23 Jun 2014 17:46:15 +0200 Subject: VS1053 poll rate is now an overridable value --- drivers/gaudio/vs1053/gaudio_play_lld.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/gaudio/vs1053/gaudio_play_lld.c b/drivers/gaudio/vs1053/gaudio_play_lld.c index e6c66043..b9b32b6e 100644 --- a/drivers/gaudio/vs1053/gaudio_play_lld.c +++ b/drivers/gaudio/vs1053/gaudio_play_lld.c @@ -25,6 +25,9 @@ #ifndef VS1053_FIRMWARE_PATCH #define VS1053_FIRMWARE_PATCH FALSE #endif +#ifndef VS1053_POLL_RATE + #define VS1053_POLL_RATAE 5 +#endif // Load the patch file if desired. New format patches only. #if VS1053_FIRMWARE_PATCH @@ -299,7 +302,7 @@ void gaudio_play_lld_start(void) { // Start the playing by starting the timer and executing FeedData immediately just to get things started // We really should set the timer to be equivalent to half the available data but that is just too hard to calculate. - gtimerStart(&playTimer, FeedData, 0, TRUE, 5); + gtimerStart(&playTimer, FeedData, 0, TRUE, VS1053_POLL_RATE); FeedData(0); } -- cgit v1.2.3 From 124e0fcc19919c83ae76aede59d48f010c0a1dc8 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Mon, 23 Jun 2014 17:50:55 +0200 Subject: typo --- drivers/gaudio/vs1053/gaudio_play_lld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/gaudio/vs1053/gaudio_play_lld.c b/drivers/gaudio/vs1053/gaudio_play_lld.c index b9b32b6e..b9c762e6 100644 --- a/drivers/gaudio/vs1053/gaudio_play_lld.c +++ b/drivers/gaudio/vs1053/gaudio_play_lld.c @@ -26,7 +26,7 @@ #define VS1053_FIRMWARE_PATCH FALSE #endif #ifndef VS1053_POLL_RATE - #define VS1053_POLL_RATAE 5 + #define VS1053_POLL_RATE 5 #endif // Load the patch file if desired. New format patches only. -- cgit v1.2.3 From dad27f76baa6d1ed8fe2a7bb1b6dc1926bc16fb7 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sat, 28 Jun 2014 06:33:47 +0200 Subject: fixing volume control for vs1053 --- drivers/gaudio/vs1053/gaudio_play_lld.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/gaudio/vs1053/gaudio_play_lld.c b/drivers/gaudio/vs1053/gaudio_play_lld.c index b9c762e6..8e7fb0a5 100644 --- a/drivers/gaudio/vs1053/gaudio_play_lld.c +++ b/drivers/gaudio/vs1053/gaudio_play_lld.c @@ -278,11 +278,19 @@ bool_t gaudio_play_lld_init(uint16_t channel, uint32_t frequency, ArrayDataForma } bool_t gaudio_play_lld_set_volume(uint8_t vol) { + uint16_t tmp; + // Volume is 0xFE -> 0x00. Adjust vol to match vol = ~vol; - if (vol == 0xFF) vol = 0xFE; + if (vol > 0xFE) + vol = 0xFE; + + tmp = 0; + tmp |= (( vol << VOL_LEFT_SHIFT ) & VOL_LEFT_MASK ); + tmp |= (( vol << VOL_RIGHT_SHIFT ) & VOL_RIGHT_MASK ); + + cmd_write(SCI_VOL, tmp); - cmd_write(SCI_VOL, ((uint16_t)vol) << 8 | vol); return TRUE; } -- cgit v1.2.3