int build_file_index(data_file files[]){ int i = 0; if (!search_for_filetype("WAV", &files[i++], 0, 1) && !search_for_filetype("WAV", &files[i++], 0, 1)){ while(file_number > 1 && !search_for_filetype("WAV", &files[i++], 0, 1)); } return i-1; }
void init_music(){ int clusterLength, secCount; search_for_filetype("WAV", &returnData,0,1); printLCD(returnData.Name, "Buffering..."); clusterLength = 1+ ceil( (float) returnData.FileSize / bytePerCluster); build_cluster_chain(cc, clusterLength, &returnData); play_type = IORD(SWITCH_PIO_BASE, 0) & 0x07; LCD_Display(returnData.Name, play_type); }
//This is used to set up the buttons to do their required roles. static void button_ISR(void* context, alt_u32 id) { //Listen to ISR on a specific edge, so that we don't receive 2 interrupts at once if(_isredge == 0){ alt_u8 btnPressed = IORD(BUTTON_PIO_BASE, 3) & 0xf; switch(btnPressed){ //Set playing flag to default value and update the status to LCD case BTN_STOP: _playing = 0; IOWR(BUTTON_PIO_BASE, 2, 0xf); DisplayStatusLCD(); break; //Set play flag to high and let while loop handle audio play (disable other buttons) case BTN_PLAY: _playing = 1; IOWR(BUTTON_PIO_BASE, 2, 0xf); break; case BTN_NEXT: if(search_for_filetype("WAV", &_fileinfo, 0, 1) == 0) DisplayStatusLCD(); break; case BTN_PREV: //Prevent file iterator from getting stuck on the first file when going previous if(file_number < 0) file_number = 0; else file_number = file_number - 2; if(search_for_filetype("WAV", &_fileinfo, 0, 1) == 0) DisplayStatusLCD(); break; } _isredge = 1; }else{ _isredge = 0; } IOWR(BUTTON_PIO_BASE, 3, 0x0); }
int main() { alt_u8 _prevswstate = 0x0; Setup(); //Set up the initial file on SD card search_for_filetype("WAV", &_fileinfo, 0, 1); _swstate = IORD(SWITCH_PIO_BASE, 0); _prevswstate = 8; while(1) { //Listen for any changes in the switches, update if so _swstate = IORD(SWITCH_PIO_BASE, 0); if(_swstate != _prevswstate){ DisplayStatusLCD(); _prevswstate = _swstate & 0x07; } if (_playing == 1) { DisplayStatusLCD(); printf("Playing audio file: %s\n", _fileinfo.Name); //Disable other buttons IOWR(BUTTON_PIO_BASE, 2, 0x01); //Initialise cluster chain and build it from the audio file int clusterChain[100000]; int tracklength = 1 + ceil(_fileinfo.FileSize/(BPB_BytsPerSec*BPB_SecPerClus)); LCD_File_Buffering(_fileinfo.Name); build_cluster_chain(clusterChain, tracklength, &_fileinfo); //Update LCD and play audio dependent on user-selected mode DisplayStatusLCD(); switch(_swstate){ case SW_NORMALPLAY: NormalPlay(_fileinfo, tracklength, clusterChain); break; case SW_DOUBLEPLAY: DoublePlay(_fileinfo, tracklength, clusterChain); break; case SW_HALFPLAY: HalfPlay(_fileinfo, tracklength, clusterChain); break; case SW_DELAYPLAY: DelayPlay(_fileinfo, tracklength, clusterChain); break; case SW_REVERSEPLAY: ReversePlay(_fileinfo, tracklength, clusterChain); break; default: NormalPlay(_fileinfo, tracklength, clusterChain); break; } //Enable buttons, and reset play flag IOWR(BUTTON_PIO_BASE, 2, 0xf); _playing = 0; } } return 0; }