Add the RTOS processing. for the Network radio streaming receiver.

Fork of VS1053b by Christian Schmiljun

Committer:
ban4jp
Date:
Sun Feb 22 14:44:41 2015 +0000
Revision:
10:114ac02a3875
Parent:
9:0d76f559a151
Add support the RTOS processing.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
christi_s 1:ced2c297cc1b 1 /* mbed VLSI VS1053b library
christi_s 1:ced2c297cc1b 2 * Copyright (c) 2010 Christian Schmiljun
christi_s 1:ced2c297cc1b 3 *
christi_s 1:ced2c297cc1b 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
christi_s 1:ced2c297cc1b 5 * of this software and associated documentation files (the "Software"), to deal
christi_s 1:ced2c297cc1b 6 * in the Software without restriction, including without limitation the rights
christi_s 1:ced2c297cc1b 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
christi_s 1:ced2c297cc1b 8 * copies of the Software, and to permit persons to whom the Software is
christi_s 1:ced2c297cc1b 9 * furnished to do so, subject to the following conditions:
christi_s 1:ced2c297cc1b 10 *
christi_s 1:ced2c297cc1b 11 * The above copyright notice and this permission notice shall be included in
christi_s 1:ced2c297cc1b 12 * all copies or substantial portions of the Software.
christi_s 1:ced2c297cc1b 13 *
christi_s 1:ced2c297cc1b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
christi_s 1:ced2c297cc1b 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
christi_s 1:ced2c297cc1b 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
christi_s 1:ced2c297cc1b 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
christi_s 1:ced2c297cc1b 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
christi_s 1:ced2c297cc1b 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
christi_s 1:ced2c297cc1b 20 * THE SOFTWARE.
christi_s 1:ced2c297cc1b 21 */
christi_s 1:ced2c297cc1b 22
christi_s 1:ced2c297cc1b 23 /* This code based on:
christi_s 1:ced2c297cc1b 24 * mbeduino_MP3_Shield_MP3Player
christi_s 1:ced2c297cc1b 25 * http://mbed.org/users/xshige/programs/mbeduino_MP3_Shield_MP3Player/lgcx63
christi_s 1:ced2c297cc1b 26 * 2010-10-16
christi_s 1:ced2c297cc1b 27 */
christi_s 1:ced2c297cc1b 28
christi_s 2:5bab956cb59e 29 #ifndef _VS1053_H
christi_s 2:5bab956cb59e 30 #define _VS1053_H
christi_s 1:ced2c297cc1b 31
christi_s 0:7728d9c6c487 32 // ----------------------------------------------------------------------------
christi_s 0:7728d9c6c487 33 // Extended settings
christi_s 0:7728d9c6c487 34 // ----------------------------------------------------------------------------
christi_s 1:ced2c297cc1b 35 // Enable debug output (Output -> printf ...)
christi_s 1:ced2c297cc1b 36 // --------------------------------------------------------------------------
christi_s 2:5bab956cb59e 37 // #define DEBUG
christi_s 2:5bab956cb59e 38 // #define DEBUGOUT (x,y...) printf(x, ##y);
christi_s 0:7728d9c6c487 39 // Patches, Addons
christi_s 0:7728d9c6c487 40 // --------------------------------------------------------------------------
christi_s 2:5bab956cb59e 41 // #define VS1053_PATCH_1_4_FLAC
christi_s 2:5bab956cb59e 42 // #define VS1053_PATCH_1_5
christi_s 2:5bab956cb59e 43 // #define VS1053_PATCH_1_5_FLAC
christi_s 2:5bab956cb59e 44 // #define VS1053_SPECANA
christi_s 2:5bab956cb59e 45 // #define VS1053B_PCM_RECORDER_0_9
christi_s 0:7728d9c6c487 46 // ----------------------------------------------------------------------------
christi_s 0:7728d9c6c487 47
christi_s 2:5bab956cb59e 48 #include "defines.h"
christi_s 2:5bab956cb59e 49 #include "mbed.h"
christi_s 2:5bab956cb59e 50
ban4jp 10:114ac02a3875 51 #ifdef VS1053_RTOS
ban4jp 10:114ac02a3875 52 #include "rtos.h"
ban4jp 10:114ac02a3875 53 #define START_THREAD 1
ban4jp 10:114ac02a3875 54 #endif
ban4jp 10:114ac02a3875 55
christi_s 1:ced2c297cc1b 56 #if defined(VS1053_PATCH_1_4_FLAC) && defined(VS1053_PATCH_1_5) && defined(VS1053_PATCH_1_5_FLAC) && defined(VS1053_SPECANA) && defined(VS1053B_PCM_RECORDER_0_9)
christi_s 1:ced2c297cc1b 57 #error "VS1053: Exclusive use of patch and app versions."
christi_s 1:ced2c297cc1b 58 #endif
christi_s 1:ced2c297cc1b 59 #if defined(VS1053_PATCH_1_4_FLAC) || defined(VS1053_PATCH_1_5) || defined(VS1053_PATCH_1_5_FLAC) || defined(VS1053_SPECANA) || defined(VS1053B_PCM_RECORDER_0_9)
christi_s 1:ced2c297cc1b 60 #define VS_PATCH
christi_s 0:7728d9c6c487 61 #endif
christi_s 0:7728d9c6c487 62
christi_s 2:5bab956cb59e 63 #ifndef DEBUGOUT
christi_s 2:5bab956cb59e 64 #define DEBUGOUT(x,y...)
christi_s 2:5bab956cb59e 65 #endif
christi_s 2:5bab956cb59e 66
christi_s 0:7728d9c6c487 67
christi_s 2:5bab956cb59e 68 #define DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT 0.0f
christi_s 2:5bab956cb59e 69 #define DEFAULT_VOLUME -40.0f
christi_s 2:5bab956cb59e 70 #define DEFAULT_BASS_AMPLITUDE 5 // 0 - 15 dB
christi_s 2:5bab956cb59e 71 #define DEFAULT_BASS_FREQUENCY 100 // 20 - 150 Hz
christi_s 2:5bab956cb59e 72 #define DEFAULT_TREBLE_AMPLITUDE 0 // -8 - 7 dB
christi_s 2:5bab956cb59e 73 #define DEFAULT_TREBLE_FREQUENCY 15000 //1000 - 15000 Hz
christi_s 0:7728d9c6c487 74
christi_s 8:5e4a21202223 75
christi_s 4:cacb5e663fa9 76
christi_s 0:7728d9c6c487 77 // SCI register address assignment
christi_s 3:88a645490529 78 #define SCI_MODE 0x00
christi_s 3:88a645490529 79 #define SCI_STATUS 0x01
christi_s 3:88a645490529 80 #define SCI_BASS 0x02
christi_s 3:88a645490529 81 #define SCI_CLOCKF 0x03
christi_s 6:eed008905159 82 #define SCI_DECODE_TIME 0x04
christi_s 3:88a645490529 83 #define SCI_AUDATA 0x05
christi_s 3:88a645490529 84 #define SCI_WRAM 0x06
christi_s 3:88a645490529 85 #define SCI_WRAMADDR 0x07
christi_s 3:88a645490529 86 #define SCI_HDAT0 0x08
christi_s 3:88a645490529 87 #define SCI_HDAT1 0x09
christi_s 3:88a645490529 88 #define SCI_AIADDR 0x0A
christi_s 3:88a645490529 89 #define SCI_VOL 0x0B
christi_s 3:88a645490529 90 #define SCI_AICTRL0 0x0C
christi_s 3:88a645490529 91 #define SCI_AICTRL1 0x0D
christi_s 3:88a645490529 92 #define SCI_AICTRL2 0x0E
christi_s 3:88a645490529 93 #define SCI_AICTRL3 0x0F
christi_s 0:7728d9c6c487 94
christi_s 0:7728d9c6c487 95
christi_s 0:7728d9c6c487 96 //SCI_MODE register bits as of p.38 of the datasheet
christi_s 3:88a645490529 97 #define SM_DIFF 0x0001
christi_s 3:88a645490529 98 #define SM_LAYER12 0x0002
christi_s 3:88a645490529 99 #define SM_RESET 0x0004
christi_s 3:88a645490529 100 #define SM_CANCEL 0x0008
christi_s 3:88a645490529 101 #define SM_EARSPEAKER_LO 0x0010
christi_s 3:88a645490529 102 #define SM_TESTS 0x0020
christi_s 3:88a645490529 103 #define SM_STREAM 0x0040
christi_s 3:88a645490529 104 #define SM_EARSPEAKER_HI 0x0080
christi_s 3:88a645490529 105 #define SM_DACT 0x0100
christi_s 3:88a645490529 106 #define SM_SDIORD 0x0200
christi_s 3:88a645490529 107 #define SM_SDISHARE 0x0400
christi_s 3:88a645490529 108 #define SM_SDINEW 0x0800
christi_s 3:88a645490529 109 #define SM_ADPCM 0x1000
christi_s 3:88a645490529 110 #define SM_B13 0x2000
christi_s 3:88a645490529 111 #define SM_LINE1 0x4000
christi_s 3:88a645490529 112 #define SM_CLK_RANGE 0x8000
christi_s 0:7728d9c6c487 113
christi_s 0:7728d9c6c487 114 //SCI_CLOCKF register bits as of p.42 of the datasheet
christi_s 3:88a645490529 115 #define SC_ADD_NOMOD 0x0000
christi_s 3:88a645490529 116 #define SC_ADD_10x 0x0800
christi_s 3:88a645490529 117 #define SC_ADD_15x 0x1000
christi_s 3:88a645490529 118 #define SC_ADD_20x 0x1800
christi_s 3:88a645490529 119 #define SC_MULT_XTALI 0x0000
christi_s 3:88a645490529 120 #define SC_MULT_XTALIx20 0x2000
christi_s 3:88a645490529 121 #define SC_MULT_XTALIx25 0x4000
christi_s 3:88a645490529 122 #define SC_MULT_XTALIx30 0x6000
christi_s 3:88a645490529 123 #define SC_MULT_XTALIx35 0x8000
christi_s 3:88a645490529 124 #define SC_MULT_XTALIx40 0xA000
christi_s 3:88a645490529 125 #define SC_MULT_XTALIx45 0xC000
christi_s 3:88a645490529 126 #define SC_MULT_XTALIx50 0xE000
christi_s 0:7728d9c6c487 127
christi_s 0:7728d9c6c487 128 // Extra Parameter in X memory (refer to p.58 of the datasheet)
christi_s 3:88a645490529 129 #define para_chipID_0 0x1E00
christi_s 3:88a645490529 130 #define para_chipID_1 0x1E01
christi_s 3:88a645490529 131 #define para_version 0x1E02
christi_s 3:88a645490529 132 #define para_config1 0x1E03
christi_s 3:88a645490529 133 #define para_playSpeed 0x1E04
christi_s 3:88a645490529 134 #define para_byteRate 0x1E05
christi_s 3:88a645490529 135 #define para_endFillByte 0x1E06
christi_s 0:7728d9c6c487 136 //
christi_s 3:88a645490529 137 #define para_positionMsec_0 0x1E27
christi_s 3:88a645490529 138 #define para_positionMsec_1 0x1E28
christi_s 3:88a645490529 139 #define para_resync 0x1E29
christi_s 4:cacb5e663fa9 140
ban4jp 10:114ac02a3875 141 #ifdef VS1053_RTOS
ban4jp 10:114ac02a3875 142 #define INTERRUPT_HANDLER_ENABLE _isPlay = true
ban4jp 10:114ac02a3875 143 #define INTERRUPT_HANDLER_DISABLE _isPlay = false
ban4jp 10:114ac02a3875 144 #else
christi_s 4:cacb5e663fa9 145 #define INTERRUPT_HANDLER_ENABLE _DREQ_INTERUPT_IN.rise(this, &VS1053::dataRequestHandler); timer.attach_us(this, &VS1053::dataRequestHandler, 1000)
christi_s 4:cacb5e663fa9 146 #define INTERRUPT_HANDLER_DISABLE _DREQ_INTERUPT_IN.rise(NULL); timer.detach()
ban4jp 10:114ac02a3875 147 #endif
christi_s 0:7728d9c6c487 148
christi_s 6:eed008905159 149
christi_s 7:b6853a2c88c2 150 /** Types of audio streams
christi_s 7:b6853a2c88c2 151 *
christi_s 7:b6853a2c88c2 152 */
christi_s 9:0d76f559a151 153 enum AudioType
christi_s 6:eed008905159 154 {
christi_s 7:b6853a2c88c2 155 WAV, /*!< WAVE audio stream */
christi_s 7:b6853a2c88c2 156 AAC, /*!< AAC audio stream (ADTS (.aac), MPEG2 ADIF (.aac) and MPEG4 AUDIO (.mp4 / .m4a / .3gp / .3g2)) */
christi_s 7:b6853a2c88c2 157 WMA, /*!< Windows Media Audio (WMA) stream */
christi_s 7:b6853a2c88c2 158 MIDI, /*!< Midi audio stream */
christi_s 7:b6853a2c88c2 159 OGG_VORBIS, /*!< Ogg Vorbis audio stream */
christi_s 7:b6853a2c88c2 160 MP3, /*!< MPEG Audio Layer */
christi_s 7:b6853a2c88c2 161 UNKNOWN /*!< Unknown */
christi_s 9:0d76f559a151 162 };
christi_s 9:0d76f559a151 163
christi_s 9:0d76f559a151 164 typedef enum AudioType AudioType;
christi_s 6:eed008905159 165
christi_s 7:b6853a2c88c2 166 /** Types of MPEG Audio Layer stream IDs.
christi_s 7:b6853a2c88c2 167 *
christi_s 7:b6853a2c88c2 168 */
christi_s 9:0d76f559a151 169 enum MP3_ID
christi_s 6:eed008905159 170 {
christi_s 7:b6853a2c88c2 171 MPG2_5a = 0, /*!< MPG 2.5, nonstandard, proprietary */
christi_s 7:b6853a2c88c2 172 MPG2_5b = 1, /*!< MPG 2.5, nonstandard, proprietary */
christi_s 7:b6853a2c88c2 173 MPG2_0 = 2, /*!< ISO 13818-3 MPG 2.0 */
christi_s 7:b6853a2c88c2 174 MPG1_0 = 3 /*!< ISO 11172-3 MPG 1.0 */
christi_s 9:0d76f559a151 175 };
christi_s 9:0d76f559a151 176
christi_s 9:0d76f559a151 177 typedef enum MP3_ID MP3_ID;
christi_s 6:eed008905159 178
christi_s 7:b6853a2c88c2 179 /** Types of MPEG Audio Layer channel modes.
christi_s 7:b6853a2c88c2 180 *
christi_s 7:b6853a2c88c2 181 */
christi_s 9:0d76f559a151 182 enum MP3_MODE
christi_s 6:eed008905159 183 {
christi_s 7:b6853a2c88c2 184 STEREO = 0, /*!< Stereo */
christi_s 7:b6853a2c88c2 185 JOINT_STEREO = 1, /*!< Joint Stereo */
christi_s 7:b6853a2c88c2 186 DUAL_CHANNEL = 2, /*!< Dual Channel */
christi_s 7:b6853a2c88c2 187 MONO = 3 /*!< Mono */
christi_s 9:0d76f559a151 188 };
christi_s 6:eed008905159 189
christi_s 9:0d76f559a151 190 typedef enum MP3_MODE MP3_MODE;
christi_s 6:eed008905159 191 /** Struct for informations about audio streams.
christi_s 6:eed008905159 192 *
christi_s 6:eed008905159 193 */
christi_s 6:eed008905159 194 typedef struct AudioInfo
christi_s 6:eed008905159 195 {
christi_s 7:b6853a2c88c2 196 AudioType type : 4; /*!< Type of the audio stream - important for the interpretation of the lower union */
christi_s 7:b6853a2c88c2 197 unsigned short kBitRate; /*!< Average bitrate of the audio stream - in kBit/s */
christi_s 7:b6853a2c88c2 198 unsigned short decodeTime; /*!< Decode time */
christi_s 6:eed008905159 199 union {
christi_s 6:eed008905159 200 struct {
christi_s 7:b6853a2c88c2 201 MP3_ID id : 2; /*!< ID */
christi_s 7:b6853a2c88c2 202 char layer : 2; /*!< Layer */
christi_s 7:b6853a2c88c2 203 char protrectBit : 1; /*!< Protect bit, see p.44 of the datasheet */
christi_s 7:b6853a2c88c2 204 char padBit : 1; /*!< Pad bit, see p.44 of the datasheet */
christi_s 7:b6853a2c88c2 205 MP3_MODE mode : 2; /*!< Channel mode */
christi_s 7:b6853a2c88c2 206 char extension : 2; /*!< Extension, see p.44 of the datasheet */
christi_s 7:b6853a2c88c2 207 char copyright : 1; /*!< Copyright, see p.44 of the datasheet */
christi_s 7:b6853a2c88c2 208 char original : 1; /*!< Original, see p.44 of the datasheet */
christi_s 7:b6853a2c88c2 209 char emphasis : 2; /*!< Emphasis, see p.44 of the datasheet */
christi_s 7:b6853a2c88c2 210 char kSampleRate : 6; /*!< Samplerate - in kHz (rounded) */
christi_s 7:b6853a2c88c2 211 } mp3; /*!< MPEG Audio Layer */
christi_s 6:eed008905159 212 struct {
christi_s 6:eed008905159 213
christi_s 7:b6853a2c88c2 214 } wma; /*!< Windows Media Audio (WMA) stream */
christi_s 6:eed008905159 215 struct {
christi_s 6:eed008905159 216
christi_s 7:b6853a2c88c2 217 } aac; /*!< AAC audio stream */
christi_s 6:eed008905159 218 struct {
christi_s 6:eed008905159 219
christi_s 7:b6853a2c88c2 220 } other; /*!< Other */
christi_s 6:eed008905159 221 } ext;
christi_s 6:eed008905159 222
christi_s 6:eed008905159 223 } AudioInfo;
christi_s 6:eed008905159 224
christi_s 2:5bab956cb59e 225 /** Class for VS1053 - Ogg Vorbis / MP3 / AAC / WMA / FLAC / MIDI Audio Codec Chip.
christi_s 7:b6853a2c88c2 226 * Datasheet, see http://www.vlsi.fi/fileadmin/datasheets/vlsi/vs1053.pdf
christi_s 2:5bab956cb59e 227 *
christi_s 2:5bab956cb59e 228 * This code based on:
christi_s 2:5bab956cb59e 229 * mbeduino_MP3_Shield_MP3Player
christi_s 2:5bab956cb59e 230 * http://mbed.org/users/xshige/programs/mbeduino_MP3_Shield_MP3Player/lgcx63
christi_s 2:5bab956cb59e 231 * 2010-10-16
christi_s 2:5bab956cb59e 232 *
christi_s 2:5bab956cb59e 233 * For the use of this class, a file "defines.h" must be created.
christi_s 2:5bab956cb59e 234 * It controls debug output and vs1053 patches.
christi_s 1:ced2c297cc1b 235 *
christi_s 2:5bab956cb59e 236 * defines.h:
christi_s 2:5bab956cb59e 237 *@code
christi_s 2:5bab956cb59e 238 * #ifndef _DEFINES_H
christi_s 2:5bab956cb59e 239 * #define _DEFINES_H
christi_s 2:5bab956cb59e 240 * // ----------------------------------------------------------------------------
christi_s 2:5bab956cb59e 241 * // debug output
christi_s 2:5bab956cb59e 242 * // ----------------------------------------------------------------------------
christi_s 2:5bab956cb59e 243 * // optional
christi_s 2:5bab956cb59e 244 * #define DEBUG
christi_s 2:5bab956cb59e 245 * #ifdef DEBUG
christi_s 2:5bab956cb59e 246 * # define DEBUGOUT(x,y...) printf(x, ##y);
christi_s 2:5bab956cb59e 247 * #else
christi_s 2:5bab956cb59e 248 * # define DEBUGOUT(x,y...)
christi_s 2:5bab956cb59e 249 * #endif
christi_s 2:5bab956cb59e 250 * // ----------------------------------------------------------------------------
christi_s 2:5bab956cb59e 251 * // VLSI VS1053b library, patch, apps
christi_s 2:5bab956cb59e 252 * // ----------------------------------------------------------------------------
christi_s 2:5bab956cb59e 253 * // optional, ONLY ONE
christi_s 2:5bab956cb59e 254 * //#define VS1053_PATCH_1_4_FLAC
christi_s 2:5bab956cb59e 255 * //#define VS1053_PATCH_1_5
christi_s 2:5bab956cb59e 256 * #define VS1053_PATCH_1_5_FLAC
christi_s 2:5bab956cb59e 257 * //#define VS1053_SPECANA
christi_s 2:5bab956cb59e 258 * //#define VS1053B_PCM_RECORDER_0_9
christi_s 2:5bab956cb59e 259 *
christi_s 7:b6853a2c88c2 260 * #endif //_DEFINES_H
christi_s 7:b6853a2c88c2 261 *@endcode
christi_s 1:ced2c297cc1b 262 *
christi_s 7:b6853a2c88c2 263 * For a complete sample, see http://mbed.org/users/christi_s/programs/Lib_VS1053b
christi_s 7:b6853a2c88c2 264 *
christi_s 1:ced2c297cc1b 265 */
christi_s 0:7728d9c6c487 266 class VS1053 {
christi_s 0:7728d9c6c487 267
christi_s 0:7728d9c6c487 268 public:
christi_s 1:ced2c297cc1b 269 /** Create a vs1053b object.
christi_s 1:ced2c297cc1b 270 *
christi_s 2:5bab956cb59e 271 * @param mosi
christi_s 2:5bab956cb59e 272 * SPI Master Out, Slave In pin to vs1053b.
christi_s 2:5bab956cb59e 273 * @param miso
christi_s 2:5bab956cb59e 274 * SPI Master In, Slave Out pin to vs1053b.
christi_s 2:5bab956cb59e 275 * @param sck
christi_s 2:5bab956cb59e 276 * SPI Clock pin to vs1053b.
christi_s 2:5bab956cb59e 277 * @param cs
christi_s 2:5bab956cb59e 278 * Pin to vs1053b control chip select.
christi_s 2:5bab956cb59e 279 * @param rst
christi_s 2:5bab956cb59e 280 * Pin to vs1053b reset.
christi_s 2:5bab956cb59e 281 * @param dreq
christi_s 2:5bab956cb59e 282 * Pin to vs1053b data request.
christi_s 2:5bab956cb59e 283 * @param dcs
christi_s 2:5bab956cb59e 284 * Pin to vs1053b data chip select.
christi_s 8:5e4a21202223 285 * @param buffer
christi_s 8:5e4a21202223 286 * Array to cache audio data.
christi_s 8:5e4a21202223 287 * @param buffer_size
christi_s 8:5e4a21202223 288 * Length of the array.
christi_s 1:ced2c297cc1b 289 */
christi_s 0:7728d9c6c487 290 VS1053(
christi_s 1:ced2c297cc1b 291 PinName mosi,
christi_s 1:ced2c297cc1b 292 PinName miso,
christi_s 1:ced2c297cc1b 293 PinName sck,
christi_s 1:ced2c297cc1b 294 PinName cs,
christi_s 1:ced2c297cc1b 295 PinName rst,
christi_s 1:ced2c297cc1b 296 PinName dreq,
christi_s 8:5e4a21202223 297 PinName dcs,
christi_s 8:5e4a21202223 298 char* buffer,
christi_s 8:5e4a21202223 299 int buffer_size
christi_s 8:5e4a21202223 300 );
christi_s 0:7728d9c6c487 301
christi_s 1:ced2c297cc1b 302 /** Reset the vs1053b. (hardware reset)
christi_s 1:ced2c297cc1b 303 *
christi_s 1:ced2c297cc1b 304 */
christi_s 2:5bab956cb59e 305 void reset(void);
christi_s 5:ead95c0f7800 306
christi_s 5:ead95c0f7800 307 /** Stop the playback if the song is completed.
christi_s 5:ead95c0f7800 308 * You must call this function for default playback.
christi_s 5:ead95c0f7800 309 *
christi_s 5:ead95c0f7800 310 */
christi_s 1:ced2c297cc1b 311 void terminateStream(void);
christi_s 1:ced2c297cc1b 312
christi_s 2:5bab956cb59e 313 /** Initialize the vs1053b device.
christi_s 1:ced2c297cc1b 314 *
christi_s 2:5bab956cb59e 315 * @return
christi_s 2:5bab956cb59e 316 * TRUE on success, FALSE on failure.
christi_s 1:ced2c297cc1b 317 */
christi_s 2:5bab956cb59e 318 bool initialize(void);
christi_s 1:ced2c297cc1b 319
christi_s 2:5bab956cb59e 320 /** Set the volume.
christi_s 2:5bab956cb59e 321 *
christi_s 2:5bab956cb59e 322 * @param volume
christi_s 2:5bab956cb59e 323 * Volume -0.5dB, -1.0dB, .. -64.0dB.
christi_s 2:5bab956cb59e 324 */
christi_s 2:5bab956cb59e 325 void setVolume(float volume = DEFAULT_VOLUME);
christi_s 2:5bab956cb59e 326
christi_s 2:5bab956cb59e 327 /** Get the volume.
christi_s 2:5bab956cb59e 328 *
christi_s 2:5bab956cb59e 329 * @return
christi_s 2:5bab956cb59e 330 * Return the volume in dB.
christi_s 2:5bab956cb59e 331 */
christi_s 1:ced2c297cc1b 332 float getVolume();
christi_s 1:ced2c297cc1b 333
christi_s 2:5bab956cb59e 334 /** Set the balance - volume difference between left-right.
christi_s 2:5bab956cb59e 335 *
christi_s 2:5bab956cb59e 336 * @param balance
christi_s 2:5bab956cb59e 337 * Difference in dB.
christi_s 2:5bab956cb59e 338 */
christi_s 2:5bab956cb59e 339 void setBalance(float balance = DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT);
christi_s 2:5bab956cb59e 340
christi_s 2:5bab956cb59e 341 /** Get the balance - volume difference between left-right.
christi_s 2:5bab956cb59e 342 *
christi_s 2:5bab956cb59e 343 * @return
christi_s 2:5bab956cb59e 344 * Difference in dB.
christi_s 2:5bab956cb59e 345 */
christi_s 1:ced2c297cc1b 346 float getBalance();
christi_s 2:5bab956cb59e 347
christi_s 2:5bab956cb59e 348 /** Get the treble frequency limit.
christi_s 2:5bab956cb59e 349 *
christi_s 2:5bab956cb59e 350 * @return
christi_s 2:5bab956cb59e 351 * Frequenzy 1000, 2000 .. 15000Hz.
christi_s 2:5bab956cb59e 352 */
christi_s 2:5bab956cb59e 353 int getTrebleFrequency(void);
christi_s 2:5bab956cb59e 354 /** Set the treble frequency limit.
christi_s 2:5bab956cb59e 355 *
christi_s 2:5bab956cb59e 356 * @param frequency
christi_s 2:5bab956cb59e 357 * Frequenzy 1000, 2000, .. 15000Hz.
christi_s 2:5bab956cb59e 358 */
christi_s 2:5bab956cb59e 359 void setTrebleFrequency(int frequency = DEFAULT_TREBLE_FREQUENCY);
christi_s 1:ced2c297cc1b 360
christi_s 2:5bab956cb59e 361 /** Get the treble amplitude.
christi_s 2:5bab956cb59e 362 *
christi_s 2:5bab956cb59e 363 * @return
christi_s 2:5bab956cb59e 364 * Amplitude -8 .. 7dB (in 1.5dB steps); 0 = off.
christi_s 2:5bab956cb59e 365 */
christi_s 2:5bab956cb59e 366 int getTrebleAmplitude(void);
christi_s 2:5bab956cb59e 367 /** Set the treble amplitude.
christi_s 2:5bab956cb59e 368 *
christi_s 2:5bab956cb59e 369 * @param amplitude
christi_s 2:5bab956cb59e 370 * Amplitude -8 .. 7dB (in 1.5dB steps); 0 = off.
christi_s 2:5bab956cb59e 371 */
christi_s 2:5bab956cb59e 372 void setTrebleAmplitude(int amplitude = DEFAULT_TREBLE_AMPLITUDE);
christi_s 1:ced2c297cc1b 373
christi_s 2:5bab956cb59e 374 /** Get the bass frequency limit.
christi_s 2:5bab956cb59e 375 *
christi_s 2:5bab956cb59e 376 * @return
christi_s 2:5bab956cb59e 377 * Frequenzy 20, 30, .. 150Hz.
christi_s 2:5bab956cb59e 378 */
christi_s 2:5bab956cb59e 379 int getBassFrequency(void);
christi_s 2:5bab956cb59e 380 /** Set the bass frequency limit.
christi_s 2:5bab956cb59e 381 *
christi_s 2:5bab956cb59e 382 * @param frequency
christi_s 2:5bab956cb59e 383 * Frequenzy 20, 30, .. 150Hz.
christi_s 2:5bab956cb59e 384 */
christi_s 2:5bab956cb59e 385 void setBassFrequency(int frequency= DEFAULT_BASS_FREQUENCY);
christi_s 2:5bab956cb59e 386
christi_s 2:5bab956cb59e 387 /** Get the bass amplitude.
christi_s 2:5bab956cb59e 388 *
christi_s 2:5bab956cb59e 389 * @return
christi_s 2:5bab956cb59e 390 * Amplitude 0 .. 15dB (in 1dB steps); 0 = off.
christi_s 2:5bab956cb59e 391 */
christi_s 2:5bab956cb59e 392 int getBassAmplitude(void);
christi_s 2:5bab956cb59e 393 /** Set the bass amplitude.
christi_s 2:5bab956cb59e 394 *
christi_s 2:5bab956cb59e 395 * @param amplitude
christi_s 2:5bab956cb59e 396 * Amplitude 0 .. 15dB (in 1dB steps); 0 = off.
christi_s 2:5bab956cb59e 397 */
christi_s 2:5bab956cb59e 398 void setBassAmplitude(int amplitude = DEFAULT_BASS_AMPLITUDE);
christi_s 2:5bab956cb59e 399
christi_s 2:5bab956cb59e 400 /** Set the speed of a playback.
christi_s 2:5bab956cb59e 401 *
christi_s 2:5bab956cb59e 402 * @param speed
christi_s 5:ead95c0f7800 403 * Speed 0, 1, .. (0, 1 normal speed).
christi_s 5:ead95c0f7800 404 * Speeds greater 2 are not recommended, buffer must be filled quickly enough.
christi_s 2:5bab956cb59e 405 */
christi_s 4:cacb5e663fa9 406 void setPlaySpeed(unsigned short speed);
christi_s 4:cacb5e663fa9 407
christi_s 5:ead95c0f7800 408 /** Copy a byte into the audio data buffer.
christi_s 5:ead95c0f7800 409 *
christi_s 5:ead95c0f7800 410 * @param c
christi_s 5:ead95c0f7800 411 * Data for the buffer.
christi_s 5:ead95c0f7800 412 *
christi_s 5:ead95c0f7800 413 * @return
christi_s 5:ead95c0f7800 414 * TRUE on success; FALSE on failure, c isn't copied in the buffer.
christi_s 5:ead95c0f7800 415 */
christi_s 8:5e4a21202223 416 bool bufferSetByte(char c);
christi_s 5:ead95c0f7800 417
christi_s 5:ead95c0f7800 418 /** Copy a array of bytes into the audio data buffer.
christi_s 5:ead95c0f7800 419 *
christi_s 5:ead95c0f7800 420 * @param s
christi_s 5:ead95c0f7800 421 * Data for the buffer.
christi_s 5:ead95c0f7800 422 *
christi_s 5:ead95c0f7800 423 * @param length
christi_s 5:ead95c0f7800 424 * Size of data array.
christi_s 5:ead95c0f7800 425 *
christi_s 5:ead95c0f7800 426 * @return
christi_s 5:ead95c0f7800 427 * TRUE on success; FALSE on failure, s isn't copied in the buffer.
christi_s 5:ead95c0f7800 428 */
christi_s 8:5e4a21202223 429 bool bufferPutStream(const char *s, unsigned int length);
christi_s 5:ead95c0f7800 430
christi_s 5:ead95c0f7800 431 /** Get the free space of the audio data buffer.
christi_s 5:ead95c0f7800 432 *
christi_s 5:ead95c0f7800 433 * @return
christi_s 5:ead95c0f7800 434 * Space 0 .. BUFFER_SIZE - 1.
christi_s 5:ead95c0f7800 435 */
christi_s 4:cacb5e663fa9 436 unsigned int bufferFree(void);
christi_s 5:ead95c0f7800 437
christi_s 5:ead95c0f7800 438 /** Get the busy space of the audio data buffer.
christi_s 5:ead95c0f7800 439 *
christi_s 5:ead95c0f7800 440 * @return
christi_s 5:ead95c0f7800 441 * Space 0 .. BUFFER_SIZE - 1.
christi_s 5:ead95c0f7800 442 */
christi_s 8:5e4a21202223 443 unsigned int bufferCount(void);
christi_s 8:5e4a21202223 444
christi_s 8:5e4a21202223 445 /** Complete length of the audio buffer.
christi_s 8:5e4a21202223 446 *
christi_s 8:5e4a21202223 447 * @return
christi_s 8:5e4a21202223 448 * Buffer length.
christi_s 8:5e4a21202223 449 */
christi_s 8:5e4a21202223 450 unsigned int bufferLength(void);
christi_s 4:cacb5e663fa9 451
christi_s 5:ead95c0f7800 452 /** Start playing audio from buffer.
christi_s 5:ead95c0f7800 453 *
christi_s 5:ead95c0f7800 454 */
christi_s 4:cacb5e663fa9 455 void play(void);
christi_s 5:ead95c0f7800 456
christi_s 5:ead95c0f7800 457 /** Interrupt the playback.
christi_s 5:ead95c0f7800 458 *
christi_s 5:ead95c0f7800 459 */
christi_s 4:cacb5e663fa9 460 void pause(void);
christi_s 5:ead95c0f7800 461
christi_s 5:ead95c0f7800 462 /** Stop the playback in the middle of a song.
christi_s 5:ead95c0f7800 463 * After this call, you can now send the next audio file to buffer.
christi_s 5:ead95c0f7800 464 *
christi_s 5:ead95c0f7800 465 */
christi_s 4:cacb5e663fa9 466 void stop(void);
christi_s 6:eed008905159 467
christi_s 6:eed008905159 468 /** Get information about played audio stream.
christi_s 6:eed008905159 469 *
christi_s 6:eed008905159 470 * @param aInfo
christi_s 6:eed008905159 471 * Return value for the informations.
christi_s 6:eed008905159 472 *
christi_s 6:eed008905159 473 */
christi_s 6:eed008905159 474 void getAudioInfo(AudioInfo* aInfo);
christi_s 1:ced2c297cc1b 475
christi_s 1:ced2c297cc1b 476 protected:
christi_s 1:ced2c297cc1b 477 unsigned short int wram_read(unsigned short int);
christi_s 1:ced2c297cc1b 478 void wram_write(unsigned short int, unsigned short int);
christi_s 1:ced2c297cc1b 479 void write_plugin(const unsigned short* , unsigned int);
christi_s 0:7728d9c6c487 480 void cs_low(void);
christi_s 0:7728d9c6c487 481 void cs_high(void);
christi_s 0:7728d9c6c487 482 void dcs_low(void);
christi_s 0:7728d9c6c487 483 void dcs_high(void);
christi_s 0:7728d9c6c487 484 void sci_en(void);
christi_s 0:7728d9c6c487 485 void sci_dis(void);
christi_s 0:7728d9c6c487 486 void sdi_en(void);
christi_s 0:7728d9c6c487 487 void sdi_dis(void);
christi_s 0:7728d9c6c487 488
christi_s 1:ced2c297cc1b 489 void spi_initialise(void);
christi_s 1:ced2c297cc1b 490
christi_s 0:7728d9c6c487 491 void sdi_initialise(void);
christi_s 0:7728d9c6c487 492
christi_s 0:7728d9c6c487 493 void sci_write(unsigned char, unsigned short int);
christi_s 0:7728d9c6c487 494 void sdi_write(unsigned char);
christi_s 0:7728d9c6c487 495 unsigned short int sci_read(unsigned short int);
christi_s 0:7728d9c6c487 496 void sine_test_activate(unsigned char);
christi_s 0:7728d9c6c487 497
christi_s 0:7728d9c6c487 498 void sine_test_deactivate(void);
christi_s 0:7728d9c6c487 499
christi_s 1:ced2c297cc1b 500 void changeVolume(void);
christi_s 4:cacb5e663fa9 501
christi_s 1:ced2c297cc1b 502
christi_s 2:5bab956cb59e 503 // TODO
christi_s 2:5bab956cb59e 504 void power_down(void);
christi_s 4:cacb5e663fa9 505
christi_s 2:5bab956cb59e 506 void changeBass(void);
christi_s 1:ced2c297cc1b 507
christi_s 4:cacb5e663fa9 508 unsigned char bufferGetByte(void);
christi_s 4:cacb5e663fa9 509 void bufferReset(void);
ban4jp 10:114ac02a3875 510 #ifdef VS1053_RTOS
ban4jp 10:114ac02a3875 511 static void dataRequestHandler_start(const void *args);
ban4jp 10:114ac02a3875 512 #endif
christi_s 4:cacb5e663fa9 513 void dataRequestHandler(void);
christi_s 2:5bab956cb59e 514
christi_s 4:cacb5e663fa9 515 SPI _spi;
christi_s 4:cacb5e663fa9 516 DigitalOut _CS;
christi_s 4:cacb5e663fa9 517 DigitalOut _RST;
christi_s 4:cacb5e663fa9 518 DigitalOut _DCS;
christi_s 4:cacb5e663fa9 519 DigitalIn _DREQ;
ban4jp 10:114ac02a3875 520 #ifdef DEBUG
ban4jp 10:114ac02a3875 521 DigitalOut _led;
ban4jp 10:114ac02a3875 522 #endif
ban4jp 10:114ac02a3875 523
ban4jp 10:114ac02a3875 524 #ifdef VS1053_RTOS
ban4jp 10:114ac02a3875 525 Thread _thread;
ban4jp 10:114ac02a3875 526 #else
christi_s 4:cacb5e663fa9 527 InterruptIn _DREQ_INTERUPT_IN;
ban4jp 10:114ac02a3875 528 #endif
christi_s 4:cacb5e663fa9 529
christi_s 8:5e4a21202223 530 char* _buffer;
christi_s 8:5e4a21202223 531 char* _bufferReadPointer;
christi_s 8:5e4a21202223 532 char* _bufferWritePointer;
christi_s 8:5e4a21202223 533 int BUFFER_SIZE;
christi_s 4:cacb5e663fa9 534
christi_s 4:cacb5e663fa9 535 bool _isIdle;
ban4jp 10:114ac02a3875 536 bool _isPlay;
christi_s 4:cacb5e663fa9 537
christi_s 2:5bab956cb59e 538 // variables to save
christi_s 2:5bab956cb59e 539 // volume, values in db
christi_s 4:cacb5e663fa9 540 float _balance;
christi_s 4:cacb5e663fa9 541 float _volume;
christi_s 2:5bab956cb59e 542 // bass enhancer settings
christi_s 4:cacb5e663fa9 543 int _sb_amplitude;
christi_s 4:cacb5e663fa9 544 int _sb_freqlimit;
christi_s 4:cacb5e663fa9 545 int _st_amplitude;
christi_s 8:5e4a21202223 546 int _st_freqlimit;
christi_s 8:5e4a21202223 547
christi_s 4:cacb5e663fa9 548
christi_s 4:cacb5e663fa9 549 Ticker timer;
christi_s 4:cacb5e663fa9 550
christi_s 6:eed008905159 551 static const char _sampleRateTable[4][4]; // _sampleRateTable[id][srate]
christi_s 6:eed008905159 552
christi_s 0:7728d9c6c487 553 };
christi_s 4:cacb5e663fa9 554
christi_s 0:7728d9c6c487 555 #endif