lab 1 code

Dependencies:   CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG

Revision:
19:479f611941a8
Parent:
18:255d15af49f2
Child:
20:2ecdf687a2d1
--- a/main.cpp	Tue Dec 31 18:43:43 2019 +0000
+++ b/main.cpp	Tue Dec 31 18:52:01 2019 +0000
@@ -25,9 +25,8 @@
     BUFFER_OFFSET_FULL = 2,
 } BUFFER_StateTypeDef;
 
-#define HALF_AUDIO_BLOCK_SAMPLES        ((uint32_t)128)          // Number of samples (L and R) in half block
-#define HALF_AUDIO_BLOCK_SIZE           ((uint32_t)256)         // Number of samples (L and R) in full block
-#define AUDIO_BLOCK_SIZE                ((uint32_t)512)
+#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)
 
 #define SDRAM_DEVICE_ADDR_AUDIO_MEM     ((uint32_t)0xC0400000)
 #define AUDIO_BUFFER_IN                 SDRAM_DEVICE_ADDR_AUDIO_MEM
@@ -47,11 +46,11 @@
 static void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length);
 
 /* To do converstion to float */
-float       L_channel_float[HALF_AUDIO_BLOCK_SIZE];
-float       R_channel_float[HALF_AUDIO_BLOCK_SIZE];
+float       L_channel_float[AUDIO_BLOCK_SAMPLES];
+float       R_channel_float[AUDIO_BLOCK_SAMPLES];
 
 /* Back conversion to integer */
-uint16_t     Processed_audio[HALF_AUDIO_BLOCK_SIZE];
+uint16_t     Processed_audio[AUDIO_BLOCK_SAMPLES * 2];
 
 /* Useful variables during looping */
 uint32_t counter = 0;
@@ -109,12 +108,12 @@
         timer.reset();
 
         /* Plot traces of first half block recording */   
-        Erase_Trace(OSC_START_X_POS, OSC_Y_POS, HALF_AUDIO_BLOCK_SAMPLES);
-        Draw_Trace(OSC_START_X_POS, OSC_Y_POS, (uint16_t *) AUDIO_BUFFER_IN, HALF_AUDIO_BLOCK_SAMPLES);
+        Erase_Trace(OSC_START_X_POS, OSC_Y_POS, AUDIO_BLOCK_SAMPLES);
+        Draw_Trace(OSC_START_X_POS, OSC_Y_POS, (uint16_t *) AUDIO_BUFFER_IN, AUDIO_BLOCK_SAMPLES);
         
         /* Convert data to floating point representation for processing */
-        //Audio_to_Float((uint16_t *) AUDIO_BUFFER_IN, (float *) L_channel_float, (float *) R_channel_float, HALF_AUDIO_BLOCK_SAMPLES);        
-        //Float_to_Audio((float *) L_channel_float, (float *) R_channel_float, (uint16_t *) Processed_audio, HALF_AUDIO_BLOCK_SAMPLES);
+        //Audio_to_Float((uint16_t *) AUDIO_BUFFER_IN, (float *) L_channel_float, (float *) R_channel_float, AUDIO_BLOCK_SAMPLES);        
+        //Float_to_Audio((float *) L_channel_float, (float *) R_channel_float, (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 *)(AUDIO_BUFFER_IN), AUDIO_BLOCK_SIZE);
@@ -128,8 +127,8 @@
         while (audio_rec_buffer_state != BUFFER_OFFSET_FULL) {}
         
         /* Plot traces of second half block recording */
-        Erase_Trace(OSC_START_X_POS+HALF_AUDIO_BLOCK_SAMPLES, OSC_Y_POS, HALF_AUDIO_BLOCK_SAMPLES);
-        Draw_Trace(OSC_START_X_POS+ HALF_AUDIO_BLOCK_SAMPLES, OSC_Y_POS, (uint16_t *) (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), HALF_AUDIO_BLOCK_SAMPLES);
+        Erase_Trace(OSC_START_X_POS+AUDIO_BLOCK_SAMPLES, OSC_Y_POS, AUDIO_BLOCK_SAMPLES);
+        Draw_Trace( OSC_START_X_POS+AUDIO_BLOCK_SAMPLES, OSC_Y_POS, (uint16_t *) (AUDIO_BUFFER_IN + (AUDIO_BLOCK_SIZE)), AUDIO_BLOCK_SAMPLES);
                 
         /* Compute important cycle information and display it*/
         counter++;