
lab 1 code
Dependencies: CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG
main.cpp@34:5bf89ab5e247, 2020-01-28 (annotated)
- Committer:
- justenmg
- Date:
- Tue Jan 28 22:23:00 2020 +0000
- Revision:
- 34:5bf89ab5e247
- Parent:
- 33:a0dab92ea1b9
Initial commit
Who changed what in which revision?
User | Revision | Line number | New 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 | |
bmazzeo | 30:debea332cdfe | 24 | /* The following type definitions are used to control the |
bmazzeo | 30:debea332cdfe | 25 | * buffering of the audio data using a double buffering technique. |
bmazzeo | 30:debea332cdfe | 26 | * Most of the transactions between the WM8994 and the microcontroller |
bmazzeo | 30:debea332cdfe | 27 | * are handled by other code - but this signals what the buffering state |
bmazzeo | 30:debea332cdfe | 28 | * is, so the data can be appropriately processed. */ |
Jerome Coutant
5:66c230f74325
|
29
|
typedef enum {
|
|
adustm | 0:da04816fb411 | 30 | BUFFER_OFFSET_NONE = 0, |
adustm | 0:da04816fb411 | 31 | BUFFER_OFFSET_HALF = 1, |
adustm | 0:da04816fb411 | 32 | BUFFER_OFFSET_FULL = 2, |
Jerome Coutant
5:66c230f74325
|
33
|
} BUFFER_StateTypeDef;
|
|
Jerome Coutant
5:66c230f74325
|
34
|
|
|
justenmg | 34:5bf89ab5e247 | 35 | /* Scale factor */ |
justenmg | 34:5bf89ab5e247 | 36 | #define SCALE_FACTOR ((uint16_t)100) // Scale factor for dividing R L |
justenmg | 34:5bf89ab5e247 | 37 | |
bmazzeo | 30:debea332cdfe | 38 | /* These audio block samples define the size of the buffering */ |
justenmg | 34:5bf89ab5e247 | 39 | #define AUDIO_SAMPLE_LENGTH ((uint16_t)16) // Bits per sample |
bmazzeo | 19:479f611941a8 | 40 | #define AUDIO_BLOCK_SAMPLES ((uint32_t)128) // Number of samples (L and R) in audio block (each samples is 16 bits) |
bmazzeo | 19:479f611941a8 | 41 | #define AUDIO_BLOCK_SIZE ((uint32_t)512) // Number of bytes in audio block (4 * AUDIO_BLOCK_SAMPLES) |
bmazzeo | 6:e689075b04ed | 42 | |
bmazzeo | 30:debea332cdfe | 43 | /* These RAM addresses are important to determine where the audio data is stored. */ |
bmazzeo | 9:f5b37c71856d | 44 | #define SDRAM_DEVICE_ADDR_AUDIO_MEM ((uint32_t)0xC0400000) |
bmazzeo | 9:f5b37c71856d | 45 | #define AUDIO_BUFFER_IN SDRAM_DEVICE_ADDR_AUDIO_MEM |
bmazzeo | 9:f5b37c71856d | 46 | #define AUDIO_BUFFER_OUT (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE * 2)) |
Jerome Coutant
5:66c230f74325
|
47
|
|
|
bmazzeo | 30:debea332cdfe | 48 | /* These definitions define the size of the oscilloscope that is used to display data. */ |
bmazzeo | 8:d1c41eca57f0 | 49 | #define OSC_START_X_POS 20 |
bmazzeo | 6:e689075b04ed | 50 | #define OSC_LINE_SIZE 256 |
justenmg | 34:5bf89ab5e247 | 51 | #define OSC_Y_POS 150 |
bmazzeo | 31:5a0235b66851 | 52 | #define AUDIO_DRAW_LIMIT 50 |
bmazzeo | 6:e689075b04ed | 53 | |
bmazzeo | 30:debea332cdfe | 54 | /* This define a timer that is then used to record the timing of the different processing stages. */ |
bmazzeo | 9:f5b37c71856d | 55 | Timer timer; |
bmazzeo | 9:f5b37c71856d | 56 | |
bmazzeo | 30:debea332cdfe | 57 | /* This variable is important because it define the audio buffer recording state. */ |
Jerome Coutant
5:66c230f74325
|
58
|
volatile uint32_t audio_rec_buffer_state = BUFFER_OFFSET_NONE;
|
|
bmazzeo | 30:debea332cdfe | 59 | |
bmazzeo | 30:debea332cdfe | 60 | /* Function declarations */ |
bmazzeo | 17:eb85a2387dd4 | 61 | static void Erase_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t Length); |
bmazzeo | 17:eb85a2387dd4 | 62 | static void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t* Mem_start, uint16_t Length); |
bmazzeo | 16:b7dca59ab076 | 63 | static void Audio_to_Float(uint16_t* buffer_in, float* L_out, float* R_out, uint16_t Length); |
bmazzeo | 16:b7dca59ab076 | 64 | static void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length); |
Jerome Coutant
5:66c230f74325
|
65
|
|
|
bmazzeo | 30:debea332cdfe | 66 | /* These memory blocks are important for converting to floating point representation. */ |
bmazzeo | 19:479f611941a8 | 67 | float L_channel_float[AUDIO_BLOCK_SAMPLES]; |
bmazzeo | 19:479f611941a8 | 68 | float R_channel_float[AUDIO_BLOCK_SAMPLES]; |
bmazzeo | 20:2ecdf687a2d1 | 69 | float *L_channel_float_p = &L_channel_float[0]; |
bmazzeo | 20:2ecdf687a2d1 | 70 | float *R_channel_float_p = &R_channel_float[0]; |
bmazzeo | 14:18f159d48340 | 71 | |
bmazzeo | 30:debea332cdfe | 72 | /* These memory blocks are where the information is stored to send back out to the WM8994 chip. */ |
bmazzeo | 22:f36d7a53bb7e | 73 | uint16_t Processed_audio[AUDIO_BLOCK_SAMPLES]; |
bmazzeo | 20:2ecdf687a2d1 | 74 | uint16_t *Processed_audio_p = &Processed_audio[0]; |
bmazzeo | 14:18f159d48340 | 75 | |
bmazzeo | 14:18f159d48340 | 76 | /* Useful variables during looping */ |
bmazzeo | 30:debea332cdfe | 77 | uint32_t counter = 0; // Loop counter |
bmazzeo | 30:debea332cdfe | 78 | char buf[40]; // Character buffer for sprintf statements to the LCD |
bmazzeo | 30:debea332cdfe | 79 | int first_half_time = 0; // Time of first processing block |
bmazzeo | 30:debea332cdfe | 80 | int second_half_time = 0; // Time of second processing block |
bmazzeo | 30:debea332cdfe | 81 | int total_time = 0; // Time of total loop (first and second blocks) |
bmazzeo | 9:f5b37c71856d | 82 | |
bmazzeo | 30:debea332cdfe | 83 | /* Main Function */ |
adustm | 0:da04816fb411 | 84 | int main() |
adustm | 0:da04816fb411 | 85 | { |
bmazzeo | 13:61131aac4031 | 86 | /* Initialize the LCD Screen and display information */ |
bmazzeo | 6:e689075b04ed | 87 | BSP_LCD_Init(); |
bmazzeo | 6:e689075b04ed | 88 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); |
bmazzeo | 6:e689075b04ed | 89 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); |
bmazzeo | 6:e689075b04ed | 90 | |
bmazzeo | 30:debea332cdfe | 91 | /* Clear the LCD and set the font to be default */ |
bmazzeo | 6:e689075b04ed | 92 | BSP_LCD_Clear(LCD_COLOR_BLACK); |
bmazzeo | 6:e689075b04ed | 93 | BSP_LCD_SetFont(&LCD_DEFAULT_FONT); |
bmazzeo | 30:debea332cdfe | 94 | |
bmazzeo | 30:debea332cdfe | 95 | /* Set the backcolor to be black and the textcolor to be orange. */ |
bmazzeo | 6:e689075b04ed | 96 | BSP_LCD_SetBackColor(LCD_COLOR_BLACK); |
bmazzeo | 6:e689075b04ed | 97 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
bmazzeo | 30:debea332cdfe | 98 | |
bmazzeo | 30:debea332cdfe | 99 | /* The following are static display elements that will remain on the screen. */ |
bmazzeo | 31:5a0235b66851 | 100 | BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"487 Lab 1 (student)", LEFT_MODE); |
bmazzeo | 30:debea332cdfe | 101 | |
bmazzeo | 30:debea332cdfe | 102 | /* Display the L and R colors for the channels */ |
bmazzeo | 17:eb85a2387dd4 | 103 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
bmazzeo | 17:eb85a2387dd4 | 104 | BSP_LCD_DisplayStringAt(0, OSC_Y_POS - 20, (uint8_t *)"L", LEFT_MODE); |
bmazzeo | 17:eb85a2387dd4 | 105 | BSP_LCD_SetTextColor(LCD_COLOR_GREEN); |
bmazzeo | 17:eb85a2387dd4 | 106 | BSP_LCD_DisplayStringAt(0, OSC_Y_POS, (uint8_t *)"R", LEFT_MODE); |
justenmg | 34:5bf89ab5e247 | 107 | |
justenmg | 34:5bf89ab5e247 | 108 | // Draw rectangle and center line for O-scope background |
justenmg | 34:5bf89ab5e247 | 109 | BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); |
justenmg | 34:5bf89ab5e247 | 110 | BSP_LCD_DrawRect(OSC_START_X_POS - 1, OSC_Y_POS - AUDIO_DRAW_LIMIT - 1, OSC_LINE_SIZE + 2, AUDIO_DRAW_LIMIT*2 + 2); |
justenmg | 34:5bf89ab5e247 | 111 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
justenmg | 34:5bf89ab5e247 | 112 | BSP_LCD_DrawLine(OSC_START_X_POS, OSC_Y_POS, OSC_START_X_POS + OSC_LINE_SIZE, OSC_Y_POS); |
justenmg | 34:5bf89ab5e247 | 113 | |
bmazzeo | 6:e689075b04ed | 114 | |
bmazzeo | 30:debea332cdfe | 115 | /* The following code should not be code that you need to worry about - it sets up the audio interfaces. */ |
bmazzeo | 30:debea332cdfe | 116 | /* Initialize the Audio Interface */ |
bmazzeo | 30:debea332cdfe | 117 | 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); |
bmazzeo | 30:debea332cdfe | 118 | |
bmazzeo | 30:debea332cdfe | 119 | /* Initialize SDRAM buffers */ |
bmazzeo | 30:debea332cdfe | 120 | BSP_SDRAM_Init(); |
bmazzeo | 30:debea332cdfe | 121 | memset((uint16_t *)AUDIO_BUFFER_IN, 0, AUDIO_BLOCK_SIZE * 2); |
bmazzeo | 30:debea332cdfe | 122 | memset((uint16_t *)AUDIO_BUFFER_OUT, 0, AUDIO_BLOCK_SIZE * 2); |
bmazzeo | 30:debea332cdfe | 123 | |
bmazzeo | 30:debea332cdfe | 124 | /* Start Recording */ |
bmazzeo | 30:debea332cdfe | 125 | if (BSP_AUDIO_IN_Record((uint16_t *)AUDIO_BUFFER_IN, AUDIO_BLOCK_SIZE) != AUDIO_OK) { printf("BSP_AUDIO_IN_Record error\n"); } |
bmazzeo | 30:debea332cdfe | 126 | |
bmazzeo | 30:debea332cdfe | 127 | /* Start Playback */ |
bmazzeo | 30:debea332cdfe | 128 | BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02); |
bmazzeo | 30:debea332cdfe | 129 | if (BSP_AUDIO_OUT_Play((uint16_t *)AUDIO_BUFFER_OUT, AUDIO_BLOCK_SIZE * 2) != AUDIO_OK) { printf("BSP_AUDIO_OUT_Play error\n"); } |
bmazzeo | 30:debea332cdfe | 130 | |
bmazzeo | 30:debea332cdfe | 131 | /* The audio interfaces are all now working. |
bmazzeo | 30:debea332cdfe | 132 | * Importantly - AUDIO_BUFFER_IN is the pointer to the incoming data from the WM8994 |
bmazzeo | 30:debea332cdfe | 133 | * AUDIO_BUFFER_OUT is the pointer to the outgoing data to the WM8994 */ |
Jerome Coutant
5:66c230f74325
|
134
|
|
|
adustm | 0:da04816fb411 | 135 | |
bmazzeo | 30:debea332cdfe | 136 | /* Initialize signal processing filters - usually there are variables that |
bmazzeo | 30:debea332cdfe | 137 | * need to be set up or that there are arrays you need to precompute - this |
bmazzeo | 30:debea332cdfe | 138 | * function call allows you to do that. */ |
bmazzeo | 25:5412779376a7 | 139 | initalize_signal_processing(); |
adustm | 0:da04816fb411 | 140 | |
bmazzeo | 30:debea332cdfe | 141 | /* Hardware timer starts. Set to zero */ |
bmazzeo | 9:f5b37c71856d | 142 | timer.start(); |
bmazzeo | 30:debea332cdfe | 143 | |
bmazzeo | 30:debea332cdfe | 144 | /* Main signal processing while loop */ |
adustm | 0:da04816fb411 | 145 | while (1) { |
bmazzeo | 30:debea332cdfe | 146 | |
bmazzeo | 6:e689075b04ed | 147 | /* First Half */ |
bmazzeo | 30:debea332cdfe | 148 | /* Wait until end of half block recording before going on in the first half cycle*/ |
bmazzeo | 11:4256dbbb0c89 | 149 | while (audio_rec_buffer_state != BUFFER_OFFSET_HALF) {} |
bmazzeo | 9:f5b37c71856d | 150 | |
bmazzeo | 13:61131aac4031 | 151 | /* This captures the time of an entire cycle */ |
bmazzeo | 9:f5b37c71856d | 152 | total_time = timer.read_us(); |
bmazzeo | 13:61131aac4031 | 153 | |
bmazzeo | 13:61131aac4031 | 154 | /* Reset the timer counter to zero */ |
bmazzeo | 9:f5b37c71856d | 155 | timer.reset(); |
Jerome Coutant
5:66c230f74325
|
156
|
|
|
bmazzeo | 13:61131aac4031 | 157 | /* Plot traces of first half block recording */ |
bmazzeo | 19:479f611941a8 | 158 | Erase_Trace(OSC_START_X_POS, OSC_Y_POS, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 19:479f611941a8 | 159 | Draw_Trace(OSC_START_X_POS, OSC_Y_POS, (uint16_t *) AUDIO_BUFFER_IN, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 18:255d15af49f2 | 160 | |
bmazzeo | 14:18f159d48340 | 161 | /* Convert data to floating point representation for processing */ |
bmazzeo | 20:2ecdf687a2d1 | 162 | Audio_to_Float((uint16_t *) AUDIO_BUFFER_IN, L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 22:f36d7a53bb7e | 163 | |
bmazzeo | 30:debea332cdfe | 164 | /* ------------------------------------------------------------------------ */ |
bmazzeo | 30:debea332cdfe | 165 | /* Here is where signal processing can be done on the floating point arrays */ |
bmazzeo | 22:f36d7a53bb7e | 166 | |
bmazzeo | 30:debea332cdfe | 167 | process_audio_channel_signals(L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 20:2ecdf687a2d1 | 168 | |
bmazzeo | 30:debea332cdfe | 169 | /* Here is where signal processing can end on the floating point arrays */ |
bmazzeo | 30:debea332cdfe | 170 | /* -------------------------------------------------------------------- */ |
bmazzeo | 20:2ecdf687a2d1 | 171 | |
bmazzeo | 22:f36d7a53bb7e | 172 | /* Covert floating point data back to fixed point audio format */ |
bmazzeo | 21:4dbfda694c0d | 173 | Float_to_Audio(L_channel_float_p, R_channel_float_p, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 14:18f159d48340 | 174 | |
bmazzeo | 13:61131aac4031 | 175 | /* Copy recorded 1st half block into the audio buffer that goes out */ |
bmazzeo | 31:5a0235b66851 | 176 | /* Replace the second memcpy with this first one once you have worked out the processed audio functions. */ |
justenmg | 34:5bf89ab5e247 | 177 | memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(Processed_audio), AUDIO_BLOCK_SIZE); |
justenmg | 34:5bf89ab5e247 | 178 | //memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(AUDIO_BUFFER_IN), AUDIO_BLOCK_SIZE); |
bmazzeo | 13:61131aac4031 | 179 | |
bmazzeo | 26:023edf8cea6c | 180 | /* Display useful cycle information (split up information display so the processing is more balanced) */ |
bmazzeo | 26:023edf8cea6c | 181 | sprintf(buf, "Cycles: %9d", counter); |
bmazzeo | 26:023edf8cea6c | 182 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
bmazzeo | 26:023edf8cea6c | 183 | BSP_LCD_DisplayStringAt(0, 46, (uint8_t *) buf, LEFT_MODE); |
bmazzeo | 26:023edf8cea6c | 184 | |
bmazzeo | 26:023edf8cea6c | 185 | |
bmazzeo | 13:61131aac4031 | 186 | /* Capture the timing of the first half processing */ |
bmazzeo | 9:f5b37c71856d | 187 | first_half_time = timer.read_us(); |
bmazzeo | 13:61131aac4031 | 188 | /* End First Half */ |
bmazzeo | 8:d1c41eca57f0 | 189 | |
bmazzeo | 6:e689075b04ed | 190 | /* Second Half */ |
adustm | 0:da04816fb411 | 191 | /* Wait end of one block recording */ |
bmazzeo | 11:4256dbbb0c89 | 192 | while (audio_rec_buffer_state != BUFFER_OFFSET_FULL) {} |
bmazzeo | 9:f5b37c71856d | 193 | |
bmazzeo | 13:61131aac4031 | 194 | /* Plot traces of second half block recording */ |
bmazzeo | 19:479f611941a8 | 195 | Erase_Trace(OSC_START_X_POS+AUDIO_BLOCK_SAMPLES, OSC_Y_POS, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 19:479f611941a8 | 196 | 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 | 197 | |
bmazzeo | 22:f36d7a53bb7e | 198 | /* Convert data to floating point representation for processing */ |
bmazzeo | 22:f36d7a53bb7e | 199 | 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 | 200 | |
bmazzeo | 30:debea332cdfe | 201 | /* ------------------------------------------------------------------------ */ |
bmazzeo | 30:debea332cdfe | 202 | /* Here is where signal processing can be done on the floating point arrays */ |
bmazzeo | 22:f36d7a53bb7e | 203 | |
bmazzeo | 30:debea332cdfe | 204 | process_audio_channel_signals(L_channel_float_p, R_channel_float_p, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 22:f36d7a53bb7e | 205 | |
bmazzeo | 30:debea332cdfe | 206 | /* Here is where signal processing can end on the floating point arrays */ |
bmazzeo | 30:debea332cdfe | 207 | /* -------------------------------------------------------------------- */ |
bmazzeo | 30:debea332cdfe | 208 | |
bmazzeo | 22:f36d7a53bb7e | 209 | /* Covert floating point data back to fixed point audio format */ |
bmazzeo | 22:f36d7a53bb7e | 210 | Float_to_Audio(L_channel_float_p, R_channel_float_p, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES); |
bmazzeo | 22:f36d7a53bb7e | 211 | |
bmazzeo | 22:f36d7a53bb7e | 212 | /* Copy recorded 2nd half block into the audio buffer that goes out */ |
justenmg | 34:5bf89ab5e247 | 213 | memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *) (Processed_audio), AUDIO_BLOCK_SIZE); |
justenmg | 34:5bf89ab5e247 | 214 | //memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE); |
bmazzeo | 31:5a0235b66851 | 215 | |
bmazzeo | 13:61131aac4031 | 216 | |
bmazzeo | 13:61131aac4031 | 217 | /* Compute important cycle information and display it*/ |
bmazzeo | 26:023edf8cea6c | 218 | sprintf(buf, "1:%6d 2:%6d T:%6d", first_half_time, second_half_time, total_time); |
bmazzeo | 6:e689075b04ed | 219 | BSP_LCD_SetTextColor(LCD_COLOR_RED); |
bmazzeo | 10:a82b64ea1d11 | 220 | BSP_LCD_DisplayStringAt(0, 20, (uint8_t *) buf, LEFT_MODE); |
bmazzeo | 13:61131aac4031 | 221 | |
bmazzeo | 13:61131aac4031 | 222 | /* Copy recorded 2nd half block into audio output buffer */ |
bmazzeo | 18:255d15af49f2 | 223 | |
bmazzeo | 13:61131aac4031 | 224 | /* Change the recording buffer state to reflect the status of the buffer */ |
bmazzeo | 13:61131aac4031 | 225 | audio_rec_buffer_state = BUFFER_OFFSET_NONE; |
bmazzeo | 26:023edf8cea6c | 226 | |
bmazzeo | 26:023edf8cea6c | 227 | /* Increase the counter */ |
bmazzeo | 26:023edf8cea6c | 228 | counter++; |
bmazzeo | 9:f5b37c71856d | 229 | |
bmazzeo | 13:61131aac4031 | 230 | /* Measures the amount of time to process the second half */ |
bmazzeo | 9:f5b37c71856d | 231 | second_half_time = timer.read_us(); |
bmazzeo | 9:f5b37c71856d | 232 | |
bmazzeo | 13:61131aac4031 | 233 | /* End Second Half */ |
adustm | 0:da04816fb411 | 234 | } |
adustm | 0:da04816fb411 | 235 | } |
Jerome Coutant
5:66c230f74325
|
236
|
|
|
bmazzeo | 7:e1dfd64eba81 | 237 | /** |
bmazzeo | 7:e1dfd64eba81 | 238 | * @brief Draws a trace of the data line. |
bmazzeo | 7:e1dfd64eba81 | 239 | * @param Xpos: X position |
bmazzeo | 33:a0dab92ea1b9 | 240 | * @param Ypos: Y position |
bmazzeo | 7:e1dfd64eba81 | 241 | * @param Mem_start: Start of memory location |
bmazzeo | 7:e1dfd64eba81 | 242 | * @param Length: length of trace |
bmazzeo | 7:e1dfd64eba81 | 243 | * @retval None |
bmazzeo | 7:e1dfd64eba81 | 244 | */ |
bmazzeo | 17:eb85a2387dd4 | 245 | void Erase_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t Length) |
bmazzeo | 7:e1dfd64eba81 | 246 | { |
justenmg | 34:5bf89ab5e247 | 247 | BSP_LCD_SetTextColor(LCD_COLOR_BLACK); |
justenmg | 34:5bf89ab5e247 | 248 | BSP_LCD_FillRect(Xpos, Ypos - AUDIO_DRAW_LIMIT, OSC_LINE_SIZE/2, AUDIO_DRAW_LIMIT); |
justenmg | 34:5bf89ab5e247 | 249 | BSP_LCD_FillRect(Xpos, Ypos+1, OSC_LINE_SIZE/2, AUDIO_DRAW_LIMIT); |
bmazzeo | 7:e1dfd64eba81 | 250 | } |
bmazzeo | 7:e1dfd64eba81 | 251 | |
Jerome Coutant
5:66c230f74325
|
252
|
|
|
bmazzeo | 6:e689075b04ed | 253 | /** |
bmazzeo | 6:e689075b04ed | 254 | * @brief Draws a trace of the data line. |
bmazzeo | 6:e689075b04ed | 255 | * @param Xpos: X position |
bmazzeo | 33:a0dab92ea1b9 | 256 | * @param Ypos: Y position |
bmazzeo | 6:e689075b04ed | 257 | * @param Mem_start: Start of memory location |
bmazzeo | 6:e689075b04ed | 258 | * @param Length: length of trace |
bmazzeo | 6:e689075b04ed | 259 | * @retval None |
bmazzeo | 6:e689075b04ed | 260 | */ |
bmazzeo | 17:eb85a2387dd4 | 261 | void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t* Mem_start, uint16_t Length) |
bmazzeo | 6:e689075b04ed | 262 | { |
justenmg | 34:5bf89ab5e247 | 263 | int16_t R; |
justenmg | 34:5bf89ab5e247 | 264 | int16_t L; |
justenmg | 34:5bf89ab5e247 | 265 | int16_t R_scaled; |
justenmg | 34:5bf89ab5e247 | 266 | int16_t L_scaled; |
justenmg | 34:5bf89ab5e247 | 267 | |
justenmg | 34:5bf89ab5e247 | 268 | |
justenmg | 34:5bf89ab5e247 | 269 | for(uint16_t ii = 0; ii < Length; ii++) |
justenmg | 34:5bf89ab5e247 | 270 | { |
justenmg | 34:5bf89ab5e247 | 271 | R = *Mem_start; |
justenmg | 34:5bf89ab5e247 | 272 | Mem_start++; |
justenmg | 34:5bf89ab5e247 | 273 | L = *Mem_start; |
justenmg | 34:5bf89ab5e247 | 274 | Mem_start++; |
justenmg | 34:5bf89ab5e247 | 275 | |
justenmg | 34:5bf89ab5e247 | 276 | R_scaled = R/SCALE_FACTOR; |
justenmg | 34:5bf89ab5e247 | 277 | L_scaled = L/SCALE_FACTOR; |
justenmg | 34:5bf89ab5e247 | 278 | if(L_scaled != 0 && L_scaled < AUDIO_DRAW_LIMIT && L_scaled > -AUDIO_DRAW_LIMIT) |
justenmg | 34:5bf89ab5e247 | 279 | { |
justenmg | 34:5bf89ab5e247 | 280 | BSP_LCD_DrawPixel(ii + Xpos, L_scaled + Ypos, LCD_COLOR_BLUE); |
justenmg | 34:5bf89ab5e247 | 281 | } |
justenmg | 34:5bf89ab5e247 | 282 | |
justenmg | 34:5bf89ab5e247 | 283 | if(R_scaled != 0 && R_scaled < AUDIO_DRAW_LIMIT && R_scaled > -AUDIO_DRAW_LIMIT) |
justenmg | 34:5bf89ab5e247 | 284 | { |
justenmg | 34:5bf89ab5e247 | 285 | BSP_LCD_DrawPixel(ii + Xpos, R_scaled + Ypos, LCD_COLOR_GREEN); |
justenmg | 34:5bf89ab5e247 | 286 | } |
justenmg | 34:5bf89ab5e247 | 287 | } |
bmazzeo | 6:e689075b04ed | 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 buffer_in: Pointer to Audio buffer start location |
bmazzeo | 14:18f159d48340 | 293 | * @param L_out: Pointer to Left channel out data (float) |
bmazzeo | 14:18f159d48340 | 294 | * @param R_out: Pointer to Right channel out data (float) |
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 Audio_to_Float(uint16_t* buffer_in, float* L_out, float* R_out, uint16_t Length) |
justenmg | 34:5bf89ab5e247 | 299 | { |
justenmg | 34:5bf89ab5e247 | 300 | int16_t R; |
justenmg | 34:5bf89ab5e247 | 301 | int16_t L; |
justenmg | 34:5bf89ab5e247 | 302 | |
justenmg | 34:5bf89ab5e247 | 303 | for(uint16_t ii = 0; ii < Length; ii++) |
justenmg | 34:5bf89ab5e247 | 304 | { |
justenmg | 34:5bf89ab5e247 | 305 | R = *buffer_in; |
justenmg | 34:5bf89ab5e247 | 306 | buffer_in++; |
justenmg | 34:5bf89ab5e247 | 307 | L = *buffer_in; |
justenmg | 34:5bf89ab5e247 | 308 | buffer_in++; |
justenmg | 34:5bf89ab5e247 | 309 | |
justenmg | 34:5bf89ab5e247 | 310 | *R_out = R; |
justenmg | 34:5bf89ab5e247 | 311 | R_out++; |
justenmg | 34:5bf89ab5e247 | 312 | *L_out = L; |
justenmg | 34:5bf89ab5e247 | 313 | L_out++; |
justenmg | 34:5bf89ab5e247 | 314 | } |
bmazzeo | 14:18f159d48340 | 315 | } |
bmazzeo | 14:18f159d48340 | 316 | |
bmazzeo | 14:18f159d48340 | 317 | /** |
bmazzeo | 14:18f159d48340 | 318 | * @brief Converts audio data in buffer to floating point representation. |
bmazzeo | 14:18f159d48340 | 319 | * @param L_out: Pointer to Left channel in data (float) |
bmazzeo | 14:18f159d48340 | 320 | * @param R_out: Pointer to Right channel in data (float) |
bmazzeo | 14:18f159d48340 | 321 | * @param buffer_out: Pointer to combined 32 bit (two 16-bit int samples) |
bmazzeo | 14:18f159d48340 | 322 | * @param Length: length of data to convert |
bmazzeo | 14:18f159d48340 | 323 | * @retval None |
bmazzeo | 14:18f159d48340 | 324 | */ |
bmazzeo | 16:b7dca59ab076 | 325 | void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length) |
bmazzeo | 14:18f159d48340 | 326 | { |
justenmg | 34:5bf89ab5e247 | 327 | int16_t R; |
justenmg | 34:5bf89ab5e247 | 328 | int16_t L; |
justenmg | 34:5bf89ab5e247 | 329 | |
justenmg | 34:5bf89ab5e247 | 330 | for(uint16_t ii = 0; ii < Length; ii++) |
justenmg | 34:5bf89ab5e247 | 331 | { |
justenmg | 34:5bf89ab5e247 | 332 | R = *R_in; |
justenmg | 34:5bf89ab5e247 | 333 | R_in++; |
justenmg | 34:5bf89ab5e247 | 334 | L = *L_in; |
justenmg | 34:5bf89ab5e247 | 335 | L_in++; |
justenmg | 34:5bf89ab5e247 | 336 | |
justenmg | 34:5bf89ab5e247 | 337 | *buffer_out = R; |
justenmg | 34:5bf89ab5e247 | 338 | buffer_out++; |
justenmg | 34:5bf89ab5e247 | 339 | *buffer_out = L; |
justenmg | 34:5bf89ab5e247 | 340 | buffer_out++; |
justenmg | 34:5bf89ab5e247 | 341 | } |
bmazzeo | 14:18f159d48340 | 342 | } |
bmazzeo | 14:18f159d48340 | 343 | |
bmazzeo | 14:18f159d48340 | 344 | |
bmazzeo | 14:18f159d48340 | 345 | |
bmazzeo | 6:e689075b04ed | 346 | |
bmazzeo | 6:e689075b04ed | 347 | |
adustm | 0:da04816fb411 | 348 | /*------------------------------------------------------------------------------------- |
adustm | 0:da04816fb411 | 349 | Callbacks implementation: |
adustm | 0:da04816fb411 | 350 | the callbacks API are defined __weak in the stm32746g_discovery_audio.c file |
adustm | 0:da04816fb411 | 351 | and their implementation should be done in the user code if they are needed. |
adustm | 0:da04816fb411 | 352 | Below some examples of callback implementations. |
adustm | 0:da04816fb411 | 353 | -------------------------------------------------------------------------------------*/ |
adustm | 0:da04816fb411 | 354 | /** |
adustm | 0:da04816fb411 | 355 | * @brief Manages the DMA Transfer complete interrupt. |
adustm | 0:da04816fb411 | 356 | * @param None |
adustm | 0:da04816fb411 | 357 | * @retval None |
adustm | 0:da04816fb411 | 358 | */ |
adustm | 0:da04816fb411 | 359 | void BSP_AUDIO_IN_TransferComplete_CallBack(void) |
adustm | 0:da04816fb411 | 360 | { |
Jerome Coutant
5:66c230f74325
|
361
|
audio_rec_buffer_state = BUFFER_OFFSET_FULL;
|
|
adustm | 0:da04816fb411 | 362 | } |
adustm | 0:da04816fb411 | 363 | |
adustm | 0:da04816fb411 | 364 | /** |
adustm | 0:da04816fb411 | 365 | * @brief Manages the DMA Half Transfer complete interrupt. |
adustm | 0:da04816fb411 | 366 | * @param None |
adustm | 0:da04816fb411 | 367 | * @retval None |
adustm | 0:da04816fb411 | 368 | */ |
adustm | 0:da04816fb411 | 369 | void BSP_AUDIO_IN_HalfTransfer_CallBack(void) |
adustm | 0:da04816fb411 | 370 | { |
Jerome Coutant
5:66c230f74325
|
371
|
audio_rec_buffer_state = BUFFER_OFFSET_HALF;
|
|
adustm | 0:da04816fb411 | 372 | } |
adustm | 0:da04816fb411 | 373 | |
Jerome Coutant
5:66c230f74325
|
374
|
/**
|
|
Jerome Coutant
5:66c230f74325
|
375
|
* @brief Audio IN Error callback function.
|
|
Jerome Coutant
5:66c230f74325
|
376
|
* @param None
|
|
Jerome Coutant
5:66c230f74325
|
377
|
* @retval None
|
|
Jerome Coutant
5:66c230f74325
|
378
|
*/
|
|
Jerome Coutant
5:66c230f74325
|
379
|
void BSP_AUDIO_IN_Error_CallBack(void)
|
|
adustm | 0:da04816fb411 | 380 | { |
Jerome Coutant
5:66c230f74325
|
381
|
printf("BSP_AUDIO_IN_Error_CallBack\n");
|
|
adustm | 0:da04816fb411 | 382 | } |