Mic Visualizer

Lab 4: Microphone Visualizer

Part 3 - Oscilloscope & Signal Processing


1. โครงสร้างภาพรวมของ Lab

Why? - ทำไมต้องเรียนรู้เรื่องนี้

  • Audio Level Monitoring: VU Meter เป็นเครื่องมือพื้นฐานในทุกระบบที่เกี่ยวกับเสียง ตั้งแต่สตูดิโอบันทึกเสียงจนถึงระบบ PA ในอาคาร

  • Peak Detection: การตรวจจับค่า Peak เป็นเทคนิคสำคัญในระบบ Power Systems (surge detection), Audio (clipping prevention) และ Vibration Monitoring

  • Threshold-based Alarming: ระบบเตือนภัยในโรงงาน (noise level > 85 dBA), ระบบ Power Quality (voltage sag/swell) ใช้หลักการ threshold เดียวกัน

  • Real-time Data Streaming: Pattern การรับข้อมูลต่อเนื่องจาก sensor แล้วแสดงผลแบบ real-time ใช้ได้กับทุก sensor ไม่เฉพาะ microphone

What? - จะได้เรียนรู้อะไร

  1. Simulated Mic Input: จำลองสัญญาณ PDM Microphone (เพราะ PC Sim ไม่มี mic จริง)

  2. VU Meter Display: สร้าง Level Meter ด้วย lv_bar พร้อมสี gradient

  3. Peak Detection & Hold: ตรวจจับค่า Peak แล้วค้างไว้ก่อนลดลง

  4. Color Threshold: Green (safe) / Yellow (warning) / Red (critical)

  5. Clipping Detection: ตรวจจับเมื่อสัญญาณเกิน threshold

How? - จะทำอย่างไร

  1. จำลองข้อมูล Microphone ด้วย Sine + Noise (amplitude แปรผัน)

  2. สร้าง Waveform chart แสดง signal

  3. สร้าง VU Meter Bar แนวตั้ง พร้อมสี zone

  4. คำนวณ Peak-to-Peak, RMS, Level % แบบ real-time

  5. เพิ่ม Peak Hold indicator และ Clipping warning


2. หลักการทำงานและ Flowchart

2.1 PDM Microphone

2.2 VU Meter Concept


3. ฟังก์ชันสำคัญ

3.1 Simulated Mic API

Function
Description

sim_mic_generate()

สร้างสัญญาณจำลอง microphone

calc_peak_to_peak()

คำนวณ Peak-to-Peak

calc_rms()

คำนวณ RMS

3.2 VU Meter Functions

Function
Description

update_vu_meter()

อัพเดทค่าและสี VU bar

update_peak_hold()

อัพเดท Peak Hold indicator

check_clipping()

ตรวจจับ clipping


4. Code เต็ม

4.1 Constants and Global Variables

4.2 Simulated Microphone

4.3 VU Meter Update Functions

4.4 Timer Callback

4.5 Main Function


5. องค์ความรู้และเทคนิค

5.1 VU Meter vs Peak Meter

5.2 Peak Hold Algorithm

5.3 Color Gradient for Level

5.4 Timer Rate vs Responsiveness


6. แบบฝึกหัด

Exercise 1: Audio Level Meter with Peak Hold Indicator

โจทย์: สร้าง VU Meter แบบมืออาชีพ:

  • เพิ่ม Peak Hold indicator เป็นเส้นขีดบาง ๆ บน VU bar (ไม่ใช่แค่ text)

  • สร้างเป็น object ขนาดเล็ก (เส้นสีขาว) ที่เลื่อนตำแหน่ง Y ตาม peak_level

  • เพิ่ม dB scale ข้าง VU bar (-40dB, -20dB, -10dB, -6dB, -3dB, 0dB)

  • แปลง level% เป็น dB: dB = 20 * log10(level/100)

คำใบ้:

Exercise 2: Clipping Detector with History

โจทย์: สร้างระบบตรวจจับ Clipping พร้อมประวัติ:

  • นับจำนวนครั้งที่เกิด clipping (clip count)

  • แสดง clip count บนจอ

  • เมื่อ clipping เกิด 3 ครั้งใน 5 วินาที ให้แสดง warning ใหญ่กลางจอ

  • เพิ่มปุ่ม Reset เพื่อ clear clip count

  • เปลี่ยน border สี chart เป็นสีแดงเมื่อ clipping

คำใบ้:


7. References


Last updated

Was this helpful?