Exemple #1
0
int main(void) {

	if (init_system() != 0) return(-1);
	
	indexed_file_count = build_file_index(files);
	printf("Indexed files: %d\n", indexed_file_count);
	
	IOWR(BUTTON_PIO_BASE, 2, 0xf);
	IOWR(BUTTON_PIO_BASE, 3, 0x0);
	alt_irq_register( BUTTON_PIO_IRQ, (void*)0, button_ISR );
	
	IOWR(LED_PIO_BASE, 0, 0x00);
	
	player_state = PLAYER_STATE_DEFAULT;	
	
	int length;
	data_file file;
	
	while(1){
		if ((cur_file_index_update == 1) || (player_state_update == 1)) {

			if (cur_file_index_update)
				file = files[cur_file_index];

			switch (player_state){

				case PLAYER_STATE_PLAYING:
					LCD_File_Buffering(file.Name);
					length = 1 + ceil(file.FileSize/(BPB_BytsPerSec*BPB_SecPerClus));
					build_cluster_chain(cluster_chain, length, &file);

					LCD_Display(file.Name, player_mode);
					play(&file, buffer, cluster_chain, player_mode);
					player_state = PLAYER_STATE_USER_INPUT;

				case PLAYER_STATE_USER_INPUT:
					LCD_Display(file.Name, player_mode);
			}

			player_state_update = 0;
			cur_file_index_update = 0;
		}
	}
	
	return(0);
}
Exemple #2
0
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;
}