1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include <stdarg.h>
- #include "yc11xx.h"
- #include "yc11xx_uart.h"
- #include "yc11xx_gpio.h"
- #include "Drv_mic.h"
- #include "system.h"
- #define LED_GPIO 4
- extern MIC_CUR_VARIABLE sMicCurVariable;
- void LED_Run(void)
- {
- static uint32_t times = 0;
- times++;
- if(times>0x100)
- {
- times = 0;
- GPIO_CONFIG(LED_GPIO) = (GPIO_CONFIG(LED_GPIO)==GPCFG_OUTPUT_HIGH)? GPCFG_OUTPUT_LOW: GPCFG_OUTPUT_HIGH;
- }
- }
- /*
- * @method Audio_sampling_init
- * @brief mic adc init
- * @retval None
- */
- void Audio_sampling_init()
- {
- DRV_Mic_Init();
- DRV_Mic_Enable();
- }
- /*
- * @method Audio_get_buffer_len
- * @brief Get adc dma buf unread data length.
- * @retval None
- */
- int Audio_get_buffer_len()
- {
- int audioWPtr = HREADW(CORE_ADCD_ADDR) ;
- int audioRPtr = TO_16BIT_ADDR(sMicCurVariable.mReadPtr) ;
- int audioBufferLen = (int)(sMicCurVariable.mEndPtr - sMicCurVariable.mReadBufPtr);
- if(audioRPtr <= audioWPtr)
- {
- return (audioWPtr - audioRPtr);
- }
- else
- {
- return (audioBufferLen - (audioRPtr - audioWPtr));
- }
- }
- /*
- * @method Audio_to_uart_start
- * @brief read mic adc data for adc_dma_buf, and send mic adc data by uart.
- * @retval None
- */
- void Audio_to_uart_start()
- {
- if (sMicCurVariable.mMicEnable == MIC_DISABLE)
- return;
- int audioWPtr = HREADW(CORE_ADCD_ADDR) ;
- int bufferLen = Audio_get_buffer_len();
-
- if (bufferLen != 0 && bufferLen >= ENCODE_INPUT_LEN)
- {
- //Original sound sampling(pcm)
- for(int indexL = 0; indexL < ENCODE_INPUT_LEN; indexL++)
- MyPrintf("%c",*(sMicCurVariable.mReadPtr + indexL));
- sMicCurVariable.mReadPtr += ENCODE_INPUT_LEN;
- if (sMicCurVariable.mReadPtr == sMicCurVariable.mEndPtr)
- sMicCurVariable.mReadPtr = sMicCurVariable.mReadBufPtr;
- }
- }
- int main(void)
- {
- printport_init();
- GPIO_CONFIG(LED_GPIO)= GPCFG_OUTPUT_LOW;
- Audio_sampling_init();
- while(1)
- {
- LED_Run();
- Audio_to_uart_start();
- }
- }
|