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

Fork of VS1053b by Christian Schmiljun

Committer:
christi_s
Date:
Sat Jan 08 16:36:00 2011 +0000
Revision:
7:b6853a2c88c2
Parent:
6:eed008905159
Child:
8:5e4a21202223
extended documentation

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