lab 1 code

Dependencies:   CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG

Committer:
bmazzeo
Date:
Wed Jan 01 06:47:21 2020 +0000
Revision:
25:5412779376a7
Parent:
23:d938f87dd1ee
Child:
26:023edf8cea6c
Working example!!! - L channel has lowpass filter. Proper initialization of filters is performed. Output is clean.

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 13:61131aac4031 136 /* Capture the timing of the first half processing */
bmazzeo 9:f5b37c71856d 137 first_half_time = timer.read_us();
bmazzeo 13:61131aac4031 138 /* End First Half */
bmazzeo 8:d1c41eca57f0 139
bmazzeo 6:e689075b04ed 140 /* Second Half */
adustm 0:da04816fb411 141 /* Wait end of one block recording */
bmazzeo 11:4256dbbb0c89 142 while (audio_rec_buffer_state != BUFFER_OFFSET_FULL) {}
bmazzeo 9:f5b37c71856d 143
bmazzeo 13:61131aac4031 144 /* Plot traces of second half block recording */
bmazzeo 19:479f611941a8 145 Erase_Trace(OSC_START_X_POS+AUDIO_BLOCK_SAMPLES, OSC_Y_POS, AUDIO_BLOCK_SAMPLES);
bmazzeo 19:479f611941a8 146 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 147
bmazzeo 22:f36d7a53bb7e 148 /* Convert data to floating point representation for processing */
bmazzeo 22:f36d7a53bb7e 149 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 150
bmazzeo 22:f36d7a53bb7e 151 /* Here is where signal processing can be done on the floating point arrays */
bmazzeo 22:f36d7a53bb7e 152
bmazzeo 23:d938f87dd1ee 153 process_audio_channel_signals(L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES);
bmazzeo 22:f36d7a53bb7e 154
bmazzeo 22:f36d7a53bb7e 155 /* Here is where signal processing can end on the floating point arrays */
bmazzeo 22:f36d7a53bb7e 156
bmazzeo 22:f36d7a53bb7e 157 /* Covert floating point data back to fixed point audio format */
bmazzeo 22:f36d7a53bb7e 158 Float_to_Audio(L_channel_float_p, R_channel_float_p, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES);
bmazzeo 22:f36d7a53bb7e 159
bmazzeo 22:f36d7a53bb7e 160 /* Copy recorded 2nd half block into the audio buffer that goes out */
bmazzeo 22:f36d7a53bb7e 161 memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *) (Processed_audio), AUDIO_BLOCK_SIZE);
bmazzeo 13:61131aac4031 162
bmazzeo 13:61131aac4031 163 /* Compute important cycle information and display it*/
bmazzeo 6:e689075b04ed 164 counter++;
bmazzeo 10:a82b64ea1d11 165 sprintf(buf, "Cycles: %9d", counter);
bmazzeo 6:e689075b04ed 166 BSP_LCD_SetTextColor(LCD_COLOR_RED);
bmazzeo 10:a82b64ea1d11 167 BSP_LCD_DisplayStringAt(0, 46, (uint8_t *) buf, LEFT_MODE);
bmazzeo 10:a82b64ea1d11 168 sprintf(buf, "1:%6d 2:%6d T:%6d", first_half_time, second_half_time, total_time);
bmazzeo 10:a82b64ea1d11 169 BSP_LCD_DisplayStringAt(0, 20, (uint8_t *) buf, LEFT_MODE);
bmazzeo 13:61131aac4031 170
bmazzeo 13:61131aac4031 171 /* Copy recorded 2nd half block into audio output buffer */
bmazzeo 22:f36d7a53bb7e 172 //memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE);
bmazzeo 18:255d15af49f2 173
bmazzeo 13:61131aac4031 174 /* Change the recording buffer state to reflect the status of the buffer */
bmazzeo 13:61131aac4031 175 audio_rec_buffer_state = BUFFER_OFFSET_NONE;
bmazzeo 9:f5b37c71856d 176
bmazzeo 13:61131aac4031 177 /* Measures the amount of time to process the second half */
bmazzeo 9:f5b37c71856d 178 second_half_time = timer.read_us();
bmazzeo 9:f5b37c71856d 179
bmazzeo 13:61131aac4031 180 /* End Second Half */
adustm 0:da04816fb411 181 }
adustm 0:da04816fb411 182 }
Jerome Coutant 5:66c230f74325 183
bmazzeo 7:e1dfd64eba81 184 /**
bmazzeo 7:e1dfd64eba81 185 * @brief Draws a trace of the data line.
bmazzeo 7:e1dfd64eba81 186 * @param Xpos: X position
bmazzeo 7:e1dfd64eba81 187 * @param L_Ypos: Left channel Y position
bmazzeo 7:e1dfd64eba81 188 * @param R_Ypos: Right channel Y position
bmazzeo 7:e1dfd64eba81 189 * @param Mem_start: Start of memory location
bmazzeo 7:e1dfd64eba81 190 * @param Length: length of trace
bmazzeo 7:e1dfd64eba81 191 * @retval None
bmazzeo 7:e1dfd64eba81 192 */
bmazzeo 17:eb85a2387dd4 193 void Erase_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bmazzeo 7:e1dfd64eba81 194 {
bmazzeo 22:f36d7a53bb7e 195 /* Creates a brown rectangle above and below the axis */
bmazzeo 7:e1dfd64eba81 196 BSP_LCD_SetTextColor(LCD_COLOR_BROWN);
bmazzeo 17:eb85a2387dd4 197 BSP_LCD_FillRect(Xpos, Ypos - AUDIO_DRAW_LIMIT, Length, AUDIO_DRAW_LIMIT);
bmazzeo 17:eb85a2387dd4 198 BSP_LCD_FillRect(Xpos, Ypos+1, Length, AUDIO_DRAW_LIMIT);
bmazzeo 7:e1dfd64eba81 199
bmazzeo 22:f36d7a53bb7e 200 /* Draw axis for plotting */
bmazzeo 17:eb85a2387dd4 201 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
bmazzeo 17:eb85a2387dd4 202 BSP_LCD_DrawHLine(Xpos, Ypos, Length);
bmazzeo 7:e1dfd64eba81 203
bmazzeo 7:e1dfd64eba81 204 }
bmazzeo 7:e1dfd64eba81 205
Jerome Coutant 5:66c230f74325 206
bmazzeo 6:e689075b04ed 207 /**
bmazzeo 6:e689075b04ed 208 * @brief Draws a trace of the data line.
bmazzeo 6:e689075b04ed 209 * @param Xpos: X position
bmazzeo 7:e1dfd64eba81 210 * @param L_Ypos: Left channel Y position
bmazzeo 7:e1dfd64eba81 211 * @param R_Ypos: Right channel Y position
bmazzeo 6:e689075b04ed 212 * @param Mem_start: Start of memory location
bmazzeo 6:e689075b04ed 213 * @param Length: length of trace
bmazzeo 6:e689075b04ed 214 * @retval None
bmazzeo 6:e689075b04ed 215 */
bmazzeo 17:eb85a2387dd4 216 void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t* Mem_start, uint16_t Length)
bmazzeo 6:e689075b04ed 217 {
bmazzeo 7:e1dfd64eba81 218 uint16_t i;
bmazzeo 18:255d15af49f2 219 uint16_t* mem_address;
bmazzeo 7:e1dfd64eba81 220 char buf[10];
bmazzeo 7:e1dfd64eba81 221 int16_t L_audio_value;
bmazzeo 7:e1dfd64eba81 222 int16_t R_audio_value;
bmazzeo 20:2ecdf687a2d1 223
bmazzeo 18:255d15af49f2 224 mem_address = Mem_start;
bmazzeo 7:e1dfd64eba81 225
bmazzeo 8:d1c41eca57f0 226 for (i=0; i<Length; i++)
bmazzeo 20:2ecdf687a2d1 227 {
bmazzeo 18:255d15af49f2 228 L_audio_value = (int16_t) *mem_address;
bmazzeo 18:255d15af49f2 229 mem_address++;
bmazzeo 18:255d15af49f2 230 R_audio_value = (int16_t) *mem_address;
bmazzeo 18:255d15af49f2 231 mem_address++;
bmazzeo 7:e1dfd64eba81 232
bmazzeo 17:eb85a2387dd4 233 L_audio_value = L_audio_value / 100;
bmazzeo 17:eb85a2387dd4 234 R_audio_value = R_audio_value / 100;
bmazzeo 7:e1dfd64eba81 235
bmazzeo 7:e1dfd64eba81 236 if (L_audio_value > AUDIO_DRAW_LIMIT) {L_audio_value = AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 237 else if (L_audio_value < -AUDIO_DRAW_LIMIT) {L_audio_value = -AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 238
bmazzeo 7:e1dfd64eba81 239 if (R_audio_value > AUDIO_DRAW_LIMIT) {R_audio_value = AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 240 else if (R_audio_value < -AUDIO_DRAW_LIMIT) {R_audio_value = -AUDIO_DRAW_LIMIT;}
bmazzeo 7:e1dfd64eba81 241
bmazzeo 17:eb85a2387dd4 242 BSP_LCD_DrawPixel(Xpos + i, (uint16_t) ((int16_t) Ypos + L_audio_value), LCD_COLOR_BLUE);
bmazzeo 17:eb85a2387dd4 243 BSP_LCD_DrawPixel(Xpos + i, (uint16_t) ((int16_t) Ypos + R_audio_value), LCD_COLOR_GREEN);
bmazzeo 6:e689075b04ed 244 }
bmazzeo 6:e689075b04ed 245
bmazzeo 6:e689075b04ed 246 }
bmazzeo 14:18f159d48340 247
bmazzeo 14:18f159d48340 248 /**
bmazzeo 14:18f159d48340 249 * @brief Converts audio data in buffer to floating point representation.
bmazzeo 14:18f159d48340 250 * @param buffer_in: Pointer to Audio buffer start location
bmazzeo 14:18f159d48340 251 * @param L_out: Pointer to Left channel out data (float)
bmazzeo 14:18f159d48340 252 * @param R_out: Pointer to Right channel out data (float)
bmazzeo 14:18f159d48340 253 * @param Length: length of data to convert
bmazzeo 14:18f159d48340 254 * @retval None
bmazzeo 14:18f159d48340 255 */
bmazzeo 16:b7dca59ab076 256 void Audio_to_Float(uint16_t* buffer_in, float* L_out, float* R_out, uint16_t Length)
bmazzeo 14:18f159d48340 257 {
bmazzeo 14:18f159d48340 258 uint16_t i;
bmazzeo 16:b7dca59ab076 259 uint16_t* audio_mem_address;
bmazzeo 20:2ecdf687a2d1 260 float* L_chan_mem_address;
bmazzeo 20:2ecdf687a2d1 261 float* R_chan_mem_address;
bmazzeo 14:18f159d48340 262 float L_audio_value;
bmazzeo 14:18f159d48340 263 float R_audio_value;
bmazzeo 20:2ecdf687a2d1 264
bmazzeo 20:2ecdf687a2d1 265 audio_mem_address = buffer_in;
bmazzeo 20:2ecdf687a2d1 266 L_chan_mem_address = L_out;
bmazzeo 20:2ecdf687a2d1 267 R_chan_mem_address = R_out;
bmazzeo 6:e689075b04ed 268
bmazzeo 14:18f159d48340 269 for (i=0; i<Length; i++)
bmazzeo 14:18f159d48340 270 {
bmazzeo 20:2ecdf687a2d1 271 L_audio_value = (float) ((int16_t) *audio_mem_address);
bmazzeo 20:2ecdf687a2d1 272 audio_mem_address++;
bmazzeo 20:2ecdf687a2d1 273 R_audio_value = (float) ((int16_t) *audio_mem_address);
bmazzeo 20:2ecdf687a2d1 274 audio_mem_address++;
bmazzeo 14:18f159d48340 275
bmazzeo 16:b7dca59ab076 276 *L_chan_mem_address = L_audio_value;
bmazzeo 20:2ecdf687a2d1 277 L_chan_mem_address++;
bmazzeo 20:2ecdf687a2d1 278
bmazzeo 14:18f159d48340 279 *R_chan_mem_address = R_audio_value;
bmazzeo 20:2ecdf687a2d1 280 R_chan_mem_address++;
bmazzeo 14:18f159d48340 281 }
bmazzeo 14:18f159d48340 282 }
bmazzeo 14:18f159d48340 283
bmazzeo 14:18f159d48340 284 /**
bmazzeo 14:18f159d48340 285 * @brief Converts audio data in buffer to floating point representation.
bmazzeo 14:18f159d48340 286 * @param L_out: Pointer to Left channel in data (float)
bmazzeo 14:18f159d48340 287 * @param R_out: Pointer to Right channel in data (float)
bmazzeo 14:18f159d48340 288 * @param buffer_out: Pointer to combined 32 bit (two 16-bit int samples)
bmazzeo 14:18f159d48340 289 * @param Length: length of data to convert
bmazzeo 14:18f159d48340 290 * @retval None
bmazzeo 14:18f159d48340 291 */
bmazzeo 16:b7dca59ab076 292 void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length)
bmazzeo 14:18f159d48340 293 {
bmazzeo 14:18f159d48340 294 uint16_t i;
bmazzeo 14:18f159d48340 295 uint16_t* audio_mem_address;
bmazzeo 21:4dbfda694c0d 296 float* L_chan_mem_address;
bmazzeo 21:4dbfda694c0d 297 float* R_chan_mem_address;
bmazzeo 21:4dbfda694c0d 298 int16_t L_audio_value;
bmazzeo 21:4dbfda694c0d 299 int16_t R_audio_value;
bmazzeo 21:4dbfda694c0d 300
bmazzeo 21:4dbfda694c0d 301 audio_mem_address = buffer_out;
bmazzeo 21:4dbfda694c0d 302 L_chan_mem_address = L_in;
bmazzeo 21:4dbfda694c0d 303 R_chan_mem_address = R_in;
bmazzeo 14:18f159d48340 304
bmazzeo 14:18f159d48340 305 for (i=0; i<Length; i++)
bmazzeo 14:18f159d48340 306 {
bmazzeo 21:4dbfda694c0d 307 L_audio_value = (int16_t) ((float) *L_chan_mem_address);
bmazzeo 21:4dbfda694c0d 308 L_chan_mem_address++;
bmazzeo 14:18f159d48340 309
bmazzeo 21:4dbfda694c0d 310 R_audio_value = (int16_t) ((float) *R_chan_mem_address);
bmazzeo 21:4dbfda694c0d 311 R_chan_mem_address++;
bmazzeo 21:4dbfda694c0d 312
bmazzeo 21:4dbfda694c0d 313 *audio_mem_address = (uint16_t) L_audio_value;
bmazzeo 21:4dbfda694c0d 314 audio_mem_address++;
bmazzeo 21:4dbfda694c0d 315 *audio_mem_address = (uint16_t) R_audio_value;
bmazzeo 21:4dbfda694c0d 316 audio_mem_address++;
bmazzeo 14:18f159d48340 317 }
bmazzeo 14:18f159d48340 318 }
bmazzeo 14:18f159d48340 319
bmazzeo 14:18f159d48340 320
bmazzeo 14:18f159d48340 321
bmazzeo 6:e689075b04ed 322
bmazzeo 6:e689075b04ed 323
adustm 0:da04816fb411 324 /*-------------------------------------------------------------------------------------
adustm 0:da04816fb411 325 Callbacks implementation:
adustm 0:da04816fb411 326 the callbacks API are defined __weak in the stm32746g_discovery_audio.c file
adustm 0:da04816fb411 327 and their implementation should be done in the user code if they are needed.
adustm 0:da04816fb411 328 Below some examples of callback implementations.
adustm 0:da04816fb411 329 -------------------------------------------------------------------------------------*/
adustm 0:da04816fb411 330 /**
adustm 0:da04816fb411 331 * @brief Manages the DMA Transfer complete interrupt.
adustm 0:da04816fb411 332 * @param None
adustm 0:da04816fb411 333 * @retval None
adustm 0:da04816fb411 334 */
adustm 0:da04816fb411 335 void BSP_AUDIO_IN_TransferComplete_CallBack(void)
adustm 0:da04816fb411 336 {
Jerome Coutant 5:66c230f74325 337 audio_rec_buffer_state = BUFFER_OFFSET_FULL;
adustm 0:da04816fb411 338 }
adustm 0:da04816fb411 339
adustm 0:da04816fb411 340 /**
adustm 0:da04816fb411 341 * @brief Manages the DMA Half Transfer complete interrupt.
adustm 0:da04816fb411 342 * @param None
adustm 0:da04816fb411 343 * @retval None
adustm 0:da04816fb411 344 */
adustm 0:da04816fb411 345 void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
adustm 0:da04816fb411 346 {
Jerome Coutant 5:66c230f74325 347 audio_rec_buffer_state = BUFFER_OFFSET_HALF;
adustm 0:da04816fb411 348 }
adustm 0:da04816fb411 349
Jerome Coutant 5:66c230f74325 350 /**
Jerome Coutant 5:66c230f74325 351 * @brief Audio IN Error callback function.
Jerome Coutant 5:66c230f74325 352 * @param None
Jerome Coutant 5:66c230f74325 353 * @retval None
Jerome Coutant 5:66c230f74325 354 */
Jerome Coutant 5:66c230f74325 355 void BSP_AUDIO_IN_Error_CallBack(void)
adustm 0:da04816fb411 356 {
Jerome Coutant 5:66c230f74325 357 printf("BSP_AUDIO_IN_Error_CallBack\n");
adustm 0:da04816fb411 358 }