/** * @brief Calculates the remaining file size and new position of the pointer. * @param None * @retval None */ void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size) { /* Calculate the remaining audio data in the file and the new size for the DMA transfer. If the Audio files size is less than the DMA max data transfer size, so there is no calculation to be done, just restart from the beginning of the file ... */ /* Check if the end of file has been reached */ #ifdef AUDIO_MAL_MODE_NORMAL #if defined MEDIA_IntFLASH #if defined PLAY_REPEAT_OFF LED_Toggle = 4; RepeatState = 1; EVAL_AUDIO_Stop(CODEC_PDWN_HW); #else /* Replay from the beginning */ AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS),AUDIO_FILE_SZE,AUIDO_START_ADDRESS); #endif #elif defined MEDIA_USB_KEY XferCplt = 1; if (WaveDataLength) WaveDataLength -= _MAX_SS; if (WaveDataLength < _MAX_SS) WaveDataLength = 0; #endif #else /* #ifdef AUDIO_MAL_MODE_CIRCULAR */ #endif /* AUDIO_MAL_MODE_CIRCULAR */ }
/** * @brief Calculates the remaining file size and new position of the pointer. * @param None * @retval None */ void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size) { /* Calculate the remaining audio data in the file and the new size for the DMA transfer. If the Audio files size is less than the DMA max data transfer size, so there is no calculation to be done, just restart from the beginning of the file ... */ /* Check if the end of file has been reached */ #ifdef AUDIO_MAL_MODE_NORMAL /* Replay from the beginning */ AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUDIO_START_ADDRESS),AUDIO_FILE_SZE, AUDIO_START_ADDRESS); #else /* #ifdef AUDIO_MAL_MODE_CIRCULAR */ #endif /* AUDIO_MAL_MODE_CIRCULAR */ }
void WavePlayBack(uint32_t AudioFreq) { /* Normal mode description: Start playing the audio file (using DMA stream) . Using this mode, the application can run other tasks in parallel since the DMA is handling the Audio Transfer instead of the CPU. The only task remaining for the CPU will be the management of the DMA Transfer Complete interrupt or the Half Transfer Complete interrupt in order to load again the buffer and to calculate the remaining data. Circular mode description: Start playing the file from a circular buffer, once the DMA is enabled it always run. User has to fill periodically the buffer with the audio data using Transfer complete and/or half transfer complete interrupts callbacks (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()... In this case the audio data file is smaller than the DMA max buffer size 65535 so there is no need to load buffer continuously or manage the transfer complete or Half transfer interrupts callbacks. */ /* Start playing */ AudioPlayStart = 1; /* Initialize wave player (Codec, DMA, I2C) */ WavePlayerInit(AudioFreq); /* Play on */ AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUDIO_START_ADDRESS), AUDIO_FILE_SZE, AUDIO_START_ADDRESS); /* Infinite loop */ while(1) { if (PauseResumeStatus != 2) { WavePlayerPauseResume(PauseResumeStatus); PauseResumeStatus = 2; } } }
void WavePlayBack(uint32_t AudioFreq) { /* Normal mode description: Start playing the audio file (using DMA stream) . Using this mode, the application can run other tasks in parallel since the DMA is handling the Audio Transfer instead of the CPU. The only task remaining for the CPU will be the management of the DMA Transfer Complete interrupt or the Half Transfer Complete interrupt in order to load again the buffer and to calculate the remaining data. Circular mode description: Start playing the file from a circular buffer, once the DMA is enabled it always run. User has to fill periodically the buffer with the audio data using Transfer complete and/or half transfer complete interrupts callbacks (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()... In this case the audio data file is smaller than the DMA max buffer size 65535 so there is no need to load buffer continuously or manage the transfer complete or Half transfer interrupts callbacks. */ /* Start playing */ AudioPlayStart = 1; RepeatState =0; #if defined MEDIA_IntFLASH /* Initialize wave player (Codec, DMA, I2C) */ WavePlayerInit(AudioFreq); /* Play on */ AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS),AUDIO_FILE_SZE,AUIDO_START_ADDRESS); /* LED Blue Start toggling */ LED_Toggle = 6; /* Infinite loop */ while(1) { /* check on the repeate status */ if (RepeatState == 0) { if (PauseResumeStatus == 0) { /* LED Blue Stop Toggling */ LED_Toggle = 0; /* Pause playing */ WavePlayerPauseResume(PauseResumeStatus); PauseResumeStatus = 2; } else if (PauseResumeStatus == 1) { /* LED Blue Toggling */ LED_Toggle = 6; /* Resume playing */ WavePlayerPauseResume(PauseResumeStatus); PauseResumeStatus = 2; } } else { /* Stop playing */ WavePlayerStop(); /* Green LED toggling */ LED_Toggle = 4; } } #elif defined MEDIA_USB_KEY /* Initialize wave player (Codec, DMA, I2C) */ WavePlayerInit(AudioFreq); AudioRemSize = 0; /* Get Data from USB Key */ f_lseek(&fileR, WaveCounter); f_read (&fileR, buffer1, _MAX_SS, &BytesRead); f_read (&fileR, buffer2, _MAX_SS, &BytesRead); /* Start playing wave */ Audio_MAL_Play((uint32_t)buffer1, _MAX_SS); buffer_switch = 1; XferCplt = 0; LED_Toggle = 6; PauseResumeStatus = 1; Count = 0; while((WaveDataLength != 0) && HCD_IsDeviceConnected(&USB_OTG_Core)) { /* Test on the command: Playing */ if (Command_index == 0) { /* wait for DMA transfert complete */ while((XferCplt == 0) && HCD_IsDeviceConnected(&USB_OTG_Core)) { if (PauseResumeStatus == 0) { /* Pause Playing wave */ LED_Toggle = 0; WavePlayerPauseResume(PauseResumeStatus); PauseResumeStatus = 2; } else if (PauseResumeStatus == 1) { LED_Toggle = 6; /* Resume Playing wave */ WavePlayerPauseResume(PauseResumeStatus); PauseResumeStatus = 2; } } XferCplt = 0; if(buffer_switch == 0) { /* Play data from buffer1 */ Audio_MAL_Play((uint32_t)buffer1, _MAX_SS); /* Store data in buffer2 */ f_read (&fileR, buffer2, _MAX_SS, &BytesRead); buffer_switch = 1; } else { /* Play data from buffer2 */ Audio_MAL_Play((uint32_t)buffer2, _MAX_SS); /* Store data in buffer1 */ f_read (&fileR, buffer1, _MAX_SS, &BytesRead); buffer_switch = 0; } } else { WavePlayerStop(); WaveDataLength = 0; RepeatState =0; break; } } #if defined PLAY_REPEAT_OFF RepeatState = 1; WavePlayerStop(); if (Command_index == 0) LED_Toggle = 4; #else LED_Toggle = 7; RepeatState = 0; AudioPlayStart = 0; WavePlayerStop(); #endif #endif }