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

Committer:
nanase
Date:
Sat Dec 26 14:51:48 2015 +0000
Revision:
0:36a62c23e60c
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nanase 0:36a62c23e60c 1 #include "main.h"
nanase 0:36a62c23e60c 2
nanase 0:36a62c23e60c 3 LCD_DISCO_F746NG lcd;
nanase 0:36a62c23e60c 4
nanase 0:36a62c23e60c 5 int16_t audio_in_buffer[BufferSize];
nanase 0:36a62c23e60c 6 __IO bool audio_in_buffer_captured = false;
nanase 0:36a62c23e60c 7 __IO int32_t audio_in_buffer_offset = 0;
nanase 0:36a62c23e60c 8 __IO int32_t audio_in_buffer_length = 0;
nanase 0:36a62c23e60c 9
nanase 0:36a62c23e60c 10 void init_audio_in()
nanase 0:36a62c23e60c 11 {
nanase 0:36a62c23e60c 12 if (BSP_AUDIO_IN_Init(INPUT_DEVICE_INPUT_LINE_1, AudioInVolume, SamplingFreq) == AUDIO_ERROR)
nanase 0:36a62c23e60c 13 error_trap();
nanase 0:36a62c23e60c 14
nanase 0:36a62c23e60c 15 NVIC_SetVector(AUDIO_IN_SAIx_DMAx_IRQ, (uint32_t)&AUDIO_IN_SAIx_DMAx_IRQHandler);
nanase 0:36a62c23e60c 16 }
nanase 0:36a62c23e60c 17
nanase 0:36a62c23e60c 18 void record_audio_in()
nanase 0:36a62c23e60c 19 {
nanase 0:36a62c23e60c 20 if (BSP_AUDIO_IN_Record((uint16_t*)&audio_in_buffer[0], BufferByteSize / 2) == AUDIO_ERROR)
nanase 0:36a62c23e60c 21 error_trap();
nanase 0:36a62c23e60c 22 }
nanase 0:36a62c23e60c 23
nanase 0:36a62c23e60c 24
nanase 0:36a62c23e60c 25 int main()
nanase 0:36a62c23e60c 26 {
nanase 0:36a62c23e60c 27 char strbuf[64];
nanase 0:36a62c23e60c 28 uint16_t width, height, height_2, graph_height;
nanase 0:36a62c23e60c 29 double y_factor;
nanase 0:36a62c23e60c 30
nanase 0:36a62c23e60c 31 lcd.Clear(LCD_COLOR_BLACK);
nanase 0:36a62c23e60c 32 lcd.SetBackColor(LCD_COLOR_BLACK);
nanase 0:36a62c23e60c 33 lcd.SetTextColor(LCD_COLOR_WHITE);
nanase 0:36a62c23e60c 34 lcd.SetFont(&Font12);
nanase 0:36a62c23e60c 35 sprintf(strbuf, "SamplingFreq: %d Hz", SamplingFreq);
nanase 0:36a62c23e60c 36 lcd.DisplayStringAt(0, 0, (uint8_t *)strbuf, LEFT_MODE);
nanase 0:36a62c23e60c 37
nanase 0:36a62c23e60c 38 width = lcd.GetXSize() - 1;
nanase 0:36a62c23e60c 39 height = lcd.GetYSize() - 1;
nanase 0:36a62c23e60c 40 graph_height = height - LINE(1);
nanase 0:36a62c23e60c 41 height_2 = graph_height / 2;
nanase 0:36a62c23e60c 42 y_factor = (graph_height * 0.5 * AudioInGraphYFactor) / 32768.0;
nanase 0:36a62c23e60c 43
nanase 0:36a62c23e60c 44 init_audio_in();
nanase 0:36a62c23e60c 45 record_audio_in();
nanase 0:36a62c23e60c 46
nanase 0:36a62c23e60c 47 while(1) {
nanase 0:36a62c23e60c 48 if (audio_in_buffer_captured) {
nanase 0:36a62c23e60c 49 lcd.SetTextColor(LCD_COLOR_BLACK);
nanase 0:36a62c23e60c 50 lcd.FillRect(0, LINE(1), width, graph_height);
nanase 0:36a62c23e60c 51 lcd.SetTextColor(LCD_COLOR_WHITE);
nanase 0:36a62c23e60c 52
nanase 0:36a62c23e60c 53 for (int32_t i = audio_in_buffer_offset, j = 0; j < audio_in_buffer_length / 2 - 1 && j < width - 1; j++) {
nanase 0:36a62c23e60c 54 uint16_t k = (uint16_t)j;
nanase 0:36a62c23e60c 55 int16_t y1 = (int16_t)(audio_in_buffer[i + 0] * y_factor);
nanase 0:36a62c23e60c 56 int16_t y2 = (int16_t)(audio_in_buffer[i + 4] * y_factor);
nanase 0:36a62c23e60c 57
nanase 0:36a62c23e60c 58 if (y1 > height_2)
nanase 0:36a62c23e60c 59 y1 = height_2;
nanase 0:36a62c23e60c 60 else if (y1 < -height_2)
nanase 0:36a62c23e60c 61 y1 = -height_2;
nanase 0:36a62c23e60c 62
nanase 0:36a62c23e60c 63 if (y2 > height_2)
nanase 0:36a62c23e60c 64 y2 = height_2;
nanase 0:36a62c23e60c 65 else if (y2 < -height_2)
nanase 0:36a62c23e60c 66 y2 = -height_2;
nanase 0:36a62c23e60c 67
nanase 0:36a62c23e60c 68 lcd.DrawLine(k, (uint16_t)(height_2 + y1 + LINE(1)), k + 1, (uint16_t)(height_2 + y2 + LINE(1)));
nanase 0:36a62c23e60c 69
nanase 0:36a62c23e60c 70 i += 4;
nanase 0:36a62c23e60c 71 }
nanase 0:36a62c23e60c 72 audio_in_buffer_captured = false;
nanase 0:36a62c23e60c 73 }
nanase 0:36a62c23e60c 74
nanase 0:36a62c23e60c 75 wait_ms(AudioInLCDInterval);
nanase 0:36a62c23e60c 76 }
nanase 0:36a62c23e60c 77 }