Back to Home

Mathematics of musical scales for developers — basics of sound processing

Analysis of the connection between mathematical principles and musical scales from antiquity to modern audio codecs. Application of group theory and algebraic structures in DSP algorithms is shown. For audio system developers.

From Pythagoras to AI: mathematics in modern audio systems
Advertisement 728x90

Mathematical Roots of Musical Harmony: From Pythagoras to Digital Tunings

Mathematical laws determine not only physical phenomena but also the aesthetics of musical sound. Modern digital audio systems and sound processing algorithms continue to use principles established in antiquity. Let's explore how irrational numbers and group theory form the foundation for audio codecs and synthesizers.

Pythagorean Experiments: The Foundation of Digital Audio Processing

The classic blacksmith experiment illustrates the key principle: consonance arises from simple frequency ratios. For IT specialists, this echoes the workings of an ADC—the analog audio signal is converted into discrete values through mathematical operations. Pythagoras, by weighing hammers, was essentially performing spectral analysis, identifying harmonics based on weight ratios.

Modern audio processors use a similar approach. During sound digitization, Nyquist's sampling theorem is applied, where the sampling rate is determined by the maximum signal frequency. This is a direct descendant of the Pythagorean principle: the 2:1 ratio for octaves aligns with the Nyquist rule, requiring the sampling frequency to exceed twice the maximum signal frequency.

Google AdInline article slot

It's important to understand that the historical Pythagorean comma problem remains relevant in digital processing. When converting audio between formats, discrepancies arise akin to the mismatch between 12 fifths and 7 octaves. Codec developers address it through dithering and noise-like error distribution.

Algebraic Structures in Musical Transformations

Building the 12-tone scale is the first practical example of group theory in action. Each semitone represents an element of the cyclic group Z/12Z, where addition corresponds to key modulation. This principle underpins the MIDI protocol: the pitch bend value is encoded as a 14-bit number controlling shifts within ±2 semitones.

Modern DSP algorithms employ more complex structures. For example, in spectrum analysis via the FFT method:

Google AdInline article slot
import numpy as np

# Calculation frequency for n-go polutona
def freq(n, base_freq=440.0):
    return base_freq * (2**(1/12))**n

# Example for noty A4 (440 Gts) and eyo oktav
print(freq(0))  # 440.0
print(freq(12)) # 880.0

This code demonstrates equal temperament—the basis of all digital audio systems. Note that professional DAW (Digital Audio Workstation) implementations use 64-bit computations to minimize rounding errors stemming from the irrationality of √2.

Temperament as an Error Compensation Algorithm

The Pythagorean comma problem (129.75 ≠ 128) has a direct parallel in computer arithmetic. Floating-point operations accumulate rounding errors across computation chains. Werckmeister's solution—evenly distributing the error across all intervals—mirrors error correction methods in digital systems.

Modern audio codecs apply similar principles:

Google AdInline article slot
  • AAC uses perceptual coding with error prediction
  • Dolby Atmos optimizes error distribution for human perception
  • Pitch-shifting algorithms correct phase distortions via window functions

Key insight: temperament isn't a simplification but an optimization tailored to system constraints. Developers make the same trade-offs between computational precision and performance in embedded audio systems.

Set Theory in Compositional Algorithms

Xenakis's work with stochastic processes foreshadowed modern generative models. Contemporary AI algorithms like Google Magenta leverage set-theoretic operations to generate music:

  • Set of notes → feature space
  • Union/intersection operations → harmonic progressions
  • Mapping to metric space → rhythmic structures

Researchers from Skoltech recently proposed a transformer architecture modification, distributing model attention via group operations over musical intervals. This maintains harmonic coherence during generation, sidestepping artifacts common in classic LSTM networks.

Importantly, these systems don't replace musicians—they provide new tools. Like equal temperament, they expand creative possibilities while upholding mathematical foundations.

Key Takeaways

  • Pythagorean comma: prototype of rounding errors in digital systems
  • Equal temperament harnesses irrational numbers as a compromise between precision and versatility
  • Modern audio codecs employ the same error distribution principles as historical tunings
  • Group theory forms the basis of the MIDI protocol and DSP algorithms
  • Generative music models advance Xenakis's ideas via set-theoretic operations

Digital audio processing continues the age-old dialogue between mathematics and music ignited by Pythagoras. Today's audio system developers grapple with the same core challenges, solving them through computational complexity and hardware limits. Grasping this historical context enables more effective algorithms—from basic pitch shifters to neural synthesizers.

— Editorial Team

Advertisement 728x90

Read Next