lab 1 code

Dependencies:   CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG

Committer:
bmazzeo
Date:
Tue Dec 31 20:10:06 2019 +0000
Revision:
22:f36d7a53bb7e
Parent:
21:4dbfda694c0d
Child:
23:d938f87dd1ee
Floating point conversion and back for both blocks

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