
lab 1 code
Dependencies: CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG
Diff: main.cpp
- Revision:
- 31:5a0235b66851
- Parent:
- 30:debea332cdfe
- Child:
- 33:a0dab92ea1b9
--- a/main.cpp Fri Jan 03 20:15:03 2020 +0000 +++ b/main.cpp Fri Jan 03 21:00:56 2020 +0000 @@ -44,8 +44,8 @@ /* 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 110 -#define AUDIO_DRAW_LIMIT 30 +#define OSC_Y_POS 130 +#define AUDIO_DRAW_LIMIT 50 /* This define a timer that is then used to record the timing of the different processing stages. */ Timer timer; @@ -93,7 +93,7 @@ BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); /* The following are static display elements that will remain on the screen. */ - BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"487 Demo Code (Mazzeo)", LEFT_MODE); + BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"487 Lab 1 (student)", LEFT_MODE); /* Display the L and R colors for the channels */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); @@ -162,7 +162,9 @@ Float_to_Audio(L_channel_float_p, R_channel_float_p, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES); /* Copy recorded 1st half block into the audio buffer that goes out */ - memcpy((uint16_t *)(AUDIO_BUFFER_OUT), (uint16_t *)(Processed_audio), AUDIO_BLOCK_SIZE); + /* 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); /* Display useful cycle information (split up information display so the processing is more balanced) */ sprintf(buf, "Cycles: %9d", counter); @@ -197,7 +199,9 @@ 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 *) (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*/ sprintf(buf, "1:%6d 2:%6d T:%6d", first_half_time, second_half_time, total_time); @@ -205,7 +209,6 @@ BSP_LCD_DisplayStringAt(0, 20, (uint8_t *) buf, LEFT_MODE); /* Copy recorded 2nd half block into audio output buffer */ - //memcpy((uint16_t *)(AUDIO_BUFFER_OUT + (AUDIO_BLOCK_SIZE)), (uint16_t *)(AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SIZE); /* Change the recording buffer state to reflect the status of the buffer */ audio_rec_buffer_state = BUFFER_OFFSET_NONE; @@ -231,15 +234,6 @@ */ void Erase_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t Length) { - /* Creates a brown rectangle above and below the axis */ - BSP_LCD_SetTextColor(LCD_COLOR_BROWN); - BSP_LCD_FillRect(Xpos, Ypos - AUDIO_DRAW_LIMIT, Length, AUDIO_DRAW_LIMIT); - BSP_LCD_FillRect(Xpos, Ypos+1, Length, AUDIO_DRAW_LIMIT); - - /* Draw axis for plotting */ - BSP_LCD_SetTextColor(LCD_COLOR_WHITE); - BSP_LCD_DrawHLine(Xpos, Ypos, Length); - } @@ -254,34 +248,6 @@ */ void Draw_Trace(uint16_t Xpos, uint16_t Ypos, uint16_t* Mem_start, uint16_t Length) { - uint16_t i; - uint16_t* mem_address; - char buf[10]; - int16_t L_audio_value; - int16_t R_audio_value; - - mem_address = Mem_start; - - for (i=0; i<Length; i++) - { - L_audio_value = (int16_t) *mem_address; - mem_address++; - R_audio_value = (int16_t) *mem_address; - mem_address++; - - L_audio_value = L_audio_value / 100; - R_audio_value = R_audio_value / 100; - - if (L_audio_value > AUDIO_DRAW_LIMIT) {L_audio_value = AUDIO_DRAW_LIMIT;} - else if (L_audio_value < -AUDIO_DRAW_LIMIT) {L_audio_value = -AUDIO_DRAW_LIMIT;} - - if (R_audio_value > AUDIO_DRAW_LIMIT) {R_audio_value = AUDIO_DRAW_LIMIT;} - else if (R_audio_value < -AUDIO_DRAW_LIMIT) {R_audio_value = -AUDIO_DRAW_LIMIT;} - - BSP_LCD_DrawPixel(Xpos + i, (uint16_t) ((int16_t) Ypos + L_audio_value), LCD_COLOR_BLUE); - BSP_LCD_DrawPixel(Xpos + i, (uint16_t) ((int16_t) Ypos + R_audio_value), LCD_COLOR_GREEN); - } - } /** @@ -294,30 +260,6 @@ */ void Audio_to_Float(uint16_t* buffer_in, float* L_out, float* R_out, uint16_t Length) { - uint16_t i; - uint16_t* audio_mem_address; - float* L_chan_mem_address; - float* R_chan_mem_address; - float L_audio_value; - float R_audio_value; - - audio_mem_address = buffer_in; - L_chan_mem_address = L_out; - R_chan_mem_address = R_out; - - for (i=0; i<Length; i++) - { - L_audio_value = (float) ((int16_t) *audio_mem_address); - audio_mem_address++; - R_audio_value = (float) ((int16_t) *audio_mem_address); - audio_mem_address++; - - *L_chan_mem_address = L_audio_value; - L_chan_mem_address++; - - *R_chan_mem_address = R_audio_value; - R_chan_mem_address++; - } } /** @@ -330,30 +272,6 @@ */ void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length) { - uint16_t i; - uint16_t* audio_mem_address; - float* L_chan_mem_address; - float* R_chan_mem_address; - int16_t L_audio_value; - int16_t R_audio_value; - - audio_mem_address = buffer_out; - L_chan_mem_address = L_in; - R_chan_mem_address = R_in; - - for (i=0; i<Length; i++) - { - L_audio_value = (int16_t) ((float) *L_chan_mem_address); - L_chan_mem_address++; - - R_audio_value = (int16_t) ((float) *R_chan_mem_address); - R_chan_mem_address++; - - *audio_mem_address = (uint16_t) L_audio_value; - audio_mem_address++; - *audio_mem_address = (uint16_t) R_audio_value; - audio_mem_address++; - } }