lab 1 code

Dependencies:   CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG

Committer:
bmazzeo
Date:
Wed Jan 01 17:17:36 2020 +0000
Revision:
26:023edf8cea6c
Parent:
25:5412779376a7
Child:
30:debea332cdfe
Just changed the display of information to put a bit more in first half block and take some from second half block.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bmazzeo 9:f5b37c71856d 1 /**
bmazzeo 9:f5b37c71856d 2 ******************************************************************************
bmazzeo 9:f5b37c71856d 3 * @file main.c
bmazzeo 9:f5b37c71856d 4 * @author Brian Mazzeo
bmazzeo 23:d938f87dd1ee 5 * @date 2020
bmazzeo 9:f5b37c71856d 6 * @brief This file provides a set of code for signal processing in 487.
bmazzeo 9:f5b37c71856d 7 * Parts are taken from example code from STMIcroelectronics
bmazzeo 9:f5b37c71856d 8 ******************************************************************************
bmazzeo 9:f5b37c71856d 9 * @attention
bmazzeo 13:61131aac4031 10 * This code was specifically developed for BYU ECEn 487 course
bmazzeo 13:61131aac4031 11 * Introduction to Digital Signal Processing.
bmazzeo 9:f5b37c71856d 12 *
bmazzeo 9:f5b37c71856d 13 *
bmazzeo 9:f5b37c71856d 14 ******************************************************************************
bmazzeo 9:f5b37c71856d 15 */
bmazzeo 9:f5b37c71856d 16
bmazzeo 9:f5b37c71856d 17
adustm 0:da04816fb411 18 #include "mbed.h"
Jerome Coutant 5:66c230f74325 19 #include "stm32746g_discovery_audio.h"
Jerome Coutant 5:66c230f74325 20 #include "stm32746g_discovery_sdram.h"
bmazzeo 6:e689075b04ed 21 #include "stm32746g_discovery_lcd.h"
bmazzeo 23:d938f87dd1ee 22 #include "signal_processing.h"
adustm 0:da04816fb411 23
Jerome Coutant 5:66c230f74325 24 typedef enum {
adustm 0:da04816fb411 25 BUFFER_OFFSET_NONE = 0,
adustm 0:da04816fb411 26 BUFFER_OFFSET_HALF = 1,
adustm 0:da04816fb411 27 BUFFER_OFFSET_FULL = 2,
Jerome Coutant 5:66c230f74325 28 } BUFFER_StateTypeDef;
Jerome Coutant 5:66c230f74325 29
bmazzeo 19:479f611941a8 30 #define AUDIO_BLOCK_SAMPLES ((uint32_t)128) // Number of samples (L and R) in audio block (each samples is 16 bits)
bmazzeo 19:479f611941a8 31 #define AUDIO_BLOCK_SIZE ((uint32_t)512) // Number of bytes in audio block (4 * AUDIO_BLOCK_SAMPLES)
bmazzeo 6:e689075b04ed 32
bmazzeo 9:f5b37c71856d 33 #define SDRAM_DEVICE_ADDR_AUDIO_MEM ((uint32_t)0xC0400000)
bmazzeo 9:f5b37c71856d 34 #define AUDIO_BUFFER_IN SDRAM_DEVICE_ADDR_AUDIO_MEM
bmazzeo 9:f5b37c71856d 35 #define AUDIO_BUFFER_OUT (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE * 2))
Jerome Coutant 5:66c230f74325 36
bmazzeo 8:d1c41eca57f0 37 #define OSC_START_X_POS 20
bmazzeo 6:e689075b04ed 38 #define OSC_LINE_SIZE 256
bmazzeo 17:eb85a2387dd4 39 #define OSC_Y_POS 110
bmazzeo 7:e1dfd64eba81 40 #define AUDIO_DRAW_LIMIT 30
bmazzeo 6:e689075b04ed 41
bmazzeo 9:f5b37c71856d 42 Timer timer;
bmazzeo 9:f5b37c71856d 43
Jerome Coutant 5:66c230f74325 44 volatile uint32_t audio_rec_buffer_state = BUFFER_OFFSET_NONE;
bmazzeo 17:eb85a2387dd4 45 static void Erase_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t Length);
bmazzeo 17:eb85a2387dd4 46 static void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t* Mem_start, uint16_t Length);
bmazzeo 16:b7dca59ab076 47 static void Audio_to_Float(uint16_t* buffer_in, float* L_out, float* R_out, uint16_t Length);
bmazzeo 16:b7dca59ab076 48 static void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length);
Jerome Coutant 5:66c230f74325 49
bmazzeo 20:2ecdf687a2d1 50 /* To do conversion to float */
bmazzeo 19:479f611941a8 51 float L_channel_float[AUDIO_BLOCK_SAMPLES];
bmazzeo 19:479f611941a8 52 float R_channel_float[AUDIO_BLOCK_SAMPLES];
bmazzeo 20:2ecdf687a2d1 53 float *L_channel_float_p = &L_channel_float[0];
bmazzeo 20:2ecdf687a2d1 54 float *R_channel_float_p = &R_channel_float[0];
bmazzeo 14:18f159d48340 55
bmazzeo 14:18f159d48340 56 /* Back conversion to integer */
bmazzeo 22:f36d7a53bb7e 57 uint16_t Processed_audio[AUDIO_BLOCK_SAMPLES];
bmazzeo 20:2ecdf687a2d1 58 uint16_t *Processed_audio_p = &Processed_audio[0];
bmazzeo 14:18f159d48340 59
bmazzeo 14:18f159d48340 60 /* Useful variables during looping */
bmazzeo 9:f5b37c71856d 61 uint32_t counter = 0;
bmazzeo 10:a82b64ea1d11 62 char buf[40];
bmazzeo 13:61131aac4031 63 int first_half_time = 0;
bmazzeo 13:61131aac4031 64 int second_half_time = 0;
bmazzeo 13:61131aac4031 65 int total_time = 0;
bmazzeo 9:f5b37c71856d 66
adustm 0:da04816fb411 67 int main()
adustm 0:da04816fb411 68 {
bmazzeo 13:61131aac4031 69 /* Initialize the LCD Screen and display information */
bmazzeo 6:e689075b04ed 70 BSP_LCD_Init();
bmazzeo 6:e689075b04ed 71 BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS);
bmazzeo 6:e689075b04ed 72 BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER);
bmazzeo 6:e689075b04ed 73
bmazzeo 6:e689075b04ed 74 BSP_LCD_Clear(LCD_COLOR_BLACK);
bmazzeo 6:e689075b04ed 75 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
bmazzeo 6:e689075b04ed 76
bmazzeo 6:e689075b04ed 77 BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
bmazzeo 6:e689075b04ed 78 BSP_LCD_SetTextColor(LCD_COLOR_ORANGE);
bmazzeo 7:e1dfd64eba81 79 BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"487 Mic Audio Test Code", LEFT_MODE);
bmazzeo 17:eb85a2387dd4 80 BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
bmazzeo 17:eb85a2387dd4 81 BSP_LCD_DisplayStringAt(0, OSC_Y_POS - 20, (uint8_t *)"L", LEFT_MODE);
bmazzeo 17:eb85a2387dd4 82 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
bmazzeo 17:eb85a2387dd4 83 BSP_LCD_DisplayStringAt(0, OSC_Y_POS, (uint8_t *)"R", LEFT_MODE);
bmazzeo 6:e689075b04ed 84
bmazzeo 13:61131aac4031 85
bmazzeo 13:61131aac4031 86 /* Initialize the Audio Interface */
Jerome Coutant 5:66c230f74325 87 BSP_AUDIO_IN_OUT_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2, OUTPUT_DEVICE_HEADPHONE, DEFAULT_AUDIO_IN_FREQ, DEFAULT_AUDIO_IN_BIT_RESOLUTION, DEFAULT_AUDIO_IN_CHANNEL_NBR);
adustm 0:da04816fb411 88
adustm 0:da04816fb411 89 /* Initialize SDRAM buffers */
Jerome Coutant 5:66c230f74325 90 BSP_SDRAM_Init();
Jerome Coutant 5:66c230f74325 91 memset((uint16_t *)AUDIO_BUFFER_IN, 0, AUDIO_BLOCK_SIZE * 2);
Jerome Coutant 5:66c230f74325 92 memset((uint16_t *)AUDIO_BUFFER_OUT, 0, AUDIO_BLOCK_SIZE * 2);
Jerome Coutant 5:66c230f74325 93
adustm 0:da04816fb411 94
adustm 0:da04816fb411 95 /* Start Recording */
bmazzeo 13:61131aac4031 96 if (BSP_AUDIO_IN_Record((uint16_t *)AUDIO_BUFFER_IN, AUDIO_BLOCK_SIZE) != AUDIO_OK) { printf("BSP_AUDIO_IN_Record error\n"); }
adustm 0:da04816fb411 97
adustm 0:da04816fb411 98 /* Start Playback */
Jerome Coutant 5:66c230f74325 99 BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
bmazzeo 13:61131aac4031 100 if (BSP_AUDIO_OUT_Play((uint16_t *)AUDIO_BUFFER_OUT, AUDIO_BLOCK_SIZE * 2) != AUDIO_OK) { printf("BSP_AUDIO_OUT_Play error\n"); }
bmazzeo 13:61131aac4031 101
bmazzeo 25:5412779376a7 102 /* Initialize signal processing filters */
bmazzeo 25:5412779376a7 103 initalize_signal_processing();
adustm 0:da04816fb411 104
bmazzeo 9:f5b37c71856d 105 timer.start();
adustm 0:da04816fb411 106 while (1) {
bmazzeo 6:e689075b04ed 107 /* First Half */
bmazzeo 13:61131aac4031 108 /* Wait end of half block recording before going on in the first half cycle*/
bmazzeo 11:4256dbbb0c89 109 while (audio_rec_buffer_state != BUFFER_OFFSET_HALF) {}
bmazzeo 9:f5b37c71856d 110
bmazzeo 13:61131aac4031 111 /* This captures the time of an entire cycle */
bmazzeo 9:f5b37c71856d 112 total_time = timer.read_us();
bmazzeo 13:61131aac4031 113
bmazzeo 13:61131aac4031 114 /* Reset the timer counter to zero */
bmazzeo 9:f5b37c71856d 115 timer.reset();
Jerome Coutant 5:66c230f74325 116
bmazzeo 13:61131aac4031 117 /* Plot traces of first half block recording */
bmazzeo 19:479f611941a8 118 Erase_Trace(OSC_START_X_POS, OSC_Y_POS, AUDIO_BLOCK_SAMPLES);
bmazzeo 19:479f611941a8 119 Draw_Trace(OSC_START_X_POS, OSC_Y_POS, (uint16_t *) AUDIO_BUFFER_IN, AUDIO_BLOCK_SAMPLES);
bmazzeo 18:255d15af49f2 120
bmazzeo 14:18f159d48340 121 /* Convert data to floating point representation for processing */
bmazzeo 20:2ecdf687a2d1 122 Audio_to_Float((uint16_t *) AUDIO_BUFFER_IN, L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES);
bmazzeo 22:f36d7a53bb7e 123
bmazzeo 22:f36d7a53bb7e 124 /* Here is where signal processing can be done on the floating point arrays */
bmazzeo 22:f36d7a53bb7e 125
bmazzeo 23:d938f87dd1ee 126 process_audio_channel_signals(L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES);
bmazzeo 20:2ecdf687a2d1 127
bmazzeo 22:f36d7a53bb7e 128 /* Here is where signal processing can end on the floating point arrays */
bmazzeo 20:2ecdf687a2d1 129
bmazzeo 22:f36d7a53bb7e 130 /* Covert floating point data back to fixed point audio format */
bmazzeo 21:4dbfda694c0d 131 Float_to_Audio(L_channel_float_p, R_channel_float_p, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES);
bmazzeo 14:18f159d48340 132
bmazzeo 13:61131aac4031 133 /* Copy recorded 1st half block into the audio buffer that goes out */
bmazzeo 21:4dbfda694c0d 134 memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(Processed_audio), AUDIO_BLOCK_SIZE);
bmazzeo 13:61131aac4031 135
bmazzeo 26:023edf8cea6c 136 /* Display useful cycle information (split up information display so the processing is more balanced) */
bmazzeo 26:023edf8cea6c 137 sprintf(buf, "Cycles: %9d", counter);
bmazzeo 26:023edf8cea6c 138 BSP_LCD_SetTextColor(LCD_COLOR_RED);
bmazzeo 26:023edf8cea6c 139 BSP_LCD_DisplayStringAt(0, 46, (uint8_t *) buf, LEFT_MODE);
bmazzeo 26:023edf8cea6c 140
bmazzeo 26:023edf8cea6c 141
bmazzeo 13:61131aac4031 142 /* Capture the timing of the first half processing */
bmazzeo 9:f5b37c71856d 143 first_half_time = timer.read_us();
bmazzeo 13:61131aac4031 144 /* End First Half */
bmazzeo 8:d1c41eca57f0 145
bmazzeo 6:e689075b04ed 146 /* Second Half */
adustm 0:da04816fb411 147 /* Wait end of one block recording */
bmazzeo 11:4256dbbb0c89 148 while (audio_rec_buffer_state != BUFFER_OFFSET_FULL) {}
bmazzeo 9:f5b37c71856d 149
bmazzeo 13:61131aac4031 150 /* Plot traces of second half block recording */
bmazzeo 19:479f611941a8 151 Erase_Trace(OSC_START_X_POS+AUDIO_BLOCK_SAMPLES, OSC_Y_POS, AUDIO_BLOCK_SAMPLES);
bmazzeo 19:479f611941a8 152 Draw_Trace( OSC_START_X_POS+AUDIO_BLOCK_SAMPLES, OSC_Y_POS, (uint16_t *) (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SAMPLES);
bmazzeo 22:f36d7a53bb7e 153
bmazzeo 22:f36d7a53bb7e 154 /* Convert data to floating point representation for processing */
bmazzeo 22:f36d7a53bb7e 155 Audio_to_Float((uint16_t *) (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES);
bmazzeo 22:f36d7a53bb7e 156
bmazzeo 22:f36d7a53bb7e 157 /* Here is where signal processing can be done on the floating point arrays */
bmazzeo 22:f36d7a53bb7e 158
bmazzeo 23:d938f87dd1ee 159 process_audio_channel_signals(L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES);
bmazzeo 22:f36d7a53bb7e 160
bmazzeo 22:f36d7a53bb7e 161 /* Here is where signal processing can end on the floating point arrays */
bmazzeo 22:f36d7a53bb7e 162
bmazzeo 22:f36d7a53bb7e 163 /* Covert floating point data back to fixed point audio format */
bmazzeo 22:f36d7a53bb7e 164 Float_to_Audio(L_channel_float_p, R_channel_float_p, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES);
bmazzeo 22:f36d7a53bb7e 165
bmazzeo 22:f36d7a53bb7e 166 /* Copy recorded 2nd half block into the audio buffer that goes out */
bmazzeo 22:f36d7a53bb7e 167 memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *) (Processed_audio), AUDIO_BLOCK_SIZE);
bmazzeo 13:61131aac4031 168
bmazzeo 13:61131aac4031 169 /* Compute important cycle information and display it*/
bmazzeo 26:023edf8cea6c 170 sprintf(buf, "1:%6d 2:%6d T:%6d", first_half_time, second_half_time, total_time);
bmazzeo 6:e689075b04ed 171 BSP_LCD_SetTextColor(LCD_COLOR_RED);
bmazzeo 10:a82b64ea1d11 172 BSP_LCD_DisplayStringAt(0, 20, (uint8_t *) buf, LEFT_MODE);
bmazzeo 13:61131aac4031 173
bmazzeo 13:61131aac4031 174 /* Copy recorded 2nd half block into audio output buffer */
bmazzeo 22:f36d7a53bb7e 175 //memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE);
bmazzeo 18:255d15af49f2 176
bmazzeo 13:61131aac4031 177 /* Change the recording buffer state to reflect the status of the buffer */
bmazzeo 13:61131aac4031 178 audio_rec_buffer_state = BUFFER_OFFSET_NONE;
bmazzeo 26:023edf8cea6c 179
bmazzeo 26:023edf8cea6c 180 /* Increase the counter */
bmazzeo 26:023edf8cea6c 181 counter++;
bmazzeo 9:f5b37c71856d 182
bmazzeo 13:61131aac4031 183 /* Measures the amount of time to process the second half */
bmazzeo 9:f5b37c71856d 184 second_half_time = timer.read_us();
bmazzeo 9:f5b37c71856d 185
bmazzeo 13:61131aac4031 186 /* End Second Half */
adustm 0:da04816fb411 187 }
adustm 0:da04816fb411 188 }
Jerome Coutant 5:66c230f74325 189
bmazzeo 7:e1dfd64eba81 190 /**
bmazzeo 7:e1dfd64eba81 191 * @brief Draws a trace of the data line.
bmazzeo 7:e1dfd64eba81 192 * @param Xpos: X position
bmazzeo 7:e1dfd64eba81 193 * @param L_Ypos: Left channel Y position
bmazzeo 7:e1dfd64eba81 194 * @param R_Ypos: Right channel Y position
bmazzeo 7:e1dfd64eba81 195 * @param Mem_start: Start of memory location
bmazzeo 7:e1dfd64eba81 196 * @param Length: length of trace
bmazzeo 7:e1dfd64eba81 197 * @retval None
bmazzeo 7:e1dfd64eba81 198 */
bmazzeo 17:eb85a2387dd4 199 void Erase_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bmazzeo 7:e1dfd64eba81 200 {
bmazzeo 22:f36d7a53bb7e 201 /* Creates a brown rectangle above and below the axis */
bmazzeo 7:e1dfd64eba81 202 BSP_LCD_SetTextColor(LCD_COLOR_BROWN);
bmazzeo 17:eb85a2387dd4 203 BSP_LCD_FillRect(Xpos, Ypos - AUDIO_DRAW_LIMIT, Length, AUDIO_DRAW_LIMIT);
bmazzeo 17:eb85a2387dd4 204 BSP_LCD_FillRect(Xpos, Ypos+1, Length, AUDIO_DRAW_LIMIT);
bmazzeo 7:e1dfd64eba81 205
bmazzeo 22:f36d7a53bb7e 206 /* Draw axis for plotting */
bmazzeo 17:eb85a2387dd4 207 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
bmazzeo 17:eb85a2387dd4 208 BSP_LCD_DrawHLine(Xpos, Ypos, Length);
bmazzeo 7:e1dfd64eba81 209
bmazzeo 7:e1dfd64eba81 210 }
bmazzeo 7:e1dfd64eba81 211
Jerome Coutant 5:66c230f74325 212
bmazzeo 6:e689075b04ed 213 /**
bmazzeo 6:e689075b04ed 214 * @brief Draws a trace of the data line.
bmazzeo 6:e689075b04ed 215 * @param Xpos: X position
bmazzeo 7:e1dfd64eba81 216 * @param L_Ypos: Left channel Y position
bmazzeo 7:e1dfd64eba81 217 * @param R_Ypos: Right channel Y position
bmazzeo 6:e689075b04ed 218 * @param Mem_start: Start of memory location
bmazzeo 6:e689075b04ed 219 * @param Length: length of trace
bmazzeo 6:e689075b04ed 220 * @retval None
bmazzeo 6:e689075b04ed 221 */
bmazzeo 17:eb85a2387dd4 222 void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t* Mem_start, uint16_t Length)
bmazzeo 6:e689075b04ed 223 {
bmazzeo 7:e1dfd64eba81 224 uint16_t i;
bmazzeo 18:255d15af49f2 225 uint16_t* mem_address;
bmazzeo 7:e1dfd64eba81 226 char buf[10];
bmazzeo 7:e1dfd64eba81 227 int16_t L_audio_value;
bmazzeo 7:e1dfd64eba81 228 int16_t R_audio_value;
bmazzeo 20:2ecdf687a2d1 229
bmazzeo 18:255d15af49f2 230 mem_address = Mem_start;
bmazzeo 7:e1dfd64eba81 231
bmazzeo 8:d1c41eca57f0 232 for (i=0; i<Length; i++)
bmazzeo 20:2ecdf687a2d1 233 {
bmazzeo 18:255d15af49f2 234 L_audio_value = (int16_t) *mem_address;
bmazzeo 18:255d15af49f2 235 mem_address++;
bmazzeo 18:255d15af49f2 236 R_audio_value = (int16_t) *mem_address;
bmazzeo 18:255d15af49f2 237 mem_address++;
bmazzeo 7:e1dfd64eba81 238
bmazzeo 17:eb85a2387dd4 239 L_audio_value = L_audio_value / 100;
bmazzeo 17:eb85a2387dd4 240 R_audio_value = R_audio_value / 100;
bmazzeo 7:e1dfd64eba81 241
bmazzeo 7:e1dfd64eba81 242 if (L_audio_value > AUDIO_DRAW_LIMIT) {L_audio_value = AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 243 else if (L_audio_value < -AUDIO_DRAW_LIMIT) {L_audio_value = -AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 244
bmazzeo 7:e1dfd64eba81 245 if (R_audio_value > AUDIO_DRAW_LIMIT) {R_audio_value = AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 246 else if (R_audio_value < -AUDIO_DRAW_LIMIT) {R_audio_value = -AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 247
bmazzeo 17:eb85a2387dd4 248 BSP_LCD_DrawPixel(Xpos + i, (uint16_t) ((int16_t) Ypos + L_audio_value), LCD_COLOR_BLUE);
bmazzeo 17:eb85a2387dd4 249 BSP_LCD_DrawPixel(Xpos + i, (uint16_t) ((int16_t) Ypos + R_audio_value), LCD_COLOR_GREEN);
bmazzeo 6:e689075b04ed 250 }
bmazzeo 6:e689075b04ed 251
bmazzeo 6:e689075b04ed 252 }
bmazzeo 14:18f159d48340 253
bmazzeo 14:18f159d48340 254 /**
bmazzeo 14:18f159d48340 255 * @brief Converts audio data in buffer to floating point representation.
bmazzeo 14:18f159d48340 256 * @param buffer_in: Pointer to Audio buffer start location
bmazzeo 14:18f159d48340 257 * @param L_out: Pointer to Left channel out data (float)
bmazzeo 14:18f159d48340 258 * @param R_out: Pointer to Right channel out data (float)
bmazzeo 14:18f159d48340 259 * @param Length: length of data to convert
bmazzeo 14:18f159d48340 260 * @retval None
bmazzeo 14:18f159d48340 261 */
bmazzeo 16:b7dca59ab076 262 void Audio_to_Float(uint16_t* buffer_in, float* L_out, float* R_out, uint16_t Length)
bmazzeo 14:18f159d48340 263 {
bmazzeo 14:18f159d48340 264 uint16_t i;
bmazzeo 16:b7dca59ab076 265 uint16_t* audio_mem_address;
bmazzeo 20:2ecdf687a2d1 266 float* L_chan_mem_address;
bmazzeo 20:2ecdf687a2d1 267 float* R_chan_mem_address;
bmazzeo 14:18f159d48340 268 float L_audio_value;
bmazzeo 14:18f159d48340 269 float R_audio_value;
bmazzeo 20:2ecdf687a2d1 270
bmazzeo 20:2ecdf687a2d1 271 audio_mem_address = buffer_in;
bmazzeo 20:2ecdf687a2d1 272 L_chan_mem_address = L_out;
bmazzeo 20:2ecdf687a2d1 273 R_chan_mem_address = R_out;
bmazzeo 6:e689075b04ed 274
bmazzeo 14:18f159d48340 275 for (i=0; i<Length; i++)
bmazzeo 14:18f159d48340 276 {
bmazzeo 20:2ecdf687a2d1 277 L_audio_value = (float) ((int16_t) *audio_mem_address);
bmazzeo 20:2ecdf687a2d1 278 audio_mem_address++;
bmazzeo 20:2ecdf687a2d1 279 R_audio_value = (float) ((int16_t) *audio_mem_address);
bmazzeo 20:2ecdf687a2d1 280 audio_mem_address++;
bmazzeo 14:18f159d48340 281
bmazzeo 16:b7dca59ab076 282 *L_chan_mem_address = L_audio_value;
bmazzeo 20:2ecdf687a2d1 283 L_chan_mem_address++;
bmazzeo 20:2ecdf687a2d1 284
bmazzeo 14:18f159d48340 285 *R_chan_mem_address = R_audio_value;
bmazzeo 20:2ecdf687a2d1 286 R_chan_mem_address++;
bmazzeo 14:18f159d48340 287 }
bmazzeo 14:18f159d48340 288 }
bmazzeo 14:18f159d48340 289
bmazzeo 14:18f159d48340 290 /**
bmazzeo 14:18f159d48340 291 * @brief Converts audio data in buffer to floating point representation.
bmazzeo 14:18f159d48340 292 * @param L_out: Pointer to Left channel in data (float)
bmazzeo 14:18f159d48340 293 * @param R_out: Pointer to Right channel in data (float)
bmazzeo 14:18f159d48340 294 * @param buffer_out: Pointer to combined 32 bit (two 16-bit int samples)
bmazzeo 14:18f159d48340 295 * @param Length: length of data to convert
bmazzeo 14:18f159d48340 296 * @retval None
bmazzeo 14:18f159d48340 297 */
bmazzeo 16:b7dca59ab076 298 void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length)
bmazzeo 14:18f159d48340 299 {
bmazzeo 14:18f159d48340 300 uint16_t i;
bmazzeo 14:18f159d48340 301 uint16_t* audio_mem_address;
bmazzeo 21:4dbfda694c0d 302 float* L_chan_mem_address;
bmazzeo 21:4dbfda694c0d 303 float* R_chan_mem_address;
bmazzeo 21:4dbfda694c0d 304 int16_t L_audio_value;
bmazzeo 21:4dbfda694c0d 305 int16_t R_audio_value;
bmazzeo 21:4dbfda694c0d 306
bmazzeo 21:4dbfda694c0d 307 audio_mem_address = buffer_out;
bmazzeo 21:4dbfda694c0d 308 L_chan_mem_address = L_in;
bmazzeo 21:4dbfda694c0d 309 R_chan_mem_address = R_in;
bmazzeo 14:18f159d48340 310
bmazzeo 14:18f159d48340 311 for (i=0; i<Length; i++)
bmazzeo 14:18f159d48340 312 {
bmazzeo 21:4dbfda694c0d 313 L_audio_value = (int16_t) ((float) *L_chan_mem_address);
bmazzeo 21:4dbfda694c0d 314 L_chan_mem_address++;
bmazzeo 14:18f159d48340 315
bmazzeo 21:4dbfda694c0d 316 R_audio_value = (int16_t) ((float) *R_chan_mem_address);
bmazzeo 21:4dbfda694c0d 317 R_chan_mem_address++;
bmazzeo 21:4dbfda694c0d 318
bmazzeo 21:4dbfda694c0d 319 *audio_mem_address = (uint16_t) L_audio_value;
bmazzeo 21:4dbfda694c0d 320 audio_mem_address++;
bmazzeo 21:4dbfda694c0d 321 *audio_mem_address = (uint16_t) R_audio_value;
bmazzeo 21:4dbfda694c0d 322 audio_mem_address++;
bmazzeo 14:18f159d48340 323 }
bmazzeo 14:18f159d48340 324 }
bmazzeo 14:18f159d48340 325
bmazzeo 14:18f159d48340 326
bmazzeo 14:18f159d48340 327
bmazzeo 6:e689075b04ed 328
bmazzeo 6:e689075b04ed 329
adustm 0:da04816fb411 330 /*-------------------------------------------------------------------------------------
adustm 0:da04816fb411 331 Callbacks implementation:
adustm 0:da04816fb411 332 the callbacks API are defined __weak in the stm32746g_discovery_audio.c file
adustm 0:da04816fb411 333 and their implementation should be done in the user code if they are needed.
adustm 0:da04816fb411 334 Below some examples of callback implementations.
adustm 0:da04816fb411 335 -------------------------------------------------------------------------------------*/
adustm 0:da04816fb411 336 /**
adustm 0:da04816fb411 337 * @brief Manages the DMA Transfer complete interrupt.
adustm 0:da04816fb411 338 * @param None
adustm 0:da04816fb411 339 * @retval None
adustm 0:da04816fb411 340 */
adustm 0:da04816fb411 341 void BSP_AUDIO_IN_TransferComplete_CallBack(void)
adustm 0:da04816fb411 342 {
Jerome Coutant 5:66c230f74325 343 audio_rec_buffer_state = BUFFER_OFFSET_FULL;
adustm 0:da04816fb411 344 }
adustm 0:da04816fb411 345
adustm 0:da04816fb411 346 /**
adustm 0:da04816fb411 347 * @brief Manages the DMA Half Transfer complete interrupt.
adustm 0:da04816fb411 348 * @param None
adustm 0:da04816fb411 349 * @retval None
adustm 0:da04816fb411 350 */
adustm 0:da04816fb411 351 void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
adustm 0:da04816fb411 352 {
Jerome Coutant 5:66c230f74325 353 audio_rec_buffer_state = BUFFER_OFFSET_HALF;
adustm 0:da04816fb411 354 }
adustm 0:da04816fb411 355
Jerome Coutant 5:66c230f74325 356 /**
Jerome Coutant 5:66c230f74325 357 * @brief Audio IN Error callback function.
Jerome Coutant 5:66c230f74325 358 * @param None
Jerome Coutant 5:66c230f74325 359 * @retval None
Jerome Coutant 5:66c230f74325 360 */
Jerome Coutant 5:66c230f74325 361 void BSP_AUDIO_IN_Error_CallBack(void)
adustm 0:da04816fb411 362 {
Jerome Coutant 5:66c230f74325 363 printf("BSP_AUDIO_IN_Error_CallBack\n");
adustm 0:da04816fb411 364 }