Acoustic feature extraction (pitch, spectral flux, roll-off), audio representations (MFCC, Mel-spectrogram), and equalization DSP. More...
Files | |
| file | pitch_harmonics.hpp |
| Fundamental-frequency estimation and harmonic-content metrics. | |
| file | audio_io.hpp |
| file | freq_scales.hpp |
| file | cepstral.hpp |
| file | melspec_delta.hpp |
| file | shape_descriptors.hpp |
| Spectral-shape descriptors. | |
Classes | |
| struct | nk::audio::AudioData |
| Decoded audio waveform data and basic metadata. More... | |
| struct | nk::audio::AudioInfo |
| Audio file metadata container (info = audioinfo(filename)). More... | |
Functions | |
| Value | nk::audio::pitch (const Value &x, double fs, double minF=50.0, double maxF=400.0, std::pmr::memory_resource *mr=nullptr) |
| Pitch via the Normalised Cross-correlation Function (the default estimator). | |
| Value | nk::audio::pitchCEP (const Value &x, double fs, double minF=50.0, double maxF=400.0, std::pmr::memory_resource *mr=nullptr) |
| Pitch via the cepstrum method (Noll 1967). | |
| Value | nk::audio::pitchPEF (const Value &x, double fs, double minF=50.0, double maxF=400.0, std::pmr::memory_resource *mr=nullptr) |
| Pitch Estimation Filter (Gonzalez & Brookes 2011). | |
| Value | nk::audio::pitchLHS (const Value &x, double fs, double minF=50.0, double maxF=400.0, std::pmr::memory_resource *mr=nullptr) |
| Log Harmonic Sum / Subharmonic Summation (Hermes 1988). | |
| Value | nk::audio::pitchSRH (const Value &x, double fs, double minF=50.0, double maxF=400.0, std::pmr::memory_resource *mr=nullptr) |
| Summation of Residual Harmonics (Drugman & Alwan 2011). | |
| Value | nk::audio::harmonicRatio (const Value &x, double fs, std::pmr::memory_resource *mr=nullptr) |
| Harmonic ratio — strength of harmonic content per frame. | |
| AudioData | nk::audio::audioreadFromBytes (const std::uint8_t *data, std::size_t len, int64_t startSample=1, int64_t endSample=-1, bool nativeType=false, std::pmr::memory_resource *mr=nullptr) |
| Decodes audio from raw memory buffer, sniffing format automatically ([y, Fs] = audioread(bytes)). | |
| AudioData | nk::audio::audioreadFromBytes (const std::string &bytes, int64_t startSample=1, int64_t endSample=-1, bool nativeType=false, std::pmr::memory_resource *mr=nullptr) |
| Decodes audio from string memory buffer (audioread(bytes)). | |
| AudioInfo | nk::audio::audioinfoFromBytes (const std::uint8_t *data, std::size_t len) |
| Reads audio metadata from memory buffer without decoding audio samples (info = audioinfo(bytes)). | |
| AudioInfo | nk::audio::audioinfoFromBytes (const std::string &bytes) |
| Reads audio metadata from string memory buffer (info = audioinfo(bytes)). | |
| std::vector< std::uint8_t > | nk::audio::audiowriteToBytes (const Value &y, double sampleRate, const std::string &format="wav", uint16_t bitsPerSample=16, const std::string &title="", const std::string &artist="", const std::string &comment="") |
| Encodes audio matrix y into memory byte buffer (bytes = audiowrite(y, Fs, ...)). | |
| AudioData | nk::audio::audioread (const std::string &path, int64_t startSample=1, int64_t endSample=-1, bool nativeType=false, std::pmr::memory_resource *mr=nullptr) |
| Reads audio file from filesystem ([y, Fs] = audioread(filename)). | |
| AudioInfo | nk::audio::audioinfo (const std::string &path) |
| Returns audio file metadata (info = audioinfo(filename)). | |
| void | nk::audio::audiowrite (const std::string &path, const Value &y, double sampleRate, uint16_t bitsPerSample=16, const std::string &title="", const std::string &artist="", const std::string &comment="") |
| Writes audio data matrix y to file on disk (audiowrite(filename, y, Fs)). | |
| Value | nk::audio::hz2mel (const Value &hz, std::pmr::memory_resource *mr=nullptr) |
| Hertz → Mel (O'Shaughnessy 1987 default form). | |
| Value | nk::audio::mel2hz (const Value &mel, std::pmr::memory_resource *mr=nullptr) |
| Mel → Hertz (inverse of hz2mel). | |
| Value | nk::audio::hz2bark (const Value &hz, std::pmr::memory_resource *mr=nullptr) |
| Hertz → Bark (Traunmüller 1990 with low/high-frequency corrections). | |
| Value | nk::audio::bark2hz (const Value &bark, std::pmr::memory_resource *mr=nullptr) |
| Bark → Hertz (inverse of hz2bark). | |
| Value | nk::audio::hz2erb (const Value &hz, std::pmr::memory_resource *mr=nullptr) |
| Hertz → ERB (Glasberg & Moore 1990). | |
| Value | nk::audio::erb2hz (const Value &erb, std::pmr::memory_resource *mr=nullptr) |
| ERB → Hertz (inverse of hz2erb). | |
| Value | nk::audio::phon2sone (const Value &phon, bool standardIs532_2=false, std::pmr::memory_resource *mr=nullptr) |
| Phon → Sone — loudness-level to loudness conversion. | |
| Value | nk::audio::sone2phon (const Value &sone, bool standardIs532_2=false, std::pmr::memory_resource *mr=nullptr) |
| Sone → Phon — loudness to loudness-level conversion. | |
| Value | nk::audio::cepstralCoefficients (const Value &S, int numCoeffs=13, std::pmr::memory_resource *mr=nullptr) |
| Generic cepstral coefficient extractor. | |
| std::tuple< Value, Value, Value > | nk::audio::mfcc (const Value &x, double fs, int numCoeffs=13, std::pmr::memory_resource *mr=nullptr) |
| Mel-frequency cepstral coefficients (MFCC). | |
| std::tuple< Value, Value, Value > | nk::audio::gtcc (const Value &x, double fs, int numCoeffs=13, std::pmr::memory_resource *mr=nullptr) |
| Gammatone cepstral coefficients (GTCC). | |
| std::tuple< Value, Value, Value > | nk::audio::melSpectrogram (const Value &x, double fs, int numBands=32, std::pmr::memory_resource *mr=nullptr) |
| Mel-band power spectrogram. | |
| Value | nk::audio::audioDelta (const Value &x, int windowLength=9, std::pmr::memory_resource *mr=nullptr) |
| Locally-smoothed first derivative along the time axis. | |
| Value | nk::audio::spectralCentroid (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral centroid — power-weighted mean frequency. | |
| Value | nk::audio::spectralSpread (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral spread — power-weighted std around the centroid. | |
| Value | nk::audio::spectralRolloffPoint (const Value &x, const Value &f, double percentile=0.95, std::pmr::memory_resource *mr=nullptr) |
| Spectral rolloff frequency. | |
| Value | nk::audio::spectralDecrease (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral decrease — slope-like measure relative to first bin. | |
| Value | nk::audio::spectralSlope (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral slope — least-squares slope of (f, X). | |
| Value | nk::audio::spectralFlux (const Value &x, const Value &f, double p=2.0, std::pmr::memory_resource *mr=nullptr) |
| Spectral flux — p-norm of frame-to-frame spectrum differences. | |
| Value | nk::audio::spectralCrest (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral crest — max(X) / mean(X) per frame. | |
| Value | nk::audio::spectralEntropy (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral entropy — Shannon entropy of normalised spectrum. | |
| Value | nk::audio::spectralFlatness (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral flatness — geomean(X) / mean(X). | |
| Value | nk::audio::spectralKurtosis (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral kurtosis — X-weighted 4th central moment. | |
| Value | nk::audio::spectralSkewness (const Value &x, const Value &f, std::pmr::memory_resource *mr=nullptr) |
| Spectral skewness — X-weighted 3rd central moment. | |
Acoustic feature extraction (pitch, spectral flux, roll-off), audio representations (MFCC, Mel-spectrogram), and equalization DSP.
| Value nk::audio::audioDelta | ( | const Value & | x, |
| int | windowLength = 9, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Locally-smoothed first derivative along the time axis.
Implements the standard delta-coefficient filter: \( \Delta x[n] = \frac{\sum_{k=1}^{M} k \cdot (x[n+k] - x[n-k])}{2 \sum_{k=1}^{M} k^2} \) where M = floor(windowLength / 2).
| x | Feature matrix (rows = time, cols = channels). |
| windowLength | Filter window length (odd, ≥ 3). Default 9. |
| mr | Memory resource (nullptr → process default). |
| AudioInfo nk::audio::audioinfo | ( | const std::string & | path | ) |
Returns audio file metadata (info = audioinfo(filename)).
| path | Path to audio file. |
| AudioInfo nk::audio::audioinfoFromBytes | ( | const std::string & | bytes | ) |
Reads audio metadata from string memory buffer (info = audioinfo(bytes)).
| bytes | Audio file bytes as string. |
| AudioInfo nk::audio::audioinfoFromBytes | ( | const std::uint8_t * | data, |
| std::size_t | len ) |
Reads audio metadata from memory buffer without decoding audio samples (info = audioinfo(bytes)).
| data | Pointer to raw audio bytes. |
| len | Length of buffer in bytes. |
| AudioData nk::audio::audioread | ( | const std::string & | path, |
| int64_t | startSample = 1, | ||
| int64_t | endSample = -1, | ||
| bool | nativeType = false, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Reads audio file from filesystem ([y, Fs] = audioread(filename)).
| path | Path to audio file. |
| startSample | 1-based start frame index (default: 1). |
| endSample | 1-based end frame index (default: -1 for all). |
| nativeType | True to return integer types, false for normalized [-1.0, 1.0] double. |
| mr | Memory resource for output allocation. |
| AudioData nk::audio::audioreadFromBytes | ( | const std::string & | bytes, |
| int64_t | startSample = 1, | ||
| int64_t | endSample = -1, | ||
| bool | nativeType = false, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Decodes audio from string memory buffer (audioread(bytes)).
| bytes | Byte string containing audio file contents. |
| startSample | 1-based start sample index. |
| endSample | 1-based end sample index (-1 for end of stream). |
| nativeType | True to return integer types, false for normalized [-1.0, 1.0] double. |
| mr | Memory resource for output allocation. |
| AudioData nk::audio::audioreadFromBytes | ( | const std::uint8_t * | data, |
| std::size_t | len, | ||
| int64_t | startSample = 1, | ||
| int64_t | endSample = -1, | ||
| bool | nativeType = false, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Decodes audio from raw memory buffer, sniffing format automatically ([y, Fs] = audioread(bytes)).
| data | Pointer to raw audio file bytes. |
| len | Length of buffer in bytes. |
| startSample | 1-based start sample index. |
| endSample | 1-based end sample index (-1 for end of stream). |
| nativeType | True to return integer types, false for normalized [-1.0, 1.0] double. |
| mr | Memory resource for output allocation. |
| void nk::audio::audiowrite | ( | const std::string & | path, |
| const Value & | y, | ||
| double | sampleRate, | ||
| uint16_t | bitsPerSample = 16, | ||
| const std::string & | title = "", | ||
| const std::string & | artist = "", | ||
| const std::string & | comment = "" ) |
Writes audio data matrix y to file on disk (audiowrite(filename, y, Fs)).
| path | Path to output audio file (e.g. .wav, .aiff, .au). |
| y | Audio matrix N x C. |
| sampleRate | Sampling rate in Hz. |
| bitsPerSample | Quantization bit depth (default 16). |
| title | Optional track title metadata. |
| artist | Optional artist metadata. |
| comment | Optional comment metadata. |
| std::vector< std::uint8_t > nk::audio::audiowriteToBytes | ( | const Value & | y, |
| double | sampleRate, | ||
| const std::string & | format = "wav", | ||
| uint16_t | bitsPerSample = 16, | ||
| const std::string & | title = "", | ||
| const std::string & | artist = "", | ||
| const std::string & | comment = "" ) |
Encodes audio matrix y into memory byte buffer (bytes = audiowrite(y, Fs, ...)).
| y | Audio sample matrix N x C. |
| sampleRate | Sampling rate in Hz. |
| format | Audio format string ("wav", "aiff", "au"). |
| bitsPerSample | Bit depth (16, 24, 32). |
| title | Optional metadata title. |
| artist | Optional metadata artist. |
| comment | Optional metadata comment. |
| Value nk::audio::cepstralCoefficients | ( | const Value & | S, |
| int | numCoeffs = 13, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Generic cepstral coefficient extractor.
Pipeline: log10 / cubic-root rectification → DCT-II → keep first numCoeffs coefficients. Input S is L × M (filterbank bands × frames). Output is M × numCoeffs (frames first).
| S | L × M real filterbank energy matrix. |
| numCoeffs | Number of cepstral coefficients to keep. Default 13. |
| mr | Memory resource (nullptr → process default). |
| std::tuple< Value, Value, Value > nk::audio::gtcc | ( | const Value & | x, |
| double | fs, | ||
| int | numCoeffs = 13, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Gammatone cepstral coefficients (GTCC).
Same STFT + cepstralCoefficients pipeline as mfcc but with an ERB-spaced Patterson-Holdsworth gammatone filterbank (Slaney 1993): cascaded 4-stage biquad frequency response, FrequencyRange = [50, fs/2], NumFilters = ceil(hz2erb(fs/2) - hz2erb(50)).
| x | Real 1-D audio signal. |
| fs | Sample rate in Hz. |
| numCoeffs | Number of cepstral coefficients. Default 13. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::harmonicRatio | ( | const Value & | x, |
| double | fs, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Harmonic ratio — strength of harmonic content per frame.
Computed as the maximum of the normalised autocorrelation function over the search range, clipped to [0, 1]. High values indicate periodic (tonal) content; low values indicate noise. Window defaults: WindowLength = round(0.03 · fs), OverlapLength = round(0.02 · fs).
| x | Real 1-D audio signal. |
| fs | Sample rate in Hz. |
| mr | Memory resource (nullptr → process default). |
Hertz → Bark (Traunmüller 1990 with low/high-frequency corrections).
| hz | Frequency values in Hz. |
| mr | Memory resource (nullptr → process default). |
Hertz → ERB (Glasberg & Moore 1990).
Equivalent Rectangular Bandwidth scale used in psychoacoustic models.
| hz | Frequency values in Hz. |
| mr | Memory resource (nullptr → process default). |
Hertz → Mel (O'Shaughnessy 1987 default form).
\( m = 2595 \log_{10}(1 + f / 700) \)
| hz | Frequency values in Hz (real array). |
| mr | Memory resource (nullptr → process default). |
Mel → Hertz (inverse of hz2mel).
| mel | Mel-frequency values. |
| mr | Memory resource (nullptr → process default). |
| std::tuple< Value, Value, Value > nk::audio::melSpectrogram | ( | const Value & | x, |
| double | fs, | ||
| int | numBands = 32, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Mel-band power spectrogram.
Defaults:
| x | Real 1-D audio signal. |
| fs | Sample rate in Hz. |
| numBands | Number of mel bands. Default 32. |
| mr | Memory resource (nullptr → process default). |
| std::tuple< Value, Value, Value > nk::audio::mfcc | ( | const Value & | x, |
| double | fs, | ||
| int | numCoeffs = 13, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Mel-frequency cepstral coefficients (MFCC).
Pipeline:
| x | Real 1-D audio signal. |
| fs | Sample rate in Hz. |
| numCoeffs | Number of cepstral coefficients. Default 13. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::phon2sone | ( | const Value & | phon, |
| bool | standardIs532_2 = false, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Phon → Sone — loudness-level to loudness conversion.
Default standard ISO 532-1: closed-form piecewise power law. Pass standardIs532_2 = true to use ISO 532-2 (table lookup with PCHIP interpolation per Table 5, linear extrapolation beyond 120 phon).
| phon | Loudness level in phon. |
| standardIs532_2 | Use ISO 532-2 table form instead of 532-1. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::pitch | ( | const Value & | x, |
| double | fs, | ||
| double | minF = 50.0, | ||
| double | maxF = 400.0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Pitch via the Normalised Cross-correlation Function (the default estimator).
Per-frame f0 estimation via normalised autocorrelation, peak-picked within [minF, maxF]. Window defaults:
| x | Real 1-D audio signal. |
| fs | Sample rate in Hz. |
| minF | Minimum pitch search bound in Hz (default 50). |
| maxF | Maximum pitch search bound in Hz (default 400). |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::pitchSRH | ( | const Value & | x, |
| double | fs, | ||
| double | minF = 50.0, | ||
| double | maxF = 400.0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Summation of Residual Harmonics (Drugman & Alwan 2011).
LPC inverse filtering + harmonic summation on the residual spectrum. Same arg semantics as pitch.
| x | See pitch. |
| fs | See pitch. |
| minF | See pitch. |
| maxF | See pitch. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralCentroid | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral centroid — power-weighted mean frequency.
\( \mu_X = \sum_k f_k \cdot X_k \big/ \sum_k X_k \)
| x | Time signal or M × N spectrum (see file note). |
| f | Sample rate or frequency vector (see file note). |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralCrest | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral crest — max(X) / mean(X) per frame.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralDecrease | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral decrease — slope-like measure relative to first bin.
\( d = \dfrac{1}{\sum_{k \ge 2} X_k}\,\sum_{k \ge 2} \dfrac{X_k - X_1}{k - 1} \)
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralEntropy | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral entropy — Shannon entropy of normalised spectrum.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralFlatness | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral flatness — geomean(X) / mean(X).
1 = white, 0 = tonal.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralFlux | ( | const Value & | x, |
| const Value & | f, | ||
| double | p = 2.0, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral flux — p-norm of frame-to-frame spectrum differences.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| p | Norm order (default 2 — Euclidean). |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralKurtosis | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral kurtosis — X-weighted 4th central moment.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralRolloffPoint | ( | const Value & | x, |
| const Value & | f, | ||
| double | percentile = 0.95, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral rolloff frequency.
f such that the cumulative spectral power below f equals percentile of the total power.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| percentile | Cumulative power fraction in (0, 1). Default 0.95. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralSkewness | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral skewness — X-weighted 3rd central moment.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralSlope | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral slope — least-squares slope of (f, X).
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |
| Value nk::audio::spectralSpread | ( | const Value & | x, |
| const Value & | f, | ||
| std::pmr::memory_resource * | mr = nullptr ) |
Spectral spread — power-weighted std around the centroid.
| x | Time signal or spectrum. |
| f | Sample rate or frequency vector. |
| mr | Memory resource (nullptr → process default). |