DISCO-F746NGのAudioInからの音声信号をLCDに波形として出力する、簡易なオシロスコープです。 This program is easy oscilloscope. The program draws waveform of signals from AudioIn on DISCO-F746NG.
Dependencies: BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG mbed
main.cpp
00001 #include "main.h" 00002 00003 LCD_DISCO_F746NG lcd; 00004 00005 int16_t audio_in_buffer[BufferSize]; 00006 __IO bool audio_in_buffer_captured = false; 00007 __IO int32_t audio_in_buffer_offset = 0; 00008 __IO int32_t audio_in_buffer_length = 0; 00009 00010 void init_audio_in() 00011 { 00012 if (BSP_AUDIO_IN_Init(INPUT_DEVICE_INPUT_LINE_1, AudioInVolume, SamplingFreq) == AUDIO_ERROR) 00013 error_trap(); 00014 00015 NVIC_SetVector(AUDIO_IN_SAIx_DMAx_IRQ, (uint32_t)&AUDIO_IN_SAIx_DMAx_IRQHandler); 00016 } 00017 00018 void record_audio_in() 00019 { 00020 if (BSP_AUDIO_IN_Record((uint16_t*)&audio_in_buffer[0], BufferByteSize / 2) == AUDIO_ERROR) 00021 error_trap(); 00022 } 00023 00024 00025 int main() 00026 { 00027 char strbuf[64]; 00028 uint16_t width, height, height_2, graph_height; 00029 double y_factor; 00030 00031 lcd.Clear(LCD_COLOR_BLACK); 00032 lcd.SetBackColor(LCD_COLOR_BLACK); 00033 lcd.SetTextColor(LCD_COLOR_WHITE); 00034 lcd.SetFont(&Font12); 00035 sprintf(strbuf, "SamplingFreq: %d Hz", SamplingFreq); 00036 lcd.DisplayStringAt(0, 0, (uint8_t *)strbuf, LEFT_MODE); 00037 00038 width = lcd.GetXSize() - 1; 00039 height = lcd.GetYSize() - 1; 00040 graph_height = height - LINE(1); 00041 height_2 = graph_height / 2; 00042 y_factor = (graph_height * 0.5 * AudioInGraphYFactor) / 32768.0; 00043 00044 init_audio_in(); 00045 record_audio_in(); 00046 00047 while(1) { 00048 if (audio_in_buffer_captured) { 00049 lcd.SetTextColor(LCD_COLOR_BLACK); 00050 lcd.FillRect(0, LINE(1), width, graph_height); 00051 lcd.SetTextColor(LCD_COLOR_WHITE); 00052 00053 for (int32_t i = audio_in_buffer_offset, j = 0; j < audio_in_buffer_length / 2 - 1 && j < width - 1; j++) { 00054 uint16_t k = (uint16_t)j; 00055 int16_t y1 = (int16_t)(audio_in_buffer[i + 0] * y_factor); 00056 int16_t y2 = (int16_t)(audio_in_buffer[i + 4] * y_factor); 00057 00058 if (y1 > height_2) 00059 y1 = height_2; 00060 else if (y1 < -height_2) 00061 y1 = -height_2; 00062 00063 if (y2 > height_2) 00064 y2 = height_2; 00065 else if (y2 < -height_2) 00066 y2 = -height_2; 00067 00068 lcd.DrawLine(k, (uint16_t)(height_2 + y1 + LINE(1)), k + 1, (uint16_t)(height_2 + y2 + LINE(1))); 00069 00070 i += 4; 00071 } 00072 audio_in_buffer_captured = false; 00073 } 00074 00075 wait_ms(AudioInLCDInterval); 00076 } 00077 }
Generated on Wed Aug 3 2022 23:10:33 by 1.7.2