Exemplo n.º 1
0
int main(void) {
  setvbuf(stdin, NULL, _IONBF, 0);
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stderr, NULL, _IONBF, 0);

  f3d_uart_init();
  delay(10);
  f3d_delay_init();
  delay(10);
  f3d_lcd_init();
  delay(10);
  f3d_i2c1_init();
  delay(10);
  f3d_accel_init();
  delay(10);
  f3d_nunchuk_init();
  delay(10);
  f3d_timer2_init();
  delay(10);
  f3d_dac_init();
  delay(10);
  f3d_rtc_init();
  delay(10);
  f3d_systick_init();
  delay(10);

  nunchuk_t nunc;
  nunchuk_t *nun = &nunc;
  int music = 0;

  const int fileNum = 3;
  char *musicFile[fileNum];
  musicFile[0] = "thermo.wav";
  musicFile[1] = "mario.wav";
  musicFile[2] = "ting.wav";

  printf("Reset\n");

  //set up screen
  f3d_lcd_fillScreen(WHITE);
  f3d_lcd_drawString(37, 0, musicFile[0], RED, WHITE);
  f3d_lcd_drawString(37, 20 * 1, musicFile[1], BLUE, WHITE);
  f3d_lcd_drawString(37, 20 * 2, musicFile[2], BLUE, WHITE);
  f3d_lcd_drawString(33, 80, "WAV Player", BLACK, WHITE);
  f3d_lcd_drawString(43, 100, "sijlee", BLACK, WHITE);
  f3d_lcd_drawString(48, 120, "sp21", BLACK, WHITE);


  f_mount(0, &Fatfs);/* Register volume work area */
  f3d_nunchuk_read(nun);
  while(1) {
    f3d_nunchuk_read(nun);
    int lastSelect = music;
    //nunchuk to right
    if (nun->jx == 255) {
      music = (music + 1) % 3;
      f3d_lcd_drawString(37, lastSelect * 20, musicFile[lastSelect], BLUE, WHITE);
      f3d_lcd_drawString(37, music * 20, musicFile[music], RED, WHITE);
      //nunchuk to left
    } else if (nun->jx == 0) {
      music = (music + 2) % 3;
      f3d_lcd_drawString(37, lastSelect * 20, musicFile[lastSelect], BLUE, WHITE);
      f3d_lcd_drawString(37, music * 20, musicFile[music], RED, WHITE);
    }
  
  //when selected, play music!
  if (nun->z) {
    FRESULT rc;     /* Result code */
    DIR dir;      /* Directory object */
    FILINFO fno;      /* File information object */
    UINT bw, br;
    unsigned int retval;
    int bytesread;

    printf("\nOpen %s\n", musicFile[music]);
    rc = f_open(&fid, musicFile[music], FA_READ);

    printf("opened file with rc: %d\n", rc);

    if (!rc) {
      printf("Success opening file\n");
      struct ckhd hd;
      uint32_t  waveid;
      struct fmtck fck;
    
      readckhd(&fid, &hd, 'FFIR');
    
      f_read(&fid, &waveid, sizeof(waveid), &ret);
      if ((ret != sizeof(waveid)) || (waveid != 'EVAW'))
	return -1;
    
      readckhd(&fid, &hd, ' tmf');
    
      f_read(&fid, &fck, sizeof(fck), &ret);
    
      // skip over extra info
    
      if (hd.cksize != 16) {
	printf("extra header info %d\n", hd.cksize - 16);
	f_lseek(&fid, hd.cksize - 16);
      }
    
      printf("audio format 0x%x\n", fck.wFormatTag);
      printf("channels %d\n", fck.nChannels);
      printf("sample rate %d\n", fck.nSamplesPerSec);
      printf("data rate %d\n", fck.nAvgBytesPerSec);
      printf("block alignment %d\n", fck.nBlockAlign);
      printf("bits per sample %d\n", fck.wBitsPerSample);
    
      // now skip all non-data chunks !
    
      while(1){
	printf("skipping all non-data chunks\n");
	readckhd(&fid, &hd, 0);
	if (hd.ckID == 'atad')
	  break;
	f_lseek(&fid, hd.cksize);
      }
    
      printf("Samples %d\n", hd.cksize);
    
      // Play it !
    
      //      audioplayerInit(fck.nSamplesPerSec);
    
      f_read(&fid, Audiobuf, AUDIOBUFSIZE, &ret);
      hd.cksize -= ret;
      audioplayerStart();
      while (hd.cksize) {
	int next = hd.cksize > AUDIOBUFSIZE/2 ? AUDIOBUFSIZE/2 : hd.cksize;
	if (audioplayerHalf) {
	  if (next < AUDIOBUFSIZE/2)
	    bzero(Audiobuf, AUDIOBUFSIZE/2);
	  f_read(&fid, Audiobuf, next, &ret);
	  hd.cksize -= ret;
	  audioplayerHalf = 0;
	}
	if (audioplayerWhole) {
	  if (next < AUDIOBUFSIZE/2)
	    bzero(&Audiobuf[AUDIOBUFSIZE/2], AUDIOBUFSIZE/2);
	  f_read(&fid, &Audiobuf[AUDIOBUFSIZE/2], next, &ret);
	  hd.cksize -= ret;
	  audioplayerWhole = 0;
	}
      }
      audioplayerStop();
    }

    printf("\nClose the file.\n"); 
    rc = f_close(&fid);
  
    if (rc) die(rc);

    delay(1000);
  }
  }
}
Exemplo n.º 2
0
int main(void) { 

  int step = 0;
  int stepMod;
  nunchuk_t n;

  setvbuf(stdin, NULL, _IONBF, 0);
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stderr, NULL, _IONBF, 0);

  f3d_i2c1_init();
  delay(10);
  f3d_nunchuk_init();
  delay(10);
  f3d_rtc_init();
  //printf("check rtc\n");
  delay(10);

  f3d_uart_init();
  f3d_timer2_init();
  //printf("check timer2\n");
  f3d_dac_init();
  //printf("check dac\n");
  f3d_delay_init();
  //printf("check delay\n");
  f3d_led_init();
  //printf("check led\n");
  f3d_lcd_init();
  //printf("check lcd\n");
  f3d_systick_init();
  //printf("check systick\n");
  f3d_user_btn_init();
  //printf("check user btn\n");

  f3d_lcd_fillScreen(WHITE);
  
  while (1){
    f3d_nunchuk_read(&n);
    if(n.jy > 150){
      step++;
    }
    if(n.jy < 15){
      step--;
    }
    
    stepMod = abs(step)%3;
    switch(stepMod) {
    case 0:
      strcpy(fileName, "thermo.wav");
      f3d_lcd_drawString(20,10,"Thermo",RED,BLACK);
      f3d_lcd_drawString(20,30,"Lion",RED,WHITE);
      f3d_lcd_drawString(20,50,"Batman",RED,WHITE);
      if(user_btn_read() == 1){
        play();
      }
      break;
    case 1:
      strcpy(fileName, "lion.wav");
      f3d_lcd_drawString(20,10,"Thermo",RED,WHITE);
      f3d_lcd_drawString(20,30,"Lion",RED,BLACK);
      f3d_lcd_drawString(20,50,"Batman",RED,WHITE);
      if(user_btn_read() == 1){
        play();
      }
      break;
    case 2:
      strcpy(fileName, "batman.wav");
      f3d_lcd_drawString(20,10,"Thermo",RED,WHITE);
      f3d_lcd_drawString(20,30,"Lion",RED,WHITE);
      f3d_lcd_drawString(20,50,"Batman",RED,BLACK);
      if(user_btn_read() == 1){
        play();
      }
      break;
    }
  }
}