void decode(uint16_t *outbuf) { offset = MP3FindSyncWord(readPtr, READBUF_SIZE); if(offset < 0) { stop(); } else { readPtr += offset; //data start point bytesLeft -= offset; //in buffer MP3Decode(hMP3Decoder, &readPtr, &bytesLeft, outbuf, 0); if (bytesLeft < READBUF_SIZE) { memmove(readBuf,readPtr,bytesLeft); fr = f_read(&fil, readBuf + bytesLeft, READBUF_SIZE - bytesLeft, &cnt); if (cnt < READBUF_SIZE - bytesLeft); memset(readBuf + bytesLeft + cnt, 0, READBUF_SIZE - bytesLeft - cnt); bytesLeft=READBUF_SIZE; readPtr=readBuf; if(fr || cnt == 0){ stop(); next_song(); } } //MP3GetLastFrameInfo(hMP3Decoder, &mp3FrameInfo); //if(mp3FrameInfo.outputSamps != 2304) decode(outbuf); } }
void TIM2_IRQHandler(void) { if(update_buf == 1) { if(cur_buf == 0) { ok = 1; if(ismp3)decode(buf2); else { fr = f_read(&fil, buf2, BUF_LENGTH*sizeof(uint16_t), &cnt); if (fr || cnt == 0){ stop(); next_song(); } } int i; for(i=0;i<BUF_LENGTH;i++) { buf2[i] = ((int)((short)buf2[i])+32768)* 4000 / 65536; } } else { if(ismp3)decode(buf); else { fr = f_read(&fil, buf, BUF_LENGTH*sizeof(uint16_t), &cnt); if (fr || cnt == 0){ stop(); next_song(); } } int i; for(i=0;i<BUF_LENGTH;i++) { buf[i] = ((int)((short)buf[i])+32768)* 4000 / 65536; } } update_buf = 0; } TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); }
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; } }
int do_formstuff(int obj_id) { int tfd; switch(obj_id) { case CTRL_STOP: if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } if(replay || replay_pause) { if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL); replay_pause=0; exit_replay(); update_time(); } break; case CTRL_PLAY: if(replay_pause || Dsp_Hf1(-1)) { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL); continue_replay(); replay_pause=0; } else { if(!replay && file_open) { replay_pause=0; init_replay(); } else { if((tfd = open_file()) > 0) { int error; fd=tfd; if((error=getmp2info(fd))==MP2_NOERR) { replay_pause=0; update_time(); setfilename(filename); init_replay(); } else { show_mp2_error(error); close_file(fd); strcpy(windforms[WIND_CTRL].wind_title,"MPEG"); wind_set(windforms[WIND_CTRL].whandle,WF_NAME, windforms[WIND_CTRL].wind_title); setfilename("MPEGFILE"); } } } } break; case CTRL_PAUSE: if(replay_pause) { continue_replay(); replay_pause=0; } else { if(replay) { pause_replay(); replay_pause=1; } } break; case CTRL_LOAD: if((tfd = open_file()) > 0) { int error; if(windforms[WIND_CTRL].formtree[CTRL_PAUSE].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_PAUSE,SET_NORMAL); replay_pause=0; if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } fd=tfd; if((error=getmp2info(tfd))==MP2_NOERR) { update_time(); setfilename(filename); } else { show_mp2_error(error); close_file(fd); strcpy(windforms[WIND_CTRL].wind_title,"MPEG"); wind_set(windforms[WIND_CTRL].whandle,WF_NAME, windforms[WIND_CTRL].wind_title); setfilename("MPEGFILE"); } } break; case CTRL_LOOP: looping=(windforms[WIND_CTRL].formtree[CTRL_LOOP].ob_state & SELECTED); break; case CTRL_INFO: /* Open info window */ if(windforms[WIND_INFO].wind_open) wind_set(windforms[WIND_INFO].whandle,WF_TOP); else { fg_init(&windforms[WIND_INFO]); wind_open(windforms[WIND_INFO].whandle, windforms[WIND_INFO].wind.x,windforms[WIND_INFO].wind.y, windforms[WIND_INFO].wind.w,windforms[WIND_INFO].wind.h); windforms[WIND_INFO].wind_open=1; } break; case CTRL_NEXT: if(file_open) { int o_replay,o_pause; if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } o_replay = replay; o_pause = replay_pause; exit_replay(); while((tfd=next_song(path, filename, 1))!=0) { if(getmp2info(tfd)!=MP2_NOERR) { close_file(tfd); } else { if(file_open) close_file(fd); fd = tfd; file_open=1; update_time(); setfilename(filename); replay = o_replay; replay_pause = o_pause; if(replay) init_replay(); if(replay_pause) { init_replay(); pause_replay(); } break; } } if(!tfd) { update_time(); } } break; case CTRL_PREV: if(file_open) { int o_replay,o_pause; if(Dsp_Hf1(-1)) /* If fast forwarding */ { if(windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) toggle_object(&windforms[WIND_CTRL],CTRL_FF,SET_NORMAL); Dsp_Hf1(0); } o_replay = replay; o_pause = replay_pause; /* if more than or one second of the song has elapsed, go to the beginning of of the same song! */ if(calc_time() > 0) { reset_file(fd); update_time(); replay = o_replay; replay_pause = o_pause; if(replay) init_replay(); if(replay_pause) { init_replay(); pause_replay(); } } else { exit_replay(); while((tfd=next_song(path, filename, 0))!=0) { if(getmp2info(tfd)!=MP2_NOERR) { close_file(tfd); } else { if(file_open) close_file(fd); fd = tfd; file_open=1; update_time(); setfilename(filename); replay = o_replay; replay_pause = o_pause; if(replay) init_replay(); if(replay_pause) { init_replay(); pause_replay(); } break; } } if(!tfd) { update_time(); } } } break; case CTRL_FF: if (windforms[WIND_CTRL].formtree[CTRL_FF].ob_state & SELECTED) Dsp_Hf1(1); else Dsp_Hf1(0); break; case CTRL_TIME: if(windforms[WIND_CTRL].formtree[CTRL_TIME].ob_state & SELECTED) count_dir = 0; /* count up */ else count_dir = 1; /* count down */ if(file_open) update_time(); break; default: break; } return 0; }
void wakeUp_User(){ mp3Player_onoff(); if(snoozeCounter == 0){ next_song(); } play_pause(); _delay_ms(1000);//warten bis mp3Player an ist boot_amp(); bool user_awake = false; LCD_LED = 1; LED_AUSTRALIA = 1; LED_NORWAY = 1; int secondsStart = seconds; while((!btn_light_pushed) && (rotary == 0) && (!btn_drehenc_pushed)){//Könnte auch von Sekundenzähler aufgewacht sein goodNight(); if(check_TimeUpdate()); update_time(); if(seconds == secondsStart + 30){ LCD_LED = 0; LED_AUSTRALIA = 0; LED_NORWAY = 0; } } LCD_LED = 0; LED_AUSTRALIA = 0; LED_NORWAY = 0; if(snoozeCounter==0){ if(btn_light_pushed){ //while(!btn_light_pushed){_delay_ms(100);} start_btnPress(); while((PINB & (1<<PINB1)) && (btn_press_duration<BTN_PRESS_LONG)){_delay_ms(50);} stop_btnPress(); if(btn_press_duration>=BTN_PRESS_LONG){ user_awake = true; } else { reset_alarmLogo(); print_snoozeLogo(); update_LCD(); snooze_alarm(); snoozeCounter = 1; } } else { reset_alarmLogo(); print_snoozeLogo(); update_LCD(); snooze_alarm(); snoozeCounter = 1; } } else { while(!user_awake){ goodNight(); if(check_TimeUpdate()) update_time(); start_btnPress(); while((PINB & (1<<PINB1)) && (btn_press_duration<BTN_PRESS_LONG)){_delay_ms(50);} stop_btnPress(); if(btn_press_duration>=BTN_PRESS_LONG){ user_awake = true; alarm = OFF; reset_alarmLogo(); reset_snoozeLogo(); snoozeCounter = 0; alarm_hour = saved_alarm_h; alarm_minute = saved_alarm_m; } } } play_pause();//Pause shutdown_amp(); mp3Player_onoff(); }