Karaoke Machine
Dependencies: SDFileSystem mbed-rtos mbed
main.cpp@0:1d4e1f997a95, 2015-12-07 (annotated)
- Committer:
- myeh
- Date:
- Mon Dec 07 20:36:22 2015 +0000
- Revision:
- 0:1d4e1f997a95
This is the code for a karaoke machine
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
myeh | 0:1d4e1f997a95 | 1 | #include "SDFileSystem.h" |
myeh | 0:1d4e1f997a95 | 2 | #include "rtos.h" |
myeh | 0:1d4e1f997a95 | 3 | #include "mbed.h" |
myeh | 0:1d4e1f997a95 | 4 | |
myeh | 0:1d4e1f997a95 | 5 | typedef struct uFMT_STRUCT { |
myeh | 0:1d4e1f997a95 | 6 | short comp_code; |
myeh | 0:1d4e1f997a95 | 7 | short num_channels; |
myeh | 0:1d4e1f997a95 | 8 | unsigned voice_rate; |
myeh | 0:1d4e1f997a95 | 9 | unsigned avg_Bps; |
myeh | 0:1d4e1f997a95 | 10 | short block_align; |
myeh | 0:1d4e1f997a95 | 11 | short sig_bps; |
myeh | 0:1d4e1f997a95 | 12 | } FMT_STRUCT; |
myeh | 0:1d4e1f997a95 | 13 | |
myeh | 0:1d4e1f997a95 | 14 | class wave_player { |
myeh | 0:1d4e1f997a95 | 15 | |
myeh | 0:1d4e1f997a95 | 16 | public: |
myeh | 0:1d4e1f997a95 | 17 | /** Create a wave player using a pointer to the given AnalogOut object. |
myeh | 0:1d4e1f997a95 | 18 | * |
myeh | 0:1d4e1f997a95 | 19 | * @param _dac pointer to an AnalogOut object to which the voices are sent. |
myeh | 0:1d4e1f997a95 | 20 | */ |
myeh | 0:1d4e1f997a95 | 21 | wave_player(AnalogOut *_dac); |
myeh | 0:1d4e1f997a95 | 22 | void play(FILE *wavefile); |
myeh | 0:1d4e1f997a95 | 23 | void set_verbosity(int v); |
myeh | 0:1d4e1f997a95 | 24 | |
myeh | 0:1d4e1f997a95 | 25 | /** the player function. |
myeh | 0:1d4e1f997a95 | 26 | * |
myeh | 0:1d4e1f997a95 | 27 | * @param wavefile A pointer to an opened wave file |
myeh | 0:1d4e1f997a95 | 28 | */ |
myeh | 0:1d4e1f997a95 | 29 | |
myeh | 0:1d4e1f997a95 | 30 | /** Set the printf verbosity of the wave player. A nonzero verbosity level |
myeh | 0:1d4e1f997a95 | 31 | * will put wave_player in a mode where the complete contents of the wave |
myeh | 0:1d4e1f997a95 | 32 | * file are echoed to the screen, including header values, and including |
myeh | 0:1d4e1f997a95 | 33 | * all of the voice values placed into the DAC FIFO, and the voice values |
myeh | 0:1d4e1f997a95 | 34 | * removed from the DAC FIFO by the ISR. The voice output frequency is |
myeh | 0:1d4e1f997a95 | 35 | * fixed at 2 Hz in this mode, so it's all very slow and the DAC output isn't |
myeh | 0:1d4e1f997a95 | 36 | * very useful, but it lets you see what's going on and may help for debugging |
myeh | 0:1d4e1f997a95 | 37 | * wave files that don't play correctly. |
myeh | 0:1d4e1f997a95 | 38 | * |
myeh | 0:1d4e1f997a95 | 39 | * @param v the verbosity level |
myeh | 0:1d4e1f997a95 | 40 | */ |
myeh | 0:1d4e1f997a95 | 41 | private: |
myeh | 0:1d4e1f997a95 | 42 | void dac_out(void); |
myeh | 0:1d4e1f997a95 | 43 | int verbosity; |
myeh | 0:1d4e1f997a95 | 44 | AnalogOut *wave_DAC; |
myeh | 0:1d4e1f997a95 | 45 | Ticker tick; |
myeh | 0:1d4e1f997a95 | 46 | unsigned short DAC_fifo[256]; |
myeh | 0:1d4e1f997a95 | 47 | short DAC_wptr; |
myeh | 0:1d4e1f997a95 | 48 | volatile short DAC_rptr; |
myeh | 0:1d4e1f997a95 | 49 | short DAC_on; |
myeh | 0:1d4e1f997a95 | 50 | }; |
myeh | 0:1d4e1f997a95 | 51 | |
myeh | 0:1d4e1f997a95 | 52 | wave_player::wave_player(AnalogOut *_dac) |
myeh | 0:1d4e1f997a95 | 53 | { |
myeh | 0:1d4e1f997a95 | 54 | wave_DAC=_dac; |
myeh | 0:1d4e1f997a95 | 55 | wave_DAC->write_u16(32768); //DAC is 0-3.3V, so idles at ~1.6V |
myeh | 0:1d4e1f997a95 | 56 | verbosity=0; |
myeh | 0:1d4e1f997a95 | 57 | } |
myeh | 0:1d4e1f997a95 | 58 | |
myeh | 0:1d4e1f997a95 | 59 | //----------------------------------------------------------------------------- |
myeh | 0:1d4e1f997a95 | 60 | // if verbosity is set then wave player enters a mode where the wave file |
myeh | 0:1d4e1f997a95 | 61 | // is decoded and displayed to the screen, including voice values put into |
myeh | 0:1d4e1f997a95 | 62 | // the DAC FIFO, and values read out of the DAC FIFO by the ISR. The DAC output |
myeh | 0:1d4e1f997a95 | 63 | // itself is so slow as to be unusable, but this might be handy for debugging |
myeh | 0:1d4e1f997a95 | 64 | // wave files that don't play |
myeh | 0:1d4e1f997a95 | 65 | //----------------------------------------------------------------------------- |
myeh | 0:1d4e1f997a95 | 66 | void wave_player::set_verbosity(int v) |
myeh | 0:1d4e1f997a95 | 67 | { |
myeh | 0:1d4e1f997a95 | 68 | verbosity=v; |
myeh | 0:1d4e1f997a95 | 69 | } |
myeh | 0:1d4e1f997a95 | 70 | |
myeh | 0:1d4e1f997a95 | 71 | //----------------------------------------------------------------------------- |
myeh | 0:1d4e1f997a95 | 72 | // player function. Takes a pointer to an opened wave file. The file needs |
myeh | 0:1d4e1f997a95 | 73 | // to be stored in a filesystem with enough bandwidth to feed the wave data. |
myeh | 0:1d4e1f997a95 | 74 | // LocalFileSystem isn't, but the SDcard is, at least for 22kHz files. The |
myeh | 0:1d4e1f997a95 | 75 | // SDcard filesystem can be hotrodded by increasing the SPI frequency it uses |
myeh | 0:1d4e1f997a95 | 76 | // internally. |
myeh | 0:1d4e1f997a95 | 77 | //----------------------------------------------------------------------------- |
myeh | 0:1d4e1f997a95 | 78 | void wave_player::play(FILE *wavefile) |
myeh | 0:1d4e1f997a95 | 79 | { |
myeh | 0:1d4e1f997a95 | 80 | unsigned chunk_id,chunk_size,channel; |
myeh | 0:1d4e1f997a95 | 81 | unsigned data,samp_int,i; |
myeh | 0:1d4e1f997a95 | 82 | short unsigned dac_data; |
myeh | 0:1d4e1f997a95 | 83 | long long slice_value; |
myeh | 0:1d4e1f997a95 | 84 | char *slice_buf; |
myeh | 0:1d4e1f997a95 | 85 | short *data_sptr; |
myeh | 0:1d4e1f997a95 | 86 | unsigned char *data_bptr; |
myeh | 0:1d4e1f997a95 | 87 | int *data_wptr; |
myeh | 0:1d4e1f997a95 | 88 | FMT_STRUCT wav_format; |
myeh | 0:1d4e1f997a95 | 89 | long slice,num_slices; |
myeh | 0:1d4e1f997a95 | 90 | DAC_wptr=0; |
myeh | 0:1d4e1f997a95 | 91 | DAC_rptr=0; |
myeh | 0:1d4e1f997a95 | 92 | for (i=0;i<256;i+=2) { |
myeh | 0:1d4e1f997a95 | 93 | DAC_fifo[i]=0; |
myeh | 0:1d4e1f997a95 | 94 | DAC_fifo[i+1]=3000; |
myeh | 0:1d4e1f997a95 | 95 | } |
myeh | 0:1d4e1f997a95 | 96 | DAC_wptr=4; |
myeh | 0:1d4e1f997a95 | 97 | DAC_on=0; |
myeh | 0:1d4e1f997a95 | 98 | |
myeh | 0:1d4e1f997a95 | 99 | fread(&chunk_id,4,1,wavefile); |
myeh | 0:1d4e1f997a95 | 100 | fread(&chunk_size,4,1,wavefile); |
myeh | 0:1d4e1f997a95 | 101 | while (!feof(wavefile)) { |
myeh | 0:1d4e1f997a95 | 102 | if (verbosity) |
myeh | 0:1d4e1f997a95 | 103 | printf("Read chunk ID 0x%x, size 0x%x\n",chunk_id,chunk_size); |
myeh | 0:1d4e1f997a95 | 104 | switch (chunk_id) { |
myeh | 0:1d4e1f997a95 | 105 | case 0x46464952: |
myeh | 0:1d4e1f997a95 | 106 | fread(&data,4,1,wavefile); |
myeh | 0:1d4e1f997a95 | 107 | if (verbosity) { |
myeh | 0:1d4e1f997a95 | 108 | printf("RIFF chunk\n"); |
myeh | 0:1d4e1f997a95 | 109 | printf(" chunk size %d (0x%x)\n",chunk_size,chunk_size); |
myeh | 0:1d4e1f997a95 | 110 | printf(" RIFF type 0x%x\n",data); |
myeh | 0:1d4e1f997a95 | 111 | } |
myeh | 0:1d4e1f997a95 | 112 | break; |
myeh | 0:1d4e1f997a95 | 113 | case 0x20746d66: |
myeh | 0:1d4e1f997a95 | 114 | fread(&wav_format,sizeof(wav_format),1,wavefile); |
myeh | 0:1d4e1f997a95 | 115 | if (verbosity) { |
myeh | 0:1d4e1f997a95 | 116 | printf("FORMAT chunk\n"); |
myeh | 0:1d4e1f997a95 | 117 | printf(" chunk size %d (0x%x)\n",chunk_size,chunk_size); |
myeh | 0:1d4e1f997a95 | 118 | printf(" compression code %d\n",wav_format.comp_code); |
myeh | 0:1d4e1f997a95 | 119 | printf(" %d channels\n",wav_format.num_channels); |
myeh | 0:1d4e1f997a95 | 120 | printf(" %d voices/sec\n",wav_format.voice_rate); |
myeh | 0:1d4e1f997a95 | 121 | printf(" %d bytes/sec\n",wav_format.avg_Bps); |
myeh | 0:1d4e1f997a95 | 122 | printf(" block align %d\n",wav_format.block_align); |
myeh | 0:1d4e1f997a95 | 123 | printf(" %d bits per voice\n",wav_format.sig_bps); |
myeh | 0:1d4e1f997a95 | 124 | } |
myeh | 0:1d4e1f997a95 | 125 | if (chunk_size > sizeof(wav_format)) |
myeh | 0:1d4e1f997a95 | 126 | fseek(wavefile,chunk_size-sizeof(wav_format),SEEK_CUR); |
myeh | 0:1d4e1f997a95 | 127 | break; |
myeh | 0:1d4e1f997a95 | 128 | case 0x61746164: |
myeh | 0:1d4e1f997a95 | 129 | // allocate a buffer big enough to hold a slice |
myeh | 0:1d4e1f997a95 | 130 | slice_buf=(char *)malloc(wav_format.block_align); |
myeh | 0:1d4e1f997a95 | 131 | if (!slice_buf) { |
myeh | 0:1d4e1f997a95 | 132 | printf("Unable to malloc slice buffer"); |
myeh | 0:1d4e1f997a95 | 133 | exit(1); |
myeh | 0:1d4e1f997a95 | 134 | } |
myeh | 0:1d4e1f997a95 | 135 | num_slices=chunk_size/wav_format.block_align; |
myeh | 0:1d4e1f997a95 | 136 | samp_int=1000000/(wav_format.voice_rate); |
myeh | 0:1d4e1f997a95 | 137 | if (verbosity) { |
myeh | 0:1d4e1f997a95 | 138 | printf("DATA chunk\n"); |
myeh | 0:1d4e1f997a95 | 139 | printf(" chunk size %d (0x%x)\n",chunk_size,chunk_size); |
myeh | 0:1d4e1f997a95 | 140 | printf(" %d slices\n",num_slices); |
myeh | 0:1d4e1f997a95 | 141 | printf(" Ideal voice interval=%d\n",(unsigned)(1000000.0/wav_format.voice_rate)); |
myeh | 0:1d4e1f997a95 | 142 | printf(" programmed interrupt tick interval=%d\n",samp_int); |
myeh | 0:1d4e1f997a95 | 143 | } |
myeh | 0:1d4e1f997a95 | 144 | |
myeh | 0:1d4e1f997a95 | 145 | // starting up ticker to write voices out -- no printfs until tick.detach is called |
myeh | 0:1d4e1f997a95 | 146 | if (verbosity) |
myeh | 0:1d4e1f997a95 | 147 | tick.attach_us(this,&wave_player::dac_out, 500000); |
myeh | 0:1d4e1f997a95 | 148 | else |
myeh | 0:1d4e1f997a95 | 149 | tick.attach_us(this,&wave_player::dac_out, samp_int); |
myeh | 0:1d4e1f997a95 | 150 | DAC_on=1; |
myeh | 0:1d4e1f997a95 | 151 | |
myeh | 0:1d4e1f997a95 | 152 | // start reading slices, which contain one voice each for however many channels |
myeh | 0:1d4e1f997a95 | 153 | // are in the wave file. one channel=mono, two channels=stereo, etc. Since |
myeh | 0:1d4e1f997a95 | 154 | // mbed only has a single AnalogOut, all of the channels present are averaged |
myeh | 0:1d4e1f997a95 | 155 | // to produce a single voice value. This summing and averaging happens in |
myeh | 0:1d4e1f997a95 | 156 | // a variable of type signed long long, to make sure that the data doesn't |
myeh | 0:1d4e1f997a95 | 157 | // overflow regardless of voice size (8 bits, 16 bits, 32 bits). |
myeh | 0:1d4e1f997a95 | 158 | // |
myeh | 0:1d4e1f997a95 | 159 | // note that from what I can find that 8 bit wave files use unsigned data, |
myeh | 0:1d4e1f997a95 | 160 | // while 16 and 32 bit wave files use signed data |
myeh | 0:1d4e1f997a95 | 161 | // |
myeh | 0:1d4e1f997a95 | 162 | for (slice=0;slice<num_slices;slice+=1) { |
myeh | 0:1d4e1f997a95 | 163 | fread(slice_buf,wav_format.block_align,1,wavefile); |
myeh | 0:1d4e1f997a95 | 164 | if (feof(wavefile)) { |
myeh | 0:1d4e1f997a95 | 165 | printf("Oops -- not enough slices in the wave file\n"); |
myeh | 0:1d4e1f997a95 | 166 | exit(1); |
myeh | 0:1d4e1f997a95 | 167 | } |
myeh | 0:1d4e1f997a95 | 168 | data_sptr=(short *)slice_buf; // 16 bit voices |
myeh | 0:1d4e1f997a95 | 169 | data_bptr=(unsigned char *)slice_buf; // 8 bit voices |
myeh | 0:1d4e1f997a95 | 170 | data_wptr=(int *)slice_buf; // 32 bit voices |
myeh | 0:1d4e1f997a95 | 171 | slice_value=0; |
myeh | 0:1d4e1f997a95 | 172 | for (channel=0;channel<wav_format.num_channels;channel++) { |
myeh | 0:1d4e1f997a95 | 173 | switch (wav_format.sig_bps) { |
myeh | 0:1d4e1f997a95 | 174 | case 16: |
myeh | 0:1d4e1f997a95 | 175 | if (verbosity) |
myeh | 0:1d4e1f997a95 | 176 | printf("16 bit channel %d data=%d ",channel,data_sptr[channel]); |
myeh | 0:1d4e1f997a95 | 177 | slice_value+=data_sptr[channel]; |
myeh | 0:1d4e1f997a95 | 178 | break; |
myeh | 0:1d4e1f997a95 | 179 | case 32: |
myeh | 0:1d4e1f997a95 | 180 | if (verbosity) |
myeh | 0:1d4e1f997a95 | 181 | printf("32 bit channel %d data=%d ",channel,data_wptr[channel]); |
myeh | 0:1d4e1f997a95 | 182 | slice_value+=data_wptr[channel]; |
myeh | 0:1d4e1f997a95 | 183 | break; |
myeh | 0:1d4e1f997a95 | 184 | case 8: |
myeh | 0:1d4e1f997a95 | 185 | if (verbosity) |
myeh | 0:1d4e1f997a95 | 186 | printf("8 bit channel %d data=%d ",channel,(int)data_bptr[channel]); |
myeh | 0:1d4e1f997a95 | 187 | slice_value+=data_bptr[channel]; |
myeh | 0:1d4e1f997a95 | 188 | break; |
myeh | 0:1d4e1f997a95 | 189 | } |
myeh | 0:1d4e1f997a95 | 190 | } |
myeh | 0:1d4e1f997a95 | 191 | slice_value/=wav_format.num_channels; |
myeh | 0:1d4e1f997a95 | 192 | |
myeh | 0:1d4e1f997a95 | 193 | // slice_value is now averaged. Next it needs to be scaled to an unsigned 16 bit value |
myeh | 0:1d4e1f997a95 | 194 | // with DC offset so it can be written to the DAC. |
myeh | 0:1d4e1f997a95 | 195 | switch (wav_format.sig_bps) { |
myeh | 0:1d4e1f997a95 | 196 | case 8: slice_value<<=8; |
myeh | 0:1d4e1f997a95 | 197 | break; |
myeh | 0:1d4e1f997a95 | 198 | case 16: slice_value+=32768; |
myeh | 0:1d4e1f997a95 | 199 | break; |
myeh | 0:1d4e1f997a95 | 200 | case 32: slice_value>>=16; |
myeh | 0:1d4e1f997a95 | 201 | slice_value+=32768; |
myeh | 0:1d4e1f997a95 | 202 | break; |
myeh | 0:1d4e1f997a95 | 203 | } |
myeh | 0:1d4e1f997a95 | 204 | dac_data=(short unsigned)slice_value; |
myeh | 0:1d4e1f997a95 | 205 | if (verbosity) |
myeh | 0:1d4e1f997a95 | 206 | printf("voice %d wptr %d slice_value %d dac_data %u\n",slice,DAC_wptr,(int)slice_value,dac_data); |
myeh | 0:1d4e1f997a95 | 207 | DAC_fifo[DAC_wptr]=dac_data; |
myeh | 0:1d4e1f997a95 | 208 | DAC_wptr=(DAC_wptr+1) & 0xff; |
myeh | 0:1d4e1f997a95 | 209 | while (DAC_wptr==DAC_rptr) { |
myeh | 0:1d4e1f997a95 | 210 | } |
myeh | 0:1d4e1f997a95 | 211 | } |
myeh | 0:1d4e1f997a95 | 212 | DAC_on=0; |
myeh | 0:1d4e1f997a95 | 213 | tick.detach(); |
myeh | 0:1d4e1f997a95 | 214 | free(slice_buf); |
myeh | 0:1d4e1f997a95 | 215 | break; |
myeh | 0:1d4e1f997a95 | 216 | case 0x5453494c: |
myeh | 0:1d4e1f997a95 | 217 | if (verbosity) |
myeh | 0:1d4e1f997a95 | 218 | printf("INFO chunk, size %d\n",chunk_size); |
myeh | 0:1d4e1f997a95 | 219 | fseek(wavefile,chunk_size,SEEK_CUR); |
myeh | 0:1d4e1f997a95 | 220 | break; |
myeh | 0:1d4e1f997a95 | 221 | default: |
myeh | 0:1d4e1f997a95 | 222 | printf("unknown chunk type 0x%x, size %d\n",chunk_id,chunk_size); |
myeh | 0:1d4e1f997a95 | 223 | data=fseek(wavefile,chunk_size,SEEK_CUR); |
myeh | 0:1d4e1f997a95 | 224 | break; |
myeh | 0:1d4e1f997a95 | 225 | } |
myeh | 0:1d4e1f997a95 | 226 | fread(&chunk_id,4,1,wavefile); |
myeh | 0:1d4e1f997a95 | 227 | fread(&chunk_size,4,1,wavefile); |
myeh | 0:1d4e1f997a95 | 228 | } |
myeh | 0:1d4e1f997a95 | 229 | } |
myeh | 0:1d4e1f997a95 | 230 | |
myeh | 0:1d4e1f997a95 | 231 | BusOut myleds(LED1,LED2,LED3,LED4); |
myeh | 0:1d4e1f997a95 | 232 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
myeh | 0:1d4e1f997a95 | 233 | AnalogOut speaker(p18); |
myeh | 0:1d4e1f997a95 | 234 | wave_player waver(&speaker); |
myeh | 0:1d4e1f997a95 | 235 | Serial pc(USBTX, USBRX); |
myeh | 0:1d4e1f997a95 | 236 | |
myeh | 0:1d4e1f997a95 | 237 | DigitalOut P15(p15); |
myeh | 0:1d4e1f997a95 | 238 | DigitalOut P16(p16); |
myeh | 0:1d4e1f997a95 | 239 | DigitalOut P19(p19); |
myeh | 0:1d4e1f997a95 | 240 | DigitalOut P20(p20); |
myeh | 0:1d4e1f997a95 | 241 | |
myeh | 0:1d4e1f997a95 | 242 | unsigned short data; |
myeh | 0:1d4e1f997a95 | 243 | |
myeh | 0:1d4e1f997a95 | 244 | |
myeh | 0:1d4e1f997a95 | 245 | class microphone |
myeh | 0:1d4e1f997a95 | 246 | { |
myeh | 0:1d4e1f997a95 | 247 | public : |
myeh | 0:1d4e1f997a95 | 248 | microphone(PinName pin); |
myeh | 0:1d4e1f997a95 | 249 | unsigned short read_u16(); |
myeh | 0:1d4e1f997a95 | 250 | operator unsigned short (); |
myeh | 0:1d4e1f997a95 | 251 | private : |
myeh | 0:1d4e1f997a95 | 252 | AnalogIn _pin; |
myeh | 0:1d4e1f997a95 | 253 | }; |
myeh | 0:1d4e1f997a95 | 254 | microphone::microphone (PinName pin): |
myeh | 0:1d4e1f997a95 | 255 | _pin(pin) |
myeh | 0:1d4e1f997a95 | 256 | { |
myeh | 0:1d4e1f997a95 | 257 | } |
myeh | 0:1d4e1f997a95 | 258 | unsigned short microphone::read_u16() |
myeh | 0:1d4e1f997a95 | 259 | { |
myeh | 0:1d4e1f997a95 | 260 | return _pin.read_u16(); |
myeh | 0:1d4e1f997a95 | 261 | } |
myeh | 0:1d4e1f997a95 | 262 | inline microphone::operator unsigned short () |
myeh | 0:1d4e1f997a95 | 263 | { |
myeh | 0:1d4e1f997a95 | 264 | return _pin.read_u16(); |
myeh | 0:1d4e1f997a95 | 265 | } |
myeh | 0:1d4e1f997a95 | 266 | |
myeh | 0:1d4e1f997a95 | 267 | |
myeh | 0:1d4e1f997a95 | 268 | microphone mymicrophone(p17); |
myeh | 0:1d4e1f997a95 | 269 | |
myeh | 0:1d4e1f997a95 | 270 | |
myeh | 0:1d4e1f997a95 | 271 | int main() |
myeh | 0:1d4e1f997a95 | 272 | { |
myeh | 0:1d4e1f997a95 | 273 | while(1) { |
myeh | 0:1d4e1f997a95 | 274 | FILE *wave_file; |
myeh | 0:1d4e1f997a95 | 275 | wave_file=fopen("/sd/wavfiles/Yakko's World.wav","r"); |
myeh | 0:1d4e1f997a95 | 276 | waver.play(wave_file); |
myeh | 0:1d4e1f997a95 | 277 | fclose(wave_file); |
myeh | 0:1d4e1f997a95 | 278 | } |
myeh | 0:1d4e1f997a95 | 279 | } |
myeh | 0:1d4e1f997a95 | 280 | |
myeh | 0:1d4e1f997a95 | 281 | void wave_player::dac_out() |
myeh | 0:1d4e1f997a95 | 282 | { |
myeh | 0:1d4e1f997a95 | 283 | if (DAC_on) { |
myeh | 0:1d4e1f997a95 | 284 | #ifdef VERBOSE |
myeh | 0:1d4e1f997a95 | 285 | printf("ISR rdptr %d got %u\n",DAC_rptr,DAC_fifo[DAC_rptr]); |
myeh | 0:1d4e1f997a95 | 286 | #endif |
myeh | 0:1d4e1f997a95 | 287 | wave_DAC->write_u16((mymicrophone + DAC_fifo[DAC_rptr])/2); |
myeh | 0:1d4e1f997a95 | 288 | DAC_rptr=(DAC_rptr+1) & 0xff; |
myeh | 0:1d4e1f997a95 | 289 | } |
myeh | 0:1d4e1f997a95 | 290 | } |