/console-audioSpectra

CLI spectral histograms of mic audio | Pitch / chord detection algorithms

Primary LanguageC++

console-audioSpectra

  • Printing spectral histograms of incoming audio to console
  • Basic pitch detection and chord guessing algorithms

Started as an excuse to learn and implement the (simplest version of the) FFT. Uses SDL2 to record audio and performs FFT on it. Then interprets and/or visualizes FFT results.

VISUALIZER OPTIONS

Scaled Spectrum

  1. Fixed semilog
  2. Fixed linear
  3. Fixed log-log
  4. Adaptive semilog
  5. Adaptive linear
  6. Adaptive log-log

Wrapped Spectrum (Spectral Guitar Tuner)

  1. Fixed
  2. Adaptive

Music Algorithms

  1. Pitch recognition (automatic tuner)
  2. Chord Guesser

Scaled Spectrum Mode

"Plots" a spectral histogram to the console with linear, semilog, or log-log scaling. And repeat.

Uses GetConsoleScreenBufferInfo() to find console dimensions and scale graph accordingly. Uses system("cls") to refresh the console between frames. Which is not great, but eh.

sc1

Spectral Guitar Tuner Mode

Guitar tuner mode is semilog scaling that wraps around at the octave. i.e., The coefficient of 55Hz (A1) adds to 110Hz (A2), 220Hz (A3) etc. Octave-marking information is thus effectively discarded, but information of flatness or sharpness is retained. Logic explained in YouTube Video.

sc2

"Auto" Guitar Tuner Mode

This performs pitch detection by identifying peaks in the FFT and finding the "approximate HCF" (i.e., fundamental frequency corresponding to an arbitrary subset of harmonics) using continued fractions. Tuner display is a needle-and-dial type, but the needle stays fixed and the dial moves, to prevent erratic needle motions near quarter-tone points.

sc3

Chord Guesser

This attempts to name a chord by assigning pitch names to spectral spikes. Hit-or-miss, but often guesses something at least close-sounding.

sc4 sc8 sc9 sc7 sc5