
lab 1 code
Dependencies: CMSIS-DSP_for_STM32F746G BSP_DISCO_F746NG
Diff: main.cpp
- Revision:
- 21:4dbfda694c0d
- Parent:
- 20:2ecdf687a2d1
- Child:
- 22:f36d7a53bb7e
--- a/main.cpp Tue Dec 31 19:22:11 2019 +0000 +++ b/main.cpp Tue Dec 31 19:50:33 2019 +0000 @@ -120,10 +120,11 @@ sprintf(buf, "Lf[0]:%8.1f Ai[0]:%6d ", L_channel_float[0], ((int16_t) *((uint16_t *) AUDIO_BUFFER_IN))); BSP_LCD_DisplayStringAt(0, 150, (uint8_t *) buf, LEFT_MODE); - //Float_to_Audio((float *) L_channel_float, (float *) R_channel_float, (uint16_t *) Processed_audio, AUDIO_BLOCK_SAMPLES); + 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 *)(AUDIO_BUFFER_IN), 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); /* Capture the timing of the first half processing */ first_half_time = timer.read_us(); @@ -267,24 +268,28 @@ void Float_to_Audio(float* L_in, float* R_in, uint16_t* buffer_out, uint16_t Length) { uint16_t i; - uint32_t data_value; uint16_t* audio_mem_address; - uint16_t* L_chan_mem_address; - uint16_t* R_chan_mem_address; - float L_audio_value; - float R_audio_value; + 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_chan_mem_address = (uint16_t*) L_in + i; - R_chan_mem_address = (uint16_t*) R_in + i; - audio_mem_address = (uint16_t*) buffer_out + i; + L_audio_value = (int16_t) ((float) *L_chan_mem_address); + L_chan_mem_address++; - L_audio_value = *((uint16_t*) L_chan_mem_address); - R_audio_value = *((uint16_t*) R_chan_mem_address); - - data_value = (((uint32_t) ((int16_t) L_audio_value)) << 16) | ((uint32_t) ((int16_t) R_audio_value)); - *audio_mem_address = data_value; + 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++; } }