Add the RTOS processing. for the Network radio streaming receiver.
Fork of VS1053b by
VS1053.h@6:eed008905159, 2011-01-08 (annotated)
- Committer:
- christi_s
- Date:
- Sat Jan 08 15:45:58 2011 +0000
- Revision:
- 6:eed008905159
- Parent:
- 5:ead95c0f7800
- Child:
- 7:b6853a2c88c2
fix loading VS1053_PATCH_1_5
add audio stream information
Who changed what in which revision?
User | Revision | Line number | New 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 | 6:eed008905159 | 140 | |
christi_s | 6:eed008905159 | 141 | typedef enum AudioType |
christi_s | 6:eed008905159 | 142 | { |
christi_s | 6:eed008905159 | 143 | WAV, |
christi_s | 6:eed008905159 | 144 | AAC, |
christi_s | 6:eed008905159 | 145 | WMA, |
christi_s | 6:eed008905159 | 146 | MIDI, |
christi_s | 6:eed008905159 | 147 | OGG_VORBIS, |
christi_s | 6:eed008905159 | 148 | MP3, |
christi_s | 6:eed008905159 | 149 | UNKNOWN |
christi_s | 6:eed008905159 | 150 | } AudioType; |
christi_s | 6:eed008905159 | 151 | |
christi_s | 6:eed008905159 | 152 | typedef enum MP3_ID |
christi_s | 6:eed008905159 | 153 | { |
christi_s | 6:eed008905159 | 154 | MPG2_5a = 0, |
christi_s | 6:eed008905159 | 155 | MPG2_5b = 1, |
christi_s | 6:eed008905159 | 156 | MPG2_0 = 2, |
christi_s | 6:eed008905159 | 157 | MPG1_0 = 3 |
christi_s | 6:eed008905159 | 158 | } MP3_ID; |
christi_s | 6:eed008905159 | 159 | |
christi_s | 6:eed008905159 | 160 | typedef enum MP3_MODE |
christi_s | 6:eed008905159 | 161 | { |
christi_s | 6:eed008905159 | 162 | STEREO = 0, |
christi_s | 6:eed008905159 | 163 | JOINT_STEREO = 1, |
christi_s | 6:eed008905159 | 164 | DUAL_CHANNEL = 2, |
christi_s | 6:eed008905159 | 165 | MONO = 3 |
christi_s | 6:eed008905159 | 166 | } MP3_MODE; |
christi_s | 6:eed008905159 | 167 | |
christi_s | 6:eed008905159 | 168 | /** Struct for informations about audio streams. |
christi_s | 6:eed008905159 | 169 | * |
christi_s | 6:eed008905159 | 170 | */ |
christi_s | 6:eed008905159 | 171 | typedef struct AudioInfo |
christi_s | 6:eed008905159 | 172 | { |
christi_s | 6:eed008905159 | 173 | AudioType type : 4; |
christi_s | 6:eed008905159 | 174 | unsigned short kBitRate; |
christi_s | 6:eed008905159 | 175 | unsigned short decodeTime; |
christi_s | 6:eed008905159 | 176 | union { |
christi_s | 6:eed008905159 | 177 | struct { |
christi_s | 6:eed008905159 | 178 | MP3_ID id : 2; |
christi_s | 6:eed008905159 | 179 | char layer : 2; |
christi_s | 6:eed008905159 | 180 | char protrectBit : 1; |
christi_s | 6:eed008905159 | 181 | char padBit : 1; |
christi_s | 6:eed008905159 | 182 | MP3_MODE mode : 2; |
christi_s | 6:eed008905159 | 183 | char extension : 2; |
christi_s | 6:eed008905159 | 184 | char copyright : 1; |
christi_s | 6:eed008905159 | 185 | char original : 1; |
christi_s | 6:eed008905159 | 186 | char emphasis : 2; |
christi_s | 6:eed008905159 | 187 | char kSampleRate : 6; |
christi_s | 6:eed008905159 | 188 | } mp3; |
christi_s | 6:eed008905159 | 189 | struct { |
christi_s | 6:eed008905159 | 190 | |
christi_s | 6:eed008905159 | 191 | } wma; |
christi_s | 6:eed008905159 | 192 | struct { |
christi_s | 6:eed008905159 | 193 | |
christi_s | 6:eed008905159 | 194 | } aac; |
christi_s | 6:eed008905159 | 195 | struct { |
christi_s | 6:eed008905159 | 196 | |
christi_s | 6:eed008905159 | 197 | } other; |
christi_s | 6:eed008905159 | 198 | } ext; |
christi_s | 6:eed008905159 | 199 | |
christi_s | 6:eed008905159 | 200 | } AudioInfo; |
christi_s | 6:eed008905159 | 201 | |
christi_s | 2:5bab956cb59e | 202 | /** Class for VS1053 - Ogg Vorbis / MP3 / AAC / WMA / FLAC / MIDI Audio Codec Chip. |
christi_s | 2:5bab956cb59e | 203 | * |
christi_s | 2:5bab956cb59e | 204 | * This code based on: |
christi_s | 2:5bab956cb59e | 205 | * mbeduino_MP3_Shield_MP3Player |
christi_s | 2:5bab956cb59e | 206 | * http://mbed.org/users/xshige/programs/mbeduino_MP3_Shield_MP3Player/lgcx63 |
christi_s | 2:5bab956cb59e | 207 | * 2010-10-16 |
christi_s | 2:5bab956cb59e | 208 | * |
christi_s | 2:5bab956cb59e | 209 | * For the use of this class, a file "defines.h" must be created. |
christi_s | 2:5bab956cb59e | 210 | * It controls debug output and vs1053 patches. |
christi_s | 1:ced2c297cc1b | 211 | * |
christi_s | 2:5bab956cb59e | 212 | * defines.h: |
christi_s | 2:5bab956cb59e | 213 | *@code |
christi_s | 2:5bab956cb59e | 214 | * #ifndef _DEFINES_H |
christi_s | 2:5bab956cb59e | 215 | * #define _DEFINES_H |
christi_s | 2:5bab956cb59e | 216 | * // ---------------------------------------------------------------------------- |
christi_s | 2:5bab956cb59e | 217 | * // debug output |
christi_s | 2:5bab956cb59e | 218 | * // ---------------------------------------------------------------------------- |
christi_s | 2:5bab956cb59e | 219 | * // optional |
christi_s | 2:5bab956cb59e | 220 | * #define DEBUG |
christi_s | 2:5bab956cb59e | 221 | * #ifdef DEBUG |
christi_s | 2:5bab956cb59e | 222 | * # define DEBUGOUT(x,y...) printf(x, ##y); |
christi_s | 2:5bab956cb59e | 223 | * #else |
christi_s | 2:5bab956cb59e | 224 | * # define DEBUGOUT(x,y...) |
christi_s | 2:5bab956cb59e | 225 | * #endif |
christi_s | 2:5bab956cb59e | 226 | * // ---------------------------------------------------------------------------- |
christi_s | 2:5bab956cb59e | 227 | * // VLSI VS1053b library, patch, apps |
christi_s | 2:5bab956cb59e | 228 | * // ---------------------------------------------------------------------------- |
christi_s | 2:5bab956cb59e | 229 | * // optional, ONLY ONE |
christi_s | 2:5bab956cb59e | 230 | * //#define VS1053_PATCH_1_4_FLAC |
christi_s | 2:5bab956cb59e | 231 | * //#define VS1053_PATCH_1_5 |
christi_s | 2:5bab956cb59e | 232 | * #define VS1053_PATCH_1_5_FLAC |
christi_s | 2:5bab956cb59e | 233 | * //#define VS1053_SPECANA |
christi_s | 2:5bab956cb59e | 234 | * //#define VS1053B_PCM_RECORDER_0_9 |
christi_s | 2:5bab956cb59e | 235 | * |
christi_s | 2:5bab956cb59e | 236 | * #endif //_DEFINES_H |
christi_s | 1:ced2c297cc1b | 237 | * |
christi_s | 3:88a645490529 | 238 | *@endcode |
christi_s | 1:ced2c297cc1b | 239 | */ |
christi_s | 0:7728d9c6c487 | 240 | class VS1053 { |
christi_s | 0:7728d9c6c487 | 241 | |
christi_s | 0:7728d9c6c487 | 242 | public: |
christi_s | 1:ced2c297cc1b | 243 | /** Create a vs1053b object. |
christi_s | 1:ced2c297cc1b | 244 | * |
christi_s | 2:5bab956cb59e | 245 | * @param mosi |
christi_s | 2:5bab956cb59e | 246 | * SPI Master Out, Slave In pin to vs1053b. |
christi_s | 2:5bab956cb59e | 247 | * @param miso |
christi_s | 2:5bab956cb59e | 248 | * SPI Master In, Slave Out pin to vs1053b. |
christi_s | 2:5bab956cb59e | 249 | * @param sck |
christi_s | 2:5bab956cb59e | 250 | * SPI Clock pin to vs1053b. |
christi_s | 2:5bab956cb59e | 251 | * @param cs |
christi_s | 2:5bab956cb59e | 252 | * Pin to vs1053b control chip select. |
christi_s | 2:5bab956cb59e | 253 | * @param rst |
christi_s | 2:5bab956cb59e | 254 | * Pin to vs1053b reset. |
christi_s | 2:5bab956cb59e | 255 | * @param dreq |
christi_s | 2:5bab956cb59e | 256 | * Pin to vs1053b data request. |
christi_s | 2:5bab956cb59e | 257 | * @param dcs |
christi_s | 2:5bab956cb59e | 258 | * Pin to vs1053b data chip select. |
christi_s | 1:ced2c297cc1b | 259 | */ |
christi_s | 0:7728d9c6c487 | 260 | VS1053( |
christi_s | 1:ced2c297cc1b | 261 | PinName mosi, |
christi_s | 1:ced2c297cc1b | 262 | PinName miso, |
christi_s | 1:ced2c297cc1b | 263 | PinName sck, |
christi_s | 1:ced2c297cc1b | 264 | PinName cs, |
christi_s | 1:ced2c297cc1b | 265 | PinName rst, |
christi_s | 1:ced2c297cc1b | 266 | PinName dreq, |
christi_s | 1:ced2c297cc1b | 267 | PinName dcs |
christi_s | 4:cacb5e663fa9 | 268 | ); |
christi_s | 0:7728d9c6c487 | 269 | |
christi_s | 1:ced2c297cc1b | 270 | /** Reset the vs1053b. (hardware reset) |
christi_s | 1:ced2c297cc1b | 271 | * |
christi_s | 1:ced2c297cc1b | 272 | */ |
christi_s | 2:5bab956cb59e | 273 | void reset(void); |
christi_s | 5:ead95c0f7800 | 274 | |
christi_s | 5:ead95c0f7800 | 275 | /** Stop the playback if the song is completed. |
christi_s | 5:ead95c0f7800 | 276 | * You must call this function for default playback. |
christi_s | 5:ead95c0f7800 | 277 | * |
christi_s | 5:ead95c0f7800 | 278 | */ |
christi_s | 1:ced2c297cc1b | 279 | void terminateStream(void); |
christi_s | 1:ced2c297cc1b | 280 | |
christi_s | 2:5bab956cb59e | 281 | /** Initialize the vs1053b device. |
christi_s | 1:ced2c297cc1b | 282 | * |
christi_s | 2:5bab956cb59e | 283 | * @return |
christi_s | 2:5bab956cb59e | 284 | * TRUE on success, FALSE on failure. |
christi_s | 1:ced2c297cc1b | 285 | */ |
christi_s | 2:5bab956cb59e | 286 | bool initialize(void); |
christi_s | 1:ced2c297cc1b | 287 | |
christi_s | 2:5bab956cb59e | 288 | /** Set the volume. |
christi_s | 2:5bab956cb59e | 289 | * |
christi_s | 2:5bab956cb59e | 290 | * @param volume |
christi_s | 2:5bab956cb59e | 291 | * Volume -0.5dB, -1.0dB, .. -64.0dB. |
christi_s | 2:5bab956cb59e | 292 | */ |
christi_s | 2:5bab956cb59e | 293 | void setVolume(float volume = DEFAULT_VOLUME); |
christi_s | 2:5bab956cb59e | 294 | |
christi_s | 2:5bab956cb59e | 295 | /** Get the volume. |
christi_s | 2:5bab956cb59e | 296 | * |
christi_s | 2:5bab956cb59e | 297 | * @return |
christi_s | 2:5bab956cb59e | 298 | * Return the volume in dB. |
christi_s | 2:5bab956cb59e | 299 | */ |
christi_s | 1:ced2c297cc1b | 300 | float getVolume(); |
christi_s | 1:ced2c297cc1b | 301 | |
christi_s | 2:5bab956cb59e | 302 | /** Set the balance - volume difference between left-right. |
christi_s | 2:5bab956cb59e | 303 | * |
christi_s | 2:5bab956cb59e | 304 | * @param balance |
christi_s | 2:5bab956cb59e | 305 | * Difference in dB. |
christi_s | 2:5bab956cb59e | 306 | */ |
christi_s | 2:5bab956cb59e | 307 | void setBalance(float balance = DEFAULT_BALANCE_DIFERENCE_LEFT_RIGHT); |
christi_s | 2:5bab956cb59e | 308 | |
christi_s | 2:5bab956cb59e | 309 | /** Get the balance - volume difference between left-right. |
christi_s | 2:5bab956cb59e | 310 | * |
christi_s | 2:5bab956cb59e | 311 | * @return |
christi_s | 2:5bab956cb59e | 312 | * Difference in dB. |
christi_s | 2:5bab956cb59e | 313 | */ |
christi_s | 1:ced2c297cc1b | 314 | float getBalance(); |
christi_s | 2:5bab956cb59e | 315 | |
christi_s | 2:5bab956cb59e | 316 | /** Get the treble frequency limit. |
christi_s | 2:5bab956cb59e | 317 | * |
christi_s | 2:5bab956cb59e | 318 | * @return |
christi_s | 2:5bab956cb59e | 319 | * Frequenzy 1000, 2000 .. 15000Hz. |
christi_s | 2:5bab956cb59e | 320 | */ |
christi_s | 2:5bab956cb59e | 321 | int getTrebleFrequency(void); |
christi_s | 2:5bab956cb59e | 322 | /** Set the treble frequency limit. |
christi_s | 2:5bab956cb59e | 323 | * |
christi_s | 2:5bab956cb59e | 324 | * @param frequency |
christi_s | 2:5bab956cb59e | 325 | * Frequenzy 1000, 2000, .. 15000Hz. |
christi_s | 2:5bab956cb59e | 326 | */ |
christi_s | 2:5bab956cb59e | 327 | void setTrebleFrequency(int frequency = DEFAULT_TREBLE_FREQUENCY); |
christi_s | 1:ced2c297cc1b | 328 | |
christi_s | 2:5bab956cb59e | 329 | /** Get the treble amplitude. |
christi_s | 2:5bab956cb59e | 330 | * |
christi_s | 2:5bab956cb59e | 331 | * @return |
christi_s | 2:5bab956cb59e | 332 | * Amplitude -8 .. 7dB (in 1.5dB steps); 0 = off. |
christi_s | 2:5bab956cb59e | 333 | */ |
christi_s | 2:5bab956cb59e | 334 | int getTrebleAmplitude(void); |
christi_s | 2:5bab956cb59e | 335 | /** Set the treble amplitude. |
christi_s | 2:5bab956cb59e | 336 | * |
christi_s | 2:5bab956cb59e | 337 | * @param amplitude |
christi_s | 2:5bab956cb59e | 338 | * Amplitude -8 .. 7dB (in 1.5dB steps); 0 = off. |
christi_s | 2:5bab956cb59e | 339 | */ |
christi_s | 2:5bab956cb59e | 340 | void setTrebleAmplitude(int amplitude = DEFAULT_TREBLE_AMPLITUDE); |
christi_s | 1:ced2c297cc1b | 341 | |
christi_s | 2:5bab956cb59e | 342 | /** Get the bass frequency limit. |
christi_s | 2:5bab956cb59e | 343 | * |
christi_s | 2:5bab956cb59e | 344 | * @return |
christi_s | 2:5bab956cb59e | 345 | * Frequenzy 20, 30, .. 150Hz. |
christi_s | 2:5bab956cb59e | 346 | */ |
christi_s | 2:5bab956cb59e | 347 | int getBassFrequency(void); |
christi_s | 2:5bab956cb59e | 348 | /** Set the bass frequency limit. |
christi_s | 2:5bab956cb59e | 349 | * |
christi_s | 2:5bab956cb59e | 350 | * @param frequency |
christi_s | 2:5bab956cb59e | 351 | * Frequenzy 20, 30, .. 150Hz. |
christi_s | 2:5bab956cb59e | 352 | */ |
christi_s | 2:5bab956cb59e | 353 | void setBassFrequency(int frequency= DEFAULT_BASS_FREQUENCY); |
christi_s | 2:5bab956cb59e | 354 | |
christi_s | 2:5bab956cb59e | 355 | /** Get the bass amplitude. |
christi_s | 2:5bab956cb59e | 356 | * |
christi_s | 2:5bab956cb59e | 357 | * @return |
christi_s | 2:5bab956cb59e | 358 | * Amplitude 0 .. 15dB (in 1dB steps); 0 = off. |
christi_s | 2:5bab956cb59e | 359 | */ |
christi_s | 2:5bab956cb59e | 360 | int getBassAmplitude(void); |
christi_s | 2:5bab956cb59e | 361 | /** Set the bass amplitude. |
christi_s | 2:5bab956cb59e | 362 | * |
christi_s | 2:5bab956cb59e | 363 | * @param amplitude |
christi_s | 2:5bab956cb59e | 364 | * Amplitude 0 .. 15dB (in 1dB steps); 0 = off. |
christi_s | 2:5bab956cb59e | 365 | */ |
christi_s | 2:5bab956cb59e | 366 | void setBassAmplitude(int amplitude = DEFAULT_BASS_AMPLITUDE); |
christi_s | 2:5bab956cb59e | 367 | |
christi_s | 2:5bab956cb59e | 368 | /** Set the speed of a playback. |
christi_s | 2:5bab956cb59e | 369 | * |
christi_s | 2:5bab956cb59e | 370 | * @param speed |
christi_s | 5:ead95c0f7800 | 371 | * Speed 0, 1, .. (0, 1 normal speed). |
christi_s | 5:ead95c0f7800 | 372 | * Speeds greater 2 are not recommended, buffer must be filled quickly enough. |
christi_s | 2:5bab956cb59e | 373 | */ |
christi_s | 4:cacb5e663fa9 | 374 | void setPlaySpeed(unsigned short speed); |
christi_s | 4:cacb5e663fa9 | 375 | |
christi_s | 5:ead95c0f7800 | 376 | /** Copy a byte into the audio data buffer. |
christi_s | 5:ead95c0f7800 | 377 | * |
christi_s | 5:ead95c0f7800 | 378 | * @param c |
christi_s | 5:ead95c0f7800 | 379 | * Data for the buffer. |
christi_s | 5:ead95c0f7800 | 380 | * |
christi_s | 5:ead95c0f7800 | 381 | * @return |
christi_s | 5:ead95c0f7800 | 382 | * TRUE on success; FALSE on failure, c isn't copied in the buffer. |
christi_s | 5:ead95c0f7800 | 383 | */ |
christi_s | 4:cacb5e663fa9 | 384 | bool bufferSetByte(unsigned char c); |
christi_s | 5:ead95c0f7800 | 385 | |
christi_s | 5:ead95c0f7800 | 386 | /** Copy a array of bytes into the audio data buffer. |
christi_s | 5:ead95c0f7800 | 387 | * |
christi_s | 5:ead95c0f7800 | 388 | * @param s |
christi_s | 5:ead95c0f7800 | 389 | * Data for the buffer. |
christi_s | 5:ead95c0f7800 | 390 | * |
christi_s | 5:ead95c0f7800 | 391 | * @param length |
christi_s | 5:ead95c0f7800 | 392 | * Size of data array. |
christi_s | 5:ead95c0f7800 | 393 | * |
christi_s | 5:ead95c0f7800 | 394 | * @return |
christi_s | 5:ead95c0f7800 | 395 | * TRUE on success; FALSE on failure, s isn't copied in the buffer. |
christi_s | 5:ead95c0f7800 | 396 | */ |
christi_s | 4:cacb5e663fa9 | 397 | bool bufferPutStream(const unsigned char *s, unsigned int length); |
christi_s | 5:ead95c0f7800 | 398 | |
christi_s | 5:ead95c0f7800 | 399 | /** Get the free space of the audio data buffer. |
christi_s | 5:ead95c0f7800 | 400 | * |
christi_s | 5:ead95c0f7800 | 401 | * @return |
christi_s | 5:ead95c0f7800 | 402 | * Space 0 .. BUFFER_SIZE - 1. |
christi_s | 5:ead95c0f7800 | 403 | */ |
christi_s | 4:cacb5e663fa9 | 404 | unsigned int bufferFree(void); |
christi_s | 5:ead95c0f7800 | 405 | |
christi_s | 5:ead95c0f7800 | 406 | /** Get the busy space of the audio data buffer. |
christi_s | 5:ead95c0f7800 | 407 | * |
christi_s | 5:ead95c0f7800 | 408 | * @return |
christi_s | 5:ead95c0f7800 | 409 | * Space 0 .. BUFFER_SIZE - 1. |
christi_s | 5:ead95c0f7800 | 410 | */ |
christi_s | 4:cacb5e663fa9 | 411 | unsigned int bufferCount(void); |
christi_s | 4:cacb5e663fa9 | 412 | |
christi_s | 5:ead95c0f7800 | 413 | /** Start playing audio from buffer. |
christi_s | 5:ead95c0f7800 | 414 | * |
christi_s | 5:ead95c0f7800 | 415 | */ |
christi_s | 4:cacb5e663fa9 | 416 | void play(void); |
christi_s | 5:ead95c0f7800 | 417 | |
christi_s | 5:ead95c0f7800 | 418 | /** Interrupt the playback. |
christi_s | 5:ead95c0f7800 | 419 | * |
christi_s | 5:ead95c0f7800 | 420 | */ |
christi_s | 4:cacb5e663fa9 | 421 | void pause(void); |
christi_s | 5:ead95c0f7800 | 422 | |
christi_s | 5:ead95c0f7800 | 423 | /** Stop the playback in the middle of a song. |
christi_s | 5:ead95c0f7800 | 424 | * After this call, you can now send the next audio file to buffer. |
christi_s | 5:ead95c0f7800 | 425 | * |
christi_s | 5:ead95c0f7800 | 426 | */ |
christi_s | 4:cacb5e663fa9 | 427 | void stop(void); |
christi_s | 6:eed008905159 | 428 | |
christi_s | 6:eed008905159 | 429 | /** Get information about played audio stream. |
christi_s | 6:eed008905159 | 430 | * |
christi_s | 6:eed008905159 | 431 | * @param aInfo |
christi_s | 6:eed008905159 | 432 | * Return value for the informations. |
christi_s | 6:eed008905159 | 433 | * |
christi_s | 6:eed008905159 | 434 | */ |
christi_s | 6:eed008905159 | 435 | void getAudioInfo(AudioInfo* aInfo); |
christi_s | 1:ced2c297cc1b | 436 | |
christi_s | 1:ced2c297cc1b | 437 | protected: |
christi_s | 1:ced2c297cc1b | 438 | unsigned short int wram_read(unsigned short int); |
christi_s | 1:ced2c297cc1b | 439 | void wram_write(unsigned short int, unsigned short int); |
christi_s | 1:ced2c297cc1b | 440 | void write_plugin(const unsigned short* , unsigned int); |
christi_s | 0:7728d9c6c487 | 441 | void cs_low(void); |
christi_s | 0:7728d9c6c487 | 442 | void cs_high(void); |
christi_s | 0:7728d9c6c487 | 443 | void dcs_low(void); |
christi_s | 0:7728d9c6c487 | 444 | void dcs_high(void); |
christi_s | 0:7728d9c6c487 | 445 | void sci_en(void); |
christi_s | 0:7728d9c6c487 | 446 | void sci_dis(void); |
christi_s | 0:7728d9c6c487 | 447 | void sdi_en(void); |
christi_s | 0:7728d9c6c487 | 448 | void sdi_dis(void); |
christi_s | 0:7728d9c6c487 | 449 | |
christi_s | 1:ced2c297cc1b | 450 | void spi_initialise(void); |
christi_s | 1:ced2c297cc1b | 451 | |
christi_s | 0:7728d9c6c487 | 452 | void sdi_initialise(void); |
christi_s | 0:7728d9c6c487 | 453 | |
christi_s | 0:7728d9c6c487 | 454 | void sci_write(unsigned char, unsigned short int); |
christi_s | 0:7728d9c6c487 | 455 | void sdi_write(unsigned char); |
christi_s | 0:7728d9c6c487 | 456 | unsigned short int sci_read(unsigned short int); |
christi_s | 0:7728d9c6c487 | 457 | void sine_test_activate(unsigned char); |
christi_s | 0:7728d9c6c487 | 458 | |
christi_s | 0:7728d9c6c487 | 459 | void sine_test_deactivate(void); |
christi_s | 0:7728d9c6c487 | 460 | |
christi_s | 1:ced2c297cc1b | 461 | void changeVolume(void); |
christi_s | 4:cacb5e663fa9 | 462 | |
christi_s | 1:ced2c297cc1b | 463 | |
christi_s | 2:5bab956cb59e | 464 | // TODO |
christi_s | 2:5bab956cb59e | 465 | void power_down(void); |
christi_s | 4:cacb5e663fa9 | 466 | |
christi_s | 2:5bab956cb59e | 467 | void changeBass(void); |
christi_s | 1:ced2c297cc1b | 468 | |
christi_s | 4:cacb5e663fa9 | 469 | unsigned char bufferGetByte(void); |
christi_s | 4:cacb5e663fa9 | 470 | void bufferReset(void); |
christi_s | 4:cacb5e663fa9 | 471 | void dataRequestHandler(void); |
christi_s | 2:5bab956cb59e | 472 | |
christi_s | 4:cacb5e663fa9 | 473 | SPI _spi; |
christi_s | 4:cacb5e663fa9 | 474 | DigitalOut _CS; |
christi_s | 4:cacb5e663fa9 | 475 | DigitalOut _RST; |
christi_s | 4:cacb5e663fa9 | 476 | DigitalOut _DCS; |
christi_s | 4:cacb5e663fa9 | 477 | DigitalIn _DREQ; |
christi_s | 4:cacb5e663fa9 | 478 | InterruptIn _DREQ_INTERUPT_IN; |
christi_s | 4:cacb5e663fa9 | 479 | |
christi_s | 4:cacb5e663fa9 | 480 | unsigned char _buffer[BUFFER_SIZE]; |
christi_s | 4:cacb5e663fa9 | 481 | unsigned char* _bufferReadPointer; |
christi_s | 4:cacb5e663fa9 | 482 | unsigned char* _bufferWritePointer; |
christi_s | 4:cacb5e663fa9 | 483 | |
christi_s | 4:cacb5e663fa9 | 484 | bool _isIdle; |
christi_s | 4:cacb5e663fa9 | 485 | |
christi_s | 2:5bab956cb59e | 486 | // variables to save |
christi_s | 2:5bab956cb59e | 487 | // volume, values in db |
christi_s | 4:cacb5e663fa9 | 488 | float _balance; |
christi_s | 4:cacb5e663fa9 | 489 | float _volume; |
christi_s | 2:5bab956cb59e | 490 | // bass enhancer settings |
christi_s | 4:cacb5e663fa9 | 491 | int _sb_amplitude; |
christi_s | 4:cacb5e663fa9 | 492 | int _sb_freqlimit; |
christi_s | 4:cacb5e663fa9 | 493 | int _st_amplitude; |
christi_s | 4:cacb5e663fa9 | 494 | int _st_freqlimit; |
christi_s | 4:cacb5e663fa9 | 495 | |
christi_s | 4:cacb5e663fa9 | 496 | Ticker timer; |
christi_s | 4:cacb5e663fa9 | 497 | |
christi_s | 6:eed008905159 | 498 | static const char _sampleRateTable[4][4]; // _sampleRateTable[id][srate] |
christi_s | 6:eed008905159 | 499 | |
christi_s | 0:7728d9c6c487 | 500 | }; |
christi_s | 4:cacb5e663fa9 | 501 | |
christi_s | 0:7728d9c6c487 | 502 | #endif |