
lab 1 code
Dependencies: CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG
Diff: main.cpp
- Revision:
- 34:5bf89ab5e247
- Parent:
- 33:a0dab92ea1b9
diff -r a0dab92ea1b9 -r 5bf89ab5e247 main.cpp --- a/main.cpp Mon Jan 06 23:22:02 2020 +0000 +++ b/main.cpp Tue Jan 28 22:23:00 2020 +0000 @@ -32,7 +32,11 @@ BUFFER_OFFSET_FULL = 2, } BUFFER_StateTypeDef; +/* Scale factor */ +#define SCALE_FACTOR ((uint16_t)100) // Scale factor for dividing R L + /* These audio block samples define the size of the buffering */ +#define AUDIO_SAMPLE_LENGTH ((uint16_t)16) // Bits per sample #define AUDIO_BLOCK_SAMPLES ((uint32_t)128) // Number of samples (L and R) in audio block (each samples is 16 bits) #define AUDIO_BLOCK_SIZE ((uint32_t)512) // Number of bytes in audio block (4 * AUDIO_BLOCK_SAMPLES) @@ -44,7 +48,7 @@ /* These definitions define the size of the oscilloscope that is used to display data. */ #define OSC_START_X_POS 20 #define OSC_LINE_SIZE 256 -#define OSC_Y_POS 130 +#define OSC_Y_POS 150 #define AUDIO_DRAW_LIMIT 50 /* This define a timer that is then used to record the timing of the different processing stages. */ @@ -100,6 +104,13 @@ BSP_LCD_DisplayStringAt(0, OSC_Y_POS - 20, (uint8_t *)"L", LEFT_MODE); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAt(0, OSC_Y_POS, (uint8_t *)"R", LEFT_MODE); + + // Draw rectangle and center line for O-scope background + BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); + BSP_LCD_DrawRect(OSC_START_X_POS - 1, OSC_Y_POS - AUDIO_DRAW_LIMIT - 1, OSC_LINE_SIZE + 2, AUDIO_DRAW_LIMIT*2 + 2); + BSP_LCD_SetTextColor(LCD_COLOR_WHITE); + BSP_LCD_DrawLine(OSC_START_X_POS, OSC_Y_POS, OSC_START_X_POS + OSC_LINE_SIZE, OSC_Y_POS); + /* The following code should not be code that you need to worry about - it sets up the audio interfaces. */ /* Initialize the Audio Interface */ @@ -163,8 +174,8 @@ /* Copy recorded 1st half block into the audio buffer that goes out */ /* Replace the second memcpy with this first one once you have worked out the processed audio functions. */ - //memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(Processed_audio), AUDIO_BLOCK_SIZE); - memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(AUDIO_BUFFER_IN), AUDIO_BLOCK_SIZE); + memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(Processed_audio), AUDIO_BLOCK_SIZE); + //memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(AUDIO_BUFFER_IN), AUDIO_BLOCK_SIZE); /* Display useful cycle information (split up information display so the processing is more balanced) */ sprintf(buf, "Cycles: %9d", counter); @@ -199,8 +210,8 @@ Float_to_Audio(L_channel_float_p, R_channel_float_p, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES); /* Copy recorded 2nd half block into the audio buffer that goes out */ - //memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *) (Processed_audio), AUDIO_BLOCK_SIZE); - memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE); + memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *) (Processed_audio), AUDIO_BLOCK_SIZE); + //memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE); /* Compute important cycle information and display it*/ @@ -233,6 +244,9 @@ */ void Erase_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t Length) { + BSP_LCD_SetTextColor(LCD_COLOR_BLACK); + BSP_LCD_FillRect(Xpos, Ypos - AUDIO_DRAW_LIMIT, OSC_LINE_SIZE/2, AUDIO_DRAW_LIMIT); + BSP_LCD_FillRect(Xpos, Ypos+1, OSC_LINE_SIZE/2, AUDIO_DRAW_LIMIT); } @@ -246,6 +260,31 @@ */ void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t* Mem_start, uint16_t Length) { + int16_t R; + int16_t L; + int16_t R_scaled; + int16_t L_scaled; + + + for(uint16_t ii = 0; ii < Length; ii++) + { + R = *Mem_start; + Mem_start++; + L = *Mem_start; + Mem_start++; + + R_scaled = R/SCALE_FACTOR; + L_scaled = L/SCALE_FACTOR; + if(L_scaled != 0 && L_scaled < AUDIO_DRAW_LIMIT && L_scaled > -AUDIO_DRAW_LIMIT) + { + BSP_LCD_DrawPixel(ii + Xpos, L_scaled + Ypos, LCD_COLOR_BLUE); + } + + if(R_scaled != 0 && R_scaled < AUDIO_DRAW_LIMIT && R_scaled > -AUDIO_DRAW_LIMIT) + { + BSP_LCD_DrawPixel(ii + Xpos, R_scaled + Ypos, LCD_COLOR_GREEN); + } + } } /** @@ -257,7 +296,22 @@ * @retval None */ void Audio_to_Float(uint16_t* buffer_in, float* L_out, float* R_out, uint16_t Length) -{ +{ + int16_t R; + int16_t L; + + for(uint16_t ii = 0; ii < Length; ii++) + { + R = *buffer_in; + buffer_in++; + L = *buffer_in; + buffer_in++; + + *R_out = R; + R_out++; + *L_out = L; + L_out++; + } } /** @@ -270,6 +324,21 @@ */ void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length) { + int16_t R; + int16_t L; + + for(uint16_t ii = 0; ii < Length; ii++) + { + R = *R_in; + R_in++; + L = *L_in; + L_in++; + + *buffer_out = R; + buffer_out++; + *buffer_out = L; + buffer_out++; + } }