Example #1
0
/**
  * @brief  De-Initializes the AUDIO media low layer.      
  * @param  options: Reserved for future use
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t Audio_DeInit(uint32_t options)
{
  BSP_AUDIO_OUT_SetMute(AUDIO_MUTE_ON); 
  BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
  BSP_AUDIO_OUT_SetMute(AUDIO_MUTE_OFF);
  return 0;
}
/**
  * @brief  Controls AUDIO Mute.              
  * @param  cmd: Command opcode
  * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  */
static int8_t Audio_MuteCtl(uint8_t cmd)
{
  BSP_AUDIO_OUT_SetMute(cmd);
  return 0;
}
/**
  * @brief  Audio task
  * @param  argument: pointer that is passed to the thread function as start argument.
  * @retval None
  */
static void Audio_Thread(void const * argument)
{
  uint32_t numOfReadBytes, remlen;    
  osEvent event;  
 
  for(;;)
  {
    event = osMessageGet(AudioEvent, 100 );
    
    if( event.status == osEventMessage )
    {
      if(haudio.state == AUDIOPLAYER_PLAY)
      {
        switch(event.value.v)
        {
        case BUFFER_OFFSET_HALF:
          
          remlen = wav_file.fsize - wav_file.fptr ;
            
          if(remlen < AUDIO_BUFFER_SIZE/2 )
          {
            BSP_AUDIO_OUT_SetMute(1);
            haudio.state = AUDIOPLAYER_EOF;
          }
  
          if(f_read(&wav_file, 
                    &haudio.buffer[0], 
                    AUDIO_BUFFER_SIZE/2, 
                    (void *)&numOfReadBytes) == FR_OK)
          { 
            if(numOfReadBytes == 0)
            {  
              BSP_AUDIO_OUT_SetMute(1);
              haudio.state = AUDIOPLAYER_EOF;
            } 
          }
          else
          {
            BSP_AUDIO_OUT_SetMute(1);
            haudio.state = AUDIOPLAYER_ERROR;    
          }
          break;  
          
        case BUFFER_OFFSET_FULL:
          
          
          remlen = wav_file.fsize - wav_file.fptr ;
            
          if(remlen < AUDIO_BUFFER_SIZE/2 )
          {
            BSP_AUDIO_OUT_SetMute(1);
            haudio.state = AUDIOPLAYER_EOF;            
          }
          
          if(f_read(&wav_file, 
                    &haudio.buffer[AUDIO_BUFFER_SIZE/2], 
                    AUDIO_BUFFER_SIZE/2, 
                    (void *)&numOfReadBytes) == FR_OK)
          { 
            if(numOfReadBytes == 0)
            { 
              BSP_AUDIO_OUT_SetMute(1);              
              haudio.state = AUDIOPLAYER_EOF;                     
            } 
          }
          else
          {
            BSP_AUDIO_OUT_SetMute(1);            
            haudio.state = AUDIOPLAYER_ERROR;   
          }
          break;   
          
        default:
          break;
        }
        
        
        
        
      }
      
    }
  }
}
/**
  * @brief  Sets the volume at mute
  * @param  state: could be MUTE_ON to mute sound or MUTE_OFF to unmute 
  *                the codec and restore previous volume level.
  * @retval Audio state.
  */
AUDIOPLAYER_ErrorTypdef  AUDIOPLAYER_Mute(uint8_t state)
{
   BSP_AUDIO_OUT_SetMute(state);
   
   return AUDIOPLAYER_ERROR_NONE;
}