Spectral Analysis

Spectral analysis and frequency band energy measurement.

This module provides frequency band analysis for mixing and mastering, breaking audio into standard production frequency ranges.

class mixref.detective.spectral.FrequencyBand[source]

Bases: object

Definition of a frequency band.

name

Band name (e.g., “Sub”, “Low”).

Type:

str

min_hz

Minimum frequency in Hz.

Type:

float

max_hz

Maximum frequency in Hz.

Type:

float

name: str
min_hz: float
max_hz: float
__init__(name, min_hz, max_hz)
class mixref.detective.spectral.BandEnergy[source]

Bases: object

Energy measurement for a frequency band.

band_name

Name of the frequency band.

Type:

str

energy_db

RMS energy in dB.

Type:

float

energy_percent

Energy as percentage of total (0-100).

Type:

float

band_name: str
energy_db: float
energy_percent: float
__init__(band_name, energy_db, energy_percent)
class mixref.detective.spectral.SpectralResult[source]

Bases: object

Result of spectral analysis.

bands

List of band energy measurements.

Type:

list[mixref.detective.spectral.BandEnergy]

total_energy_db

Total RMS energy across all frequencies.

Type:

float

bands: list[BandEnergy]
total_energy_db: float
__init__(bands, total_energy_db)
mixref.detective.spectral.analyze_spectrum(audio, sample_rate, bands=None)[source]

Analyze frequency band energy distribution.

Parameters:
  • audio (Any) – Audio signal as numpy array. Shape: (samples,) for mono or (channels, samples) for multi-channel.

  • sample_rate (int) – Sample rate in Hz.

  • bands (list[FrequencyBand] | None) – Optional custom frequency bands. Defaults to standard production bands.

Returns:

SpectralResult with energy per band.

Return type:

SpectralResult

Example

>>> import numpy as np
>>> from mixref.detective.spectral import analyze_spectrum
>>>
>>> # Pink noise (equal energy per octave)
>>> sr = 44100
>>> duration = 5
>>> audio = np.random.randn(sr * duration) * 0.1
>>>
>>> result = analyze_spectrum(audio, sr)
>>> for band in result.bands:
...     print(f"{band.band_name}: {band.energy_percent:.1f}%")
mixref.detective.spectral.compare_spectral_balance(result1, result2)[source]

Compare spectral balance between two tracks.

Parameters:
  • result1 (SpectralResult) – Spectral analysis of first track.

  • result2 (SpectralResult) – Spectral analysis of second track (reference).

Returns:

Dict mapping band names to dB difference (track1 - track2). Positive = track1 louder in that band.

Return type:

dict[str, float]

Example

>>> from mixref.detective.spectral import analyze_spectrum, compare_spectral_balance
>>> import numpy as np
>>>
>>> sr = 44100
>>> audio1 = np.random.randn(sr * 5) * 0.1
>>> audio2 = np.random.randn(sr * 5) * 0.1
>>>
>>> result1 = analyze_spectrum(audio1, sr)
>>> result2 = analyze_spectrum(audio2, sr)
>>> diff = compare_spectral_balance(result1, result2)