Beispiel #1
0
void loop(){
	int i;
	static u8 zero[32] = {0};
	
	if (is_playing){
		int buf_len = mp3_buffer_len();
		static int last_second = -1;
		int second;
		
		store_buffer();
		
		if (buf_len < 32){
			for (i=0;i<8;i++) fill_mp3_buffer();
		}else if (mp3_need_data()){
			if (wifi_available_len() < 30 && last_second < 2){
				printf("oooooverrrrrrrrr\r\n");
				while (wifi_available_len() > 0) wifi_receive();
				mp3_input_data(zero);
				
				cur_song_init();
				is_playing = 0;
				return;
			}
			
			mp3_input_data(cur_song.buffer);
			for (i=32;i<cur_song.buffer_idx;i++){
				cur_song.buffer[i-32] = cur_song.buffer[i];
			}
			cur_song.buffer_idx -= 32;
			
			
			if (cur_song.frame_size > 0){
				second = cur_song.content_remain / cur_song.frame_size * 26 /1000;
				if (second != last_second)	printf("time : -%d\r\n",second);
				last_second = second;
			}
		}
	}else{
		char * sg;
		sg = next_song();
	
		printf(">>> %s\r\n",sg);
		send_fetch_song(sg);
		
		is_playing = 1;
	}
}
Beispiel #2
0
static void play_mp3(char* filename) {

	bool out_of_data;
	int cc;


	// Open file
	if (FR_OK == f_open(&file, filename, FA_OPEN_EXISTING | FA_READ)) {

		// Read ID3v2 Tag
		char szArtist[120];
		char szTitle[120];
		Mp3ReadId3V2Tag(&file, szArtist, sizeof(szArtist), szTitle, sizeof(szTitle));


		///////////////////////////////////////////////////////////buffer starts getting filled for first time
		// Start Initial fill of buffer
		hMP3Decoder = MP3InitDecoder();
		for (cc = 0 ; cc < NUMBER_BUFFERS ; cc++ ) {
			out_of_data = fill_mp3_buffer(&file,cc);

			if ( out_of_data ) {
				break;
			}
		}

		// Initialize buffer counters
		buffer_read = 0;
		buffer_write = 0;

/////////////////////////////////////////////////////////////////////////////////////////
		// Play mp3
		running_player = true;
		InitializeAudio(Audio44100HzSettings);
		// InitializeAudio(Audio32000HzSettings);
		SetAudioVolume(0xAF);
		PlayAudioWithCallback(AudioCallback, 0);
//////////////////////////////////////////////////////////////////////////////////////////
		for(;;) {
			/*
			 *  If we have an unused buffer, call fill_mp3_buffer to fill it.
			 */
			if ( buffer_read != buffer_write ) {


				// Refill the MP3 buffer
				out_of_data = fill_mp3_buffer(&file,buffer_write);

				if ( !out_of_data ) {
					buffer_write = ( buffer_write + 1 ) % NUMBER_BUFFERS;
				}

				// Out of data or error or user button... Stop playback!
				if (out_of_data || (exitMp3 == 1))
				{
					StopAudio();
					running_player = false;

					// Re-initialize and set volume to avoid noise
					InitializeAudio(Audio44100HzSettings);
					SetAudioVolume(0);

					// Close currently open file
					f_close(&file);
					return;
				}


			}
			else {
				// We don't have any work to do, shut down until interrupt (DMA transfer complete)
				__asm__ volatile ("wfi");
			}
		}
	}