/**
 * @brief  Start wave player
 * @param  None
 * @retval None
 */
void WavePlayerStart(void)
{
  char path[] = "0:/";

  _WAV_FileCounter = FS_ScanDir(_WAV_SoundDir, _WAV_FileList);

  buffer_switch = 1;

  /* Get the read out protection status */
  if (f_opendir(&dir, _WAV_SoundDir)!= FR_OK)
  {
    while(1)
    {
      STM_EVAL_LEDToggle(LED5);
      Delay(10);
    }
  }
  else
  {
#ifdef WAV_OLDCODE
    uint8_t wavHeader[_MAX_SS];

    WaveFileName = WAVE_NAME;
    /* Open the wave file to be played */
    if (f_open(&fileR, WaveFileName , FA_READ) != FR_OK)
    {
      STM_EVAL_LEDOn(LED5);
      Command_index = 1;
    }
    else
    {
      /* Read data(_MAX_SS byte) from the selected file */
      f_read (&fileR, (void *) wavHeader, _MAX_SS, &BytesRead);

      WaveFileStatus = WavePlayer_WaveParsing((uint8_t *) wavHeader);

      if (WaveFileStatus == Valid_WAVE_File)  /* the .WAV file is valid */
      {
        /* Set WaveDataLenght to the Speech wave length */
        WaveDataLength = WAVE_Format.DataSize;
      }
      else /* Unvalid wave file */
      {
        /* Led Red Toggles in infinite loop */
        while(1)
        {
          STM_EVAL_LEDToggle(LED5);
          Delay(10);
        }
      }
      /* Play the wave */
      WavePlayBack(I2S_AudioFreq_44k);
    }
#else
    WAV_OpenNextFile();
    WavePlayBack(I2S_AudioFreq_44k);
#endif
  }
}
示例#2
0
/**
  * @brief  Start wave player
  * @param  None
  * @retval None
  */
void WavePlayerStart(void)
{
  char path[] = "0:/";

  buffer_switch = 1;

  /* Get the read out protection status */
  if (f_opendir(&dir, path)!= FR_OK)
  {
    while(1)
    {
      STM_EVAL_LEDToggle(LED5);
      Delay(10);
    }
  }
  else
  {
    if (WaveRecStatus == 1)
    {
      WaveFileName = REC_WAVE_NAME;
    }
    else
    {
      WaveFileName = WAVE_NAME;
    }
    /* Open the wave file to be played */
    if (f_open(&fileR, WaveFileName , FA_READ) != FR_OK)
    {
      STM_EVAL_LEDOn(LED5);
      Command_index = 1;
    }
    else
    {
      /* Read data(_MAX_SS byte) from the selected file */
      f_read (&fileR, buffer1, _MAX_SS, &BytesRead);

      WaveFileStatus = WavePlayer_WaveParsing(&wavelen);

      if (WaveFileStatus == Valid_WAVE_File)  /* the .WAV file is valid */
      {
        /* Set WaveDataLenght to the Speech wave length */
        WaveDataLength = WAVE_Format.DataSize;
      }
      else /* Unvalid wave file */
      {
        /* Led Red Toggles in infinite loop */
        while(1)
        {
          STM_EVAL_LEDToggle(LED5);
          Delay(10);
        }
      }
      /* Play the wave */
      WavePlayBack(WAVE_Format.SampleRate);
    }
  }
}
void WAV_OpenNextFile(void)
{
  uint8_t i;
  FRESULT fresult;
  uint8_t wavHeader[_MAX_SS];

  f_close(&fileR);
  for(i = 0; i < _WAV_FileCounter; i++){
    fresult = f_open(&fileR, _WAV_FileList[_WAV_CurrentFileNumber], FA_READ);
    if (fresult != FR_OK) {
      _WAV_CurrentFileNumber = (_WAV_CurrentFileNumber+1)%_WAV_FileCounter;
      continue;
    }
    else {
      f_read (&fileR, (void *) wavHeader, _MAX_SS, &BytesRead);
      WaveFileStatus = WavePlayer_WaveParsing((uint8_t *) wavHeader);
      if (WaveFileStatus == Valid_WAVE_File) {
        WaveDataLength = WAVE_Format.DataSize;
        printf("Reading sound file %s\n", _WAV_FileList[_WAV_CurrentFileNumber]);
        _WAV_CurrentFileNumber = (_WAV_CurrentFileNumber+1)%_WAV_FileCounter;
        break;
      }
      else {
        f_close(&fileR);
        _WAV_CurrentFileNumber = (_WAV_CurrentFileNumber+1)%_WAV_FileCounter;
        continue;
      }
    }
  }
  if(i == _WAV_FileCounter){
    /* Led Red Toggles in infinite loop */
    while(1)
    {
      STM_EVAL_LEDToggle(LED5);
      Delay(10);
    }
  }
}