AudioRecord
Dependencies: STM32L4xx_HAL_Driver CMSIS_DSP_401
audio_record.c@3:ec7e3c37fe80, 2015-11-26 (annotated)
- Committer:
- EricLew
- Date:
- Thu Nov 26 22:32:56 2015 +0000
- Revision:
- 3:ec7e3c37fe80
- Parent:
- 1:1ae4b642c533
FFT is currently not working and commented out
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EricLew | 0:d4e5ad7ad71c | 1 | /* Includes ------------------------------------------------------------------*/ |
EricLew | 0:d4e5ad7ad71c | 2 | #include "main.h" |
EricLew | 0:d4e5ad7ad71c | 3 | |
EricLew | 0:d4e5ad7ad71c | 4 | /* Variable indicating which audio demo is currently running (playback v.s. record) */ |
EricLew | 0:d4e5ad7ad71c | 5 | Audio_DemoTypeDef AudioDemo = AUDIO_DEMO_NONE; |
EricLew | 0:d4e5ad7ad71c | 6 | |
EricLew | 3:ec7e3c37fe80 | 7 | |
EricLew | 3:ec7e3c37fe80 | 8 | |
EricLew | 3:ec7e3c37fe80 | 9 | |
EricLew | 0:d4e5ad7ad71c | 10 | /* Private typedef -----------------------------------------------------------*/ |
EricLew | 0:d4e5ad7ad71c | 11 | typedef enum |
EricLew | 0:d4e5ad7ad71c | 12 | { |
EricLew | 0:d4e5ad7ad71c | 13 | BUFFER_OFFSET_NONE = 0, |
EricLew | 0:d4e5ad7ad71c | 14 | BUFFER_OFFSET_HALF, |
EricLew | 0:d4e5ad7ad71c | 15 | BUFFER_OFFSET_FULL, |
EricLew | 0:d4e5ad7ad71c | 16 | } RecordBufferOffset_Typedef; |
EricLew | 0:d4e5ad7ad71c | 17 | |
EricLew | 0:d4e5ad7ad71c | 18 | |
EricLew | 0:d4e5ad7ad71c | 19 | /* Private define ------------------------------------------------------------*/ |
EricLew | 0:d4e5ad7ad71c | 20 | /* Size (in bytes) of the buffer containing the recorded PCM samples */ |
EricLew | 1:1ae4b642c533 | 21 | #define RECORD_BUFFER_SIZE (uint32_t)1024 //BUFFER SIZE IS THE SAME FOR BOTH RECORDINGS |
EricLew | 0:d4e5ad7ad71c | 22 | |
EricLew | 0:d4e5ad7ad71c | 23 | /* Buffer containing the PCM samples coming from the microphone */ |
EricLew | 1:1ae4b642c533 | 24 | static uint32_t RecordBuffer[RECORD_BUFFER_SIZE]; //RECORDING BUFFER FOR SAMPLE #0 |
EricLew | 1:1ae4b642c533 | 25 | static uint32_t RecordBuffer1[RECORD_BUFFER_SIZE];//RECORDING BUFFER FOR SAMPLE #1 |
EricLew | 0:d4e5ad7ad71c | 26 | |
EricLew | 0:d4e5ad7ad71c | 27 | /* Buffer used to stream the recorded PCM samples towards the audio codec. */ |
EricLew | 3:ec7e3c37fe80 | 28 | static uint32_t PlaybackBuffer[2048]; //PLAYBACK BUFFER FOR SAMPLE#0 |
EricLew | 3:ec7e3c37fe80 | 29 | static uint32_t PlaybackBuffer1[2048];//PLAYBACK BUFFER FOR SAMPLE#1 |
EricLew | 3:ec7e3c37fe80 | 30 | |
EricLew | 0:d4e5ad7ad71c | 31 | |
EricLew | 0:d4e5ad7ad71c | 32 | #define NB_SAMPLES_RATE 7 |
EricLew | 1:1ae4b642c533 | 33 | static uint32_t SamplesRates[NB_SAMPLES_RATE] = {BSP_AUDIO_FREQUENCY_48K}; //SAMPLE RATE IS THE SAME |
EricLew | 0:d4e5ad7ad71c | 34 | |
EricLew | 0:d4e5ad7ad71c | 35 | /* Information indicating which part of the recorded buffer is ready for audio loopback */ |
EricLew | 0:d4e5ad7ad71c | 36 | static RecordBufferOffset_Typedef RecordBufferOffset = BUFFER_OFFSET_NONE; |
EricLew | 0:d4e5ad7ad71c | 37 | |
EricLew | 0:d4e5ad7ad71c | 38 | /* Private function prototypes -----------------------------------------------*/ |
EricLew | 0:d4e5ad7ad71c | 39 | /* Display actuyel record sample rate */ |
EricLew | 0:d4e5ad7ad71c | 40 | static void SampleRateDisplay(uint8_t SampleRate); |
EricLew | 0:d4e5ad7ad71c | 41 | |
EricLew | 0:d4e5ad7ad71c | 42 | /* Record sample rate selection */ |
EricLew | 0:d4e5ad7ad71c | 43 | static void SampleRateSelection(void); |
EricLew | 0:d4e5ad7ad71c | 44 | |
EricLew | 0:d4e5ad7ad71c | 45 | /* Audio recorder callback functions */ |
EricLew | 0:d4e5ad7ad71c | 46 | static void AudioRecord_TransferComplete_CallBack(void); |
EricLew | 0:d4e5ad7ad71c | 47 | static void AudioRecord_HalfTransfer_CallBack(void); |
EricLew | 0:d4e5ad7ad71c | 48 | static void AudioRecord_Error_CallBack(void); |
EricLew | 0:d4e5ad7ad71c | 49 | |
EricLew | 0:d4e5ad7ad71c | 50 | /* Private functions ---------------------------------------------------------*/ |
EricLew | 0:d4e5ad7ad71c | 51 | |
EricLew | 0:d4e5ad7ad71c | 52 | /** |
EricLew | 0:d4e5ad7ad71c | 53 | * @brief Setup and start audio recording in loopback mode |
EricLew | 0:d4e5ad7ad71c | 54 | * @param None |
EricLew | 0:d4e5ad7ad71c | 55 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 56 | */ |
EricLew | 0:d4e5ad7ad71c | 57 | void AudioRecord_demo(void) |
EricLew | 0:d4e5ad7ad71c | 58 | { |
EricLew | 0:d4e5ad7ad71c | 59 | /* Indicates which part of the payback buffer must be updated */ |
EricLew | 0:d4e5ad7ad71c | 60 | uint8_t transfer_range = 0; |
EricLew | 0:d4e5ad7ad71c | 61 | |
EricLew | 1:1ae4b642c533 | 62 | /* Flag indicating whether the audio codec has already been initialized */ |
EricLew | 0:d4e5ad7ad71c | 63 | uint32_t audio_loop_back_init = RESET ; |
EricLew | 1:1ae4b642c533 | 64 | |
EricLew | 0:d4e5ad7ad71c | 65 | /* Audio record demo is running */ |
EricLew | 0:d4e5ad7ad71c | 66 | AudioDemo = AUDIO_DEMO_RECORD; |
EricLew | 0:d4e5ad7ad71c | 67 | |
EricLew | 0:d4e5ad7ad71c | 68 | /* Turn off green LED5 */ |
EricLew | 0:d4e5ad7ad71c | 69 | BSP_LED_Off(LED5); |
EricLew | 0:d4e5ad7ad71c | 70 | |
EricLew | 0:d4e5ad7ad71c | 71 | /* Initialize record buffer offset */ |
EricLew | 0:d4e5ad7ad71c | 72 | RecordBufferOffset = BUFFER_OFFSET_NONE; |
EricLew | 0:d4e5ad7ad71c | 73 | |
EricLew | 0:d4e5ad7ad71c | 74 | /* Select the audio record sample rate */ |
EricLew | 0:d4e5ad7ad71c | 75 | SampleRateSelection(); |
EricLew | 1:1ae4b642c533 | 76 | //INITIALIZE RECORDING #0 |
EricLew | 0:d4e5ad7ad71c | 77 | /* Initialize audio input */ |
EricLew | 0:d4e5ad7ad71c | 78 | if (BSP_AUDIO_IN_Init(SamplesRates[SampleRateIndex], |
EricLew | 0:d4e5ad7ad71c | 79 | DEFAULT_AUDIO_IN_BIT_RESOLUTION, |
EricLew | 0:d4e5ad7ad71c | 80 | DEFAULT_AUDIO_IN_CHANNEL_NBR) != AUDIO_OK) |
EricLew | 0:d4e5ad7ad71c | 81 | { |
EricLew | 0:d4e5ad7ad71c | 82 | /* Record Error */ |
EricLew | 0:d4e5ad7ad71c | 83 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 84 | } |
EricLew | 0:d4e5ad7ad71c | 85 | |
EricLew | 0:d4e5ad7ad71c | 86 | /* Set Callback function pointers */ |
EricLew | 0:d4e5ad7ad71c | 87 | BSP_AUDIO_IN_RegisterCallbacks(AudioRecord_Error_CallBack, |
EricLew | 0:d4e5ad7ad71c | 88 | AudioRecord_HalfTransfer_CallBack, |
EricLew | 0:d4e5ad7ad71c | 89 | AudioRecord_TransferComplete_CallBack); |
EricLew | 0:d4e5ad7ad71c | 90 | |
EricLew | 0:d4e5ad7ad71c | 91 | /* Start the audio record */ |
EricLew | 0:d4e5ad7ad71c | 92 | if (BSP_AUDIO_IN_Record((uint16_t*)&RecordBuffer[0], |
EricLew | 0:d4e5ad7ad71c | 93 | RECORD_BUFFER_SIZE) != AUDIO_OK) |
EricLew | 0:d4e5ad7ad71c | 94 | { |
EricLew | 0:d4e5ad7ad71c | 95 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 96 | } |
EricLew | 1:1ae4b642c533 | 97 | uint32_t counter=0; //COUNTER IS REGISTER R4 |
EricLew | 0:d4e5ad7ad71c | 98 | /* PCM samples recording loop */ |
EricLew | 0:d4e5ad7ad71c | 99 | while (AudioRecordExit != SET) |
EricLew | 0:d4e5ad7ad71c | 100 | { |
EricLew | 1:1ae4b642c533 | 101 | |
EricLew | 1:1ae4b642c533 | 102 | if (counter==10000000) //Approximately 3 seconds of record time |
EricLew | 1:1ae4b642c533 | 103 | { |
EricLew | 1:1ae4b642c533 | 104 | AudioRecordExit=1; |
EricLew | 1:1ae4b642c533 | 105 | } |
EricLew | 1:1ae4b642c533 | 106 | else |
EricLew | 1:1ae4b642c533 | 107 | { |
EricLew | 1:1ae4b642c533 | 108 | counter=counter++; |
EricLew | 1:1ae4b642c533 | 109 | } |
EricLew | 0:d4e5ad7ad71c | 110 | /* 1st or 2nd half of the record buffer ready for being copied |
EricLew | 0:d4e5ad7ad71c | 111 | to the playback buffer */ |
EricLew | 0:d4e5ad7ad71c | 112 | if(RecordBufferOffset != BUFFER_OFFSET_NONE) |
EricLew | 0:d4e5ad7ad71c | 113 | { |
EricLew | 0:d4e5ad7ad71c | 114 | /* Copy half of the record buffer to the playback buffer */ |
EricLew | 0:d4e5ad7ad71c | 115 | if(RecordBufferOffset == BUFFER_OFFSET_HALF) |
EricLew | 0:d4e5ad7ad71c | 116 | { |
EricLew | 0:d4e5ad7ad71c | 117 | memcpy(&PlaybackBuffer[(RECORD_BUFFER_SIZE/2) * transfer_range], |
EricLew | 0:d4e5ad7ad71c | 118 | RecordBuffer, |
EricLew | 0:d4e5ad7ad71c | 119 | RECORD_BUFFER_SIZE); |
EricLew | 0:d4e5ad7ad71c | 120 | |
EricLew | 0:d4e5ad7ad71c | 121 | |
EricLew | 0:d4e5ad7ad71c | 122 | } |
EricLew | 0:d4e5ad7ad71c | 123 | else /* if(RecordBufferOffset == BUFFER_OFFSET_FULL)*/ |
EricLew | 0:d4e5ad7ad71c | 124 | { |
EricLew | 0:d4e5ad7ad71c | 125 | memcpy(&PlaybackBuffer[(RECORD_BUFFER_SIZE/2) * transfer_range], |
EricLew | 0:d4e5ad7ad71c | 126 | &RecordBuffer[RECORD_BUFFER_SIZE/2], |
EricLew | 0:d4e5ad7ad71c | 127 | RECORD_BUFFER_SIZE); |
EricLew | 0:d4e5ad7ad71c | 128 | } |
EricLew | 0:d4e5ad7ad71c | 129 | |
EricLew | 0:d4e5ad7ad71c | 130 | /* Wait for next data */ |
EricLew | 0:d4e5ad7ad71c | 131 | RecordBufferOffset = BUFFER_OFFSET_NONE; |
EricLew | 0:d4e5ad7ad71c | 132 | transfer_range = (transfer_range+1) % 4; |
EricLew | 0:d4e5ad7ad71c | 133 | } |
EricLew | 0:d4e5ad7ad71c | 134 | } |
EricLew | 0:d4e5ad7ad71c | 135 | |
EricLew | 0:d4e5ad7ad71c | 136 | |
EricLew | 1:1ae4b642c533 | 137 | /* Stop audio input */ |
EricLew | 1:1ae4b642c533 | 138 | if (BSP_AUDIO_IN_Stop() != AUDIO_OK) |
EricLew | 1:1ae4b642c533 | 139 | { |
EricLew | 1:1ae4b642c533 | 140 | Error_Handler(); |
EricLew | 1:1ae4b642c533 | 141 | } |
EricLew | 1:1ae4b642c533 | 142 | /* De-initialize audio input */ |
EricLew | 1:1ae4b642c533 | 143 | if (BSP_AUDIO_IN_DeInit() != AUDIO_OK) |
EricLew | 1:1ae4b642c533 | 144 | { |
EricLew | 1:1ae4b642c533 | 145 | Error_Handler(); |
EricLew | 1:1ae4b642c533 | 146 | } |
EricLew | 1:1ae4b642c533 | 147 | //END OF RECORDING #0 |
EricLew | 1:1ae4b642c533 | 148 | //INITIALIZE RECORDING #1 |
EricLew | 1:1ae4b642c533 | 149 | transfer_range = 0; |
EricLew | 1:1ae4b642c533 | 150 | |
EricLew | 1:1ae4b642c533 | 151 | /* Flag indicating whether the audio codec has already been initialized */ |
EricLew | 1:1ae4b642c533 | 152 | audio_loop_back_init = RESET ; |
EricLew | 1:1ae4b642c533 | 153 | |
EricLew | 1:1ae4b642c533 | 154 | /* Turn off green LED5 */ |
EricLew | 1:1ae4b642c533 | 155 | BSP_LED_Off(LED5); |
EricLew | 0:d4e5ad7ad71c | 156 | |
EricLew | 1:1ae4b642c533 | 157 | /* Initialize record buffer offset */ |
EricLew | 1:1ae4b642c533 | 158 | RecordBufferOffset = BUFFER_OFFSET_NONE; |
EricLew | 1:1ae4b642c533 | 159 | /* Initialize audio input */ |
EricLew | 1:1ae4b642c533 | 160 | if (BSP_AUDIO_IN_Init(SamplesRates[SampleRateIndex], |
EricLew | 1:1ae4b642c533 | 161 | DEFAULT_AUDIO_IN_BIT_RESOLUTION, |
EricLew | 1:1ae4b642c533 | 162 | DEFAULT_AUDIO_IN_CHANNEL_NBR) != AUDIO_OK) |
EricLew | 1:1ae4b642c533 | 163 | { |
EricLew | 1:1ae4b642c533 | 164 | /* Record Error */ |
EricLew | 1:1ae4b642c533 | 165 | Error_Handler(); |
EricLew | 1:1ae4b642c533 | 166 | } |
EricLew | 1:1ae4b642c533 | 167 | |
EricLew | 1:1ae4b642c533 | 168 | /* Set Callback function pointers */ |
EricLew | 1:1ae4b642c533 | 169 | BSP_AUDIO_IN_RegisterCallbacks(AudioRecord_Error_CallBack, |
EricLew | 1:1ae4b642c533 | 170 | AudioRecord_HalfTransfer_CallBack, |
EricLew | 1:1ae4b642c533 | 171 | AudioRecord_TransferComplete_CallBack); |
EricLew | 1:1ae4b642c533 | 172 | |
EricLew | 1:1ae4b642c533 | 173 | /* Start the audio record */ |
EricLew | 1:1ae4b642c533 | 174 | if (BSP_AUDIO_IN_Record((uint16_t*)&RecordBuffer1[0], |
EricLew | 1:1ae4b642c533 | 175 | RECORD_BUFFER_SIZE) != AUDIO_OK) |
EricLew | 1:1ae4b642c533 | 176 | { |
EricLew | 1:1ae4b642c533 | 177 | Error_Handler(); |
EricLew | 1:1ae4b642c533 | 178 | } |
EricLew | 1:1ae4b642c533 | 179 | |
EricLew | 1:1ae4b642c533 | 180 | AudioRecordExit = 0; //RESET AUDIO RECORD FLAG |
EricLew | 1:1ae4b642c533 | 181 | counter=0; //RESET COUNTER |
EricLew | 1:1ae4b642c533 | 182 | /* PCM samples recording loop */ //COPIED FROM ABOVE USE '1' WHEN REFERENCING VARIABLES |
EricLew | 1:1ae4b642c533 | 183 | while (AudioRecordExit != SET) |
EricLew | 1:1ae4b642c533 | 184 | { |
EricLew | 1:1ae4b642c533 | 185 | |
EricLew | 1:1ae4b642c533 | 186 | if (counter==10000000) //Approximately 3 seconds of record time |
EricLew | 1:1ae4b642c533 | 187 | { |
EricLew | 1:1ae4b642c533 | 188 | AudioRecordExit=1; //FLAG IS REGISTER R5 |
EricLew | 1:1ae4b642c533 | 189 | } |
EricLew | 1:1ae4b642c533 | 190 | else |
EricLew | 1:1ae4b642c533 | 191 | { |
EricLew | 1:1ae4b642c533 | 192 | counter=counter++; |
EricLew | 1:1ae4b642c533 | 193 | } |
EricLew | 1:1ae4b642c533 | 194 | /* 1st or 2nd half of the record buffer ready for being copied |
EricLew | 1:1ae4b642c533 | 195 | to the playback buffer */ |
EricLew | 1:1ae4b642c533 | 196 | if(RecordBufferOffset != BUFFER_OFFSET_NONE) |
EricLew | 1:1ae4b642c533 | 197 | { |
EricLew | 1:1ae4b642c533 | 198 | /* Copy half of the record buffer to the playback buffer */ |
EricLew | 1:1ae4b642c533 | 199 | if(RecordBufferOffset == BUFFER_OFFSET_HALF) |
EricLew | 1:1ae4b642c533 | 200 | { |
EricLew | 1:1ae4b642c533 | 201 | memcpy(&PlaybackBuffer1[(RECORD_BUFFER_SIZE/2) * transfer_range], |
EricLew | 1:1ae4b642c533 | 202 | RecordBuffer1, |
EricLew | 1:1ae4b642c533 | 203 | RECORD_BUFFER_SIZE); |
EricLew | 1:1ae4b642c533 | 204 | |
EricLew | 1:1ae4b642c533 | 205 | |
EricLew | 1:1ae4b642c533 | 206 | } |
EricLew | 1:1ae4b642c533 | 207 | else /* if(RecordBufferOffset == BUFFER_OFFSET_FULL)*/ |
EricLew | 1:1ae4b642c533 | 208 | { |
EricLew | 1:1ae4b642c533 | 209 | memcpy(&PlaybackBuffer1[(RECORD_BUFFER_SIZE/2) * transfer_range], |
EricLew | 1:1ae4b642c533 | 210 | &RecordBuffer1[RECORD_BUFFER_SIZE/2], |
EricLew | 1:1ae4b642c533 | 211 | RECORD_BUFFER_SIZE); |
EricLew | 1:1ae4b642c533 | 212 | } |
EricLew | 1:1ae4b642c533 | 213 | |
EricLew | 1:1ae4b642c533 | 214 | /* Wait for next data */ |
EricLew | 1:1ae4b642c533 | 215 | RecordBufferOffset = BUFFER_OFFSET_NONE; |
EricLew | 1:1ae4b642c533 | 216 | transfer_range = (transfer_range+1) % 4; |
EricLew | 1:1ae4b642c533 | 217 | } |
EricLew | 1:1ae4b642c533 | 218 | } |
EricLew | 1:1ae4b642c533 | 219 | |
EricLew | 0:d4e5ad7ad71c | 220 | |
EricLew | 0:d4e5ad7ad71c | 221 | /* Stop audio input */ |
EricLew | 0:d4e5ad7ad71c | 222 | if (BSP_AUDIO_IN_Stop() != AUDIO_OK) |
EricLew | 0:d4e5ad7ad71c | 223 | { |
EricLew | 0:d4e5ad7ad71c | 224 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 225 | } |
EricLew | 1:1ae4b642c533 | 226 | |
EricLew | 0:d4e5ad7ad71c | 227 | /* De-initialize audio input */ |
EricLew | 0:d4e5ad7ad71c | 228 | if (BSP_AUDIO_IN_DeInit() != AUDIO_OK) |
EricLew | 0:d4e5ad7ad71c | 229 | { |
EricLew | 0:d4e5ad7ad71c | 230 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 231 | } |
EricLew | 1:1ae4b642c533 | 232 | //END OF RECORDING #1 |
EricLew | 0:d4e5ad7ad71c | 233 | /* Turn OFF LED5: stop record */ |
EricLew | 0:d4e5ad7ad71c | 234 | BSP_LED_Off(LED5); |
EricLew | 0:d4e5ad7ad71c | 235 | |
EricLew | 0:d4e5ad7ad71c | 236 | /* Reset AudioRecordExit flag */ |
EricLew | 0:d4e5ad7ad71c | 237 | AudioRecordExit = 0; |
EricLew | 1:1ae4b642c533 | 238 | |
EricLew | 3:ec7e3c37fe80 | 239 | // uint32_t fftLenReal=4096; |
EricLew | 3:ec7e3c37fe80 | 240 | // uint32_t ifftFlagR=0; |
EricLew | 3:ec7e3c37fe80 | 241 | // uint32_t bitReverseFlag=0; |
EricLew | 3:ec7e3c37fe80 | 242 | // |
EricLew | 3:ec7e3c37fe80 | 243 | // arm_rfft_init_q31 (arm_rfft_instance_q31, fftLenReal, ifftFlagR, bitReverseFlag) |
EricLew | 3:ec7e3c37fe80 | 244 | // |
EricLew | 3:ec7e3c37fe80 | 245 | // |
EricLew | 3:ec7e3c37fe80 | 246 | // arm_rfft_q31 ( const arm_rfft_instance_q31 * S, &PlaybackBuffer, |
EricLew | 3:ec7e3c37fe80 | 247 | //q31_t * pDst |
EricLew | 3:ec7e3c37fe80 | 248 | //) |
EricLew | 3:ec7e3c37fe80 | 249 | // |
EricLew | 3:ec7e3c37fe80 | 250 | |
EricLew | 1:1ae4b642c533 | 251 | |
EricLew | 0:d4e5ad7ad71c | 252 | /* Turn off green led */ |
EricLew | 0:d4e5ad7ad71c | 253 | AudioDemo = AUDIO_DEMO_NONE; |
EricLew | 0:d4e5ad7ad71c | 254 | } |
EricLew | 0:d4e5ad7ad71c | 255 | |
EricLew | 0:d4e5ad7ad71c | 256 | /** |
EricLew | 0:d4e5ad7ad71c | 257 | * @brief Display actual audio record sample rate on LCD |
EricLew | 0:d4e5ad7ad71c | 258 | * @param None |
EricLew | 0:d4e5ad7ad71c | 259 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 260 | */ |
EricLew | 0:d4e5ad7ad71c | 261 | static void SampleRateDisplay(uint8_t SampleRate) |
EricLew | 0:d4e5ad7ad71c | 262 | { |
EricLew | 0:d4e5ad7ad71c | 263 | /* Clear the LCD glass */ |
EricLew | 0:d4e5ad7ad71c | 264 | BSP_LCD_GLASS_Clear(); |
EricLew | 0:d4e5ad7ad71c | 265 | |
EricLew | 0:d4e5ad7ad71c | 266 | /* Display actual audio record sample rate */ |
EricLew | 0:d4e5ad7ad71c | 267 | switch (SamplesRates[SampleRate]) |
EricLew | 0:d4e5ad7ad71c | 268 | { |
EricLew | 0:d4e5ad7ad71c | 269 | case BSP_AUDIO_FREQUENCY_48K: |
EricLew | 0:d4e5ad7ad71c | 270 | BSP_LCD_GLASS_DisplayString((uint8_t *)"48000"); |
EricLew | 0:d4e5ad7ad71c | 271 | break; |
EricLew | 1:1ae4b642c533 | 272 | } |
EricLew | 1:1ae4b642c533 | 273 | } |
EricLew | 0:d4e5ad7ad71c | 274 | /** |
EricLew | 0:d4e5ad7ad71c | 275 | * @brief Audio record sample rate selection |
EricLew | 0:d4e5ad7ad71c | 276 | * @param None |
EricLew | 0:d4e5ad7ad71c | 277 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 278 | */ |
EricLew | 0:d4e5ad7ad71c | 279 | void SampleRateSelection(void) |
EricLew | 0:d4e5ad7ad71c | 280 | { |
EricLew | 0:d4e5ad7ad71c | 281 | /* Display actual audio record sample rate */ |
EricLew | 0:d4e5ad7ad71c | 282 | SampleRateDisplay(SampleRateIndex); |
EricLew | 0:d4e5ad7ad71c | 283 | |
EricLew | 0:d4e5ad7ad71c | 284 | /* Select audio record sample rate */ |
EricLew | 0:d4e5ad7ad71c | 285 | while (!AudioRecordSampleRateSelected) |
EricLew | 0:d4e5ad7ad71c | 286 | { |
EricLew | 0:d4e5ad7ad71c | 287 | if (AudioRecordSampleRateChange != 0) |
EricLew | 0:d4e5ad7ad71c | 288 | { |
EricLew | 0:d4e5ad7ad71c | 289 | SampleRateDisplay(SampleRateIndex); |
EricLew | 0:d4e5ad7ad71c | 290 | HAL_Delay(5); |
EricLew | 0:d4e5ad7ad71c | 291 | AudioRecordSampleRateChange = 0; |
EricLew | 0:d4e5ad7ad71c | 292 | } |
EricLew | 0:d4e5ad7ad71c | 293 | } |
EricLew | 0:d4e5ad7ad71c | 294 | |
EricLew | 0:d4e5ad7ad71c | 295 | AudioRecordSampleRateSelected = 0; |
EricLew | 0:d4e5ad7ad71c | 296 | } |
EricLew | 0:d4e5ad7ad71c | 297 | |
EricLew | 0:d4e5ad7ad71c | 298 | /** |
EricLew | 0:d4e5ad7ad71c | 299 | * @brief Callback function invoked when half of the PCM samples have been |
EricLew | 0:d4e5ad7ad71c | 300 | * DM Atransfered from the DFSDM channel. |
EricLew | 0:d4e5ad7ad71c | 301 | * @param None |
EricLew | 0:d4e5ad7ad71c | 302 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 303 | */ |
EricLew | 0:d4e5ad7ad71c | 304 | void AudioRecord_TransferComplete_CallBack(void) |
EricLew | 0:d4e5ad7ad71c | 305 | { |
EricLew | 0:d4e5ad7ad71c | 306 | /* Toggle green LED */ |
EricLew | 0:d4e5ad7ad71c | 307 | BSP_LED_Toggle(LED5); |
EricLew | 0:d4e5ad7ad71c | 308 | |
EricLew | 0:d4e5ad7ad71c | 309 | RecordBufferOffset = BUFFER_OFFSET_FULL; |
EricLew | 0:d4e5ad7ad71c | 310 | } |
EricLew | 0:d4e5ad7ad71c | 311 | |
EricLew | 0:d4e5ad7ad71c | 312 | /** |
EricLew | 0:d4e5ad7ad71c | 313 | * @brief Callback function invoked when all the PCM samples have been |
EricLew | 0:d4e5ad7ad71c | 314 | * DMA transfered from the DFSDM channel. |
EricLew | 0:d4e5ad7ad71c | 315 | * @param None |
EricLew | 0:d4e5ad7ad71c | 316 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 317 | */ |
EricLew | 0:d4e5ad7ad71c | 318 | void AudioRecord_HalfTransfer_CallBack(void) |
EricLew | 0:d4e5ad7ad71c | 319 | { |
EricLew | 0:d4e5ad7ad71c | 320 | RecordBufferOffset = BUFFER_OFFSET_HALF; |
EricLew | 0:d4e5ad7ad71c | 321 | } |
EricLew | 0:d4e5ad7ad71c | 322 | |
EricLew | 0:d4e5ad7ad71c | 323 | /** |
EricLew | 0:d4e5ad7ad71c | 324 | * @brief Callback function invoked when an error occured durint he DMA |
EricLew | 0:d4e5ad7ad71c | 325 | * transfer of the PCM samples from the DFSDM channel. |
EricLew | 0:d4e5ad7ad71c | 326 | * @param None |
EricLew | 0:d4e5ad7ad71c | 327 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 328 | */ |
EricLew | 0:d4e5ad7ad71c | 329 | void AudioRecord_Error_CallBack(void) |
EricLew | 0:d4e5ad7ad71c | 330 | { |
EricLew | 0:d4e5ad7ad71c | 331 | /* Stop the program with an infinite loop */ |
EricLew | 0:d4e5ad7ad71c | 332 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 333 | } |
EricLew | 0:d4e5ad7ad71c | 334 | /** |
EricLew | 0:d4e5ad7ad71c | 335 | * @} |
EricLew | 0:d4e5ad7ad71c | 336 | */ |
EricLew | 0:d4e5ad7ad71c | 337 | |
EricLew | 0:d4e5ad7ad71c | 338 | |
EricLew | 0:d4e5ad7ad71c | 339 | /** |
EricLew | 0:d4e5ad7ad71c | 340 | * @} |
EricLew | 0:d4e5ad7ad71c | 341 | */ |
EricLew | 0:d4e5ad7ad71c | 342 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
EricLew | 0:d4e5ad7ad71c | 343 |