Hasty Briefsbeta

Bilingual

Making Our Own Spectrogram

20 hours ago
  • Fourier transforms convert signals between time and frequency domains, enabling spectrogram generation.
  • A square wave can be approximated by summing cosine waves with harmonics, illustrating how Fourier series work.
  • Real-world audio (e.g., a mouth pop) can be reconstructed using a limited number of cosine components via FFT.
  • Windowing functions like Hann windows prevent spectral leakage by tapering signal edges during chunked analysis.
  • Overlap-add reconstruction with Hann windows yields correct audio, except at boundaries where padding is needed.
  • The Gabor limit forces a trade-off between time and frequency resolution; choosing FFT size and overlap affects spectrogram sharpness.
  • Interpolation between frequency bins improves visual smoothness, while disabling it reveals bin boundaries.
  • Perceptually uniform color maps (e.g., colorcet) enhance readability of spectrograms over simple black-white gradients.
  • A logarithmic frequency scale with custom interpolation provides better representation of human pitch perception.
  • Audio input is captured from system devices (e.g., via Loopback) using the cpal crate with a callback for live processing.
  • UI and audio threads communicate via channels; a bounded VecDeque prevents memory overflow during rendering stalls.
  • Texture updates in egui involve allocating a handle, drawing to a ColorImage, and uploading to GPU each frame.
  • Profiling reveals CPU hotspots: 25% of cycles on cloning ColorImage, 40% on texture uploads, and 27% on FFT computations.
  • The spectrogram visualizes various music genres and sounds (e.g., vibrato, frequency sweeps, bird calls) for educational fun.