32#ifndef MINIDSP_VERSION_MAJOR
33#define MINIDSP_VERSION_MAJOR 0
35#ifndef MINIDSP_VERSION_MINOR
36#define MINIDSP_VERSION_MINOR 0
38#ifndef MINIDSP_VERSION_PATCH
39#define MINIDSP_VERSION_PATCH 0
41#ifndef MINIDSP_VERSION
42#define MINIDSP_VERSION "0.0.0"
79 const char *func_name,
110#define M_PI 3.14159265358979323846
124double MD_dot(
const double *a,
const double *b,
unsigned N);
133double MD_entropy(
const double *a,
unsigned N,
bool clip);
136double MD_energy(
const double *a,
unsigned N);
139double MD_power(
const double *a,
unsigned N);
170double MD_rms(
const double *a,
unsigned N);
229 double *out,
unsigned max_lag);
260 unsigned min_distance,
unsigned *peaks_out,
261 unsigned *num_peaks_out);
294 double min_freq_hz,
double max_freq_hz);
328double MD_f0_fft(
const double *signal,
unsigned N,
330 double min_freq_hz,
double max_freq_hz);
357void MD_mix(
const double *a,
const double *b,
double *out,
358 unsigned N,
double w_a,
double w_b);
391 unsigned delay_samples,
double feedback,
392 double dry,
double wet);
420void MD_tremolo(
const double *in,
double *out,
unsigned N,
421 double rate_hz,
double depth,
double sample_rate);
449 unsigned delay_samples,
double feedback,
450 double dry,
double wet);
477 const double *kernel,
unsigned kernel_len,
493 unsigned window_len,
double *out);
509 const double *coeffs,
unsigned num_taps,
525 const double *kernel,
unsigned kernel_len,
554 double cutoff_freq,
double sample_rate,
566 double oldmin,
double oldmax,
567 double newmin,
double newmax);
571 double oldmin,
double oldmax,
572 double newmin,
double newmax);
580 double newmin,
double newmax);
587 unsigned N,
double dblevel);
810void MD_stft(
const double *signal,
unsigned signal_len,
811 unsigned N,
unsigned hop,
840 double min_freq_hz,
double max_freq_hz,
841 double *filterbank_out);
862 double sample_rate,
unsigned num_mels,
863 double min_freq_hz,
double max_freq_hz,
889void MD_mfcc(
const double *signal,
unsigned N,
891 unsigned num_mels,
unsigned num_coeffs,
892 double min_freq_hz,
double max_freq_hz,
937 double cutoff_hz,
double sample_rate);
1057void MD_sine_wave(
double *output,
unsigned N,
double amplitude,
1058 double freq,
double sample_rate);
1109void MD_impulse(
double *output,
unsigned N,
double amplitude,
unsigned position);
1141 double f_start,
double f_end,
double sample_rate);
1175void MD_chirp_log(
double *output,
unsigned N,
double amplitude,
1176 double f_start,
double f_end,
double sample_rate);
1210 double freq,
double sample_rate);
1240 double freq,
double sample_rate);
1305 double base_freq,
double sample_rate,
1306 double rate_octaves_per_sec,
unsigned num_octaves);
1371unsigned MD_dtmf_detect(
const double *signal,
unsigned signal_len,
1406 unsigned tone_ms,
unsigned pause_ms);
1425 unsigned tone_ms,
unsigned pause_ms);
1467 unsigned margin,
int weightfunc,
1482int MD_get_delay(
const double *siga,
const double *sigb,
unsigned N,
1483 double *ent,
unsigned margin,
int weightfunc);
1495void MD_gcc(
const double *siga,
const double *sigb,
unsigned N,
1496 double *lagvals,
int weightfunc);
1530 double freq_lo,
double freq_hi,
1531 double duration_sec,
double sample_rate);
1538#define MD_STEG_LSB 0
1540#define MD_STEG_FREQ_BAND 1
1556#define MD_STEG_SPECTEXT 2
1559#define MD_STEG_TYPE_TEXT 0
1561#define MD_STEG_TYPE_BINARY 1
1571unsigned MD_steg_capacity(
unsigned signal_len,
double sample_rate,
int method);
1611 unsigned signal_len,
double sample_rate,
1612 const char *message,
int method);
1637 char *message_out,
unsigned max_msg_len,
1666 unsigned signal_len,
double sample_rate,
1667 const unsigned char *data,
unsigned data_len,
1693 unsigned char *data_out,
unsigned max_len,
1725 double sample_rate,
int *payload_type_out);
1747 double in_rate,
double out_rate);
1778unsigned MD_resample(
const double *input,
unsigned input_len,
1779 double *output,
unsigned max_output_len,
1780 double in_rate,
double out_rate,
1781 unsigned num_zero_crossings,
double kaiser_beta);
1789#define MD_VAD_FEAT_ENERGY 0
1790#define MD_VAD_FEAT_ZCR 1
1791#define MD_VAD_FEAT_SPECTRAL_ENTROPY 2
1792#define MD_VAD_FEAT_SPECTRAL_FLATNESS 3
1793#define MD_VAD_FEAT_BAND_ENERGY_RATIO 4
1794#define MD_VAD_NUM_FEATURES 5
1907 unsigned N,
double sample_rate);
1942 unsigned N,
double sample_rate,
1943 double *score_out,
double *features_out);
void MD_Gen_Kaiser_Win(double *out, unsigned n, double beta)
Generate a Kaiser window of length n with shape parameter beta.
void MD_chirp_linear(double *output, unsigned N, double amplitude, double f_start, double f_end, double sample_rate)
Generate a linear chirp (swept sine with linearly increasing frequency).
#define MD_VAD_NUM_FEATURES
Total number of features.
double MD_power(const double *a, unsigned N)
Compute signal power: energy divided by the number of samples.
unsigned MD_steg_capacity(unsigned signal_len, double sample_rate, int method)
Compute the maximum message length (in bytes) that can be hidden.
unsigned MD_steg_encode_bytes(const double *host, double *output, unsigned signal_len, double sample_rate, const unsigned char *data, unsigned data_len, int method)
Encode arbitrary binary data into a host audio signal.
void MD_power_spectral_density(const double *signal, unsigned N, double *psd_out)
Compute the power spectral density (PSD) of a real-valued signal.
unsigned MD_dtmf_detect(const double *signal, unsigned signal_len, double sample_rate, MD_DTMFTone *tones_out, unsigned max_tones)
Detect DTMF tones in an audio signal.
MD_ErrorCode
Error codes reported by miniDSP when a precondition is violated.
@ MD_ERR_INVALID_SIZE
A size or count argument is invalid (e.g.
@ MD_ERR_INVALID_RANGE
A range or bound is invalid (e.g.
@ MD_ERR_ALLOC_FAILED
A memory allocation failed.
@ MD_ERR_NULL_POINTER
A required pointer argument is NULL.
void MD_vad_default_params(MD_vad_params *params)
Populate a VAD params struct with optimized defaults.
void MD_white_noise(double *output, unsigned N, double amplitude, unsigned seed)
Generate Gaussian white noise.
unsigned MD_resample_output_len(unsigned input_len, double in_rate, double out_rate)
Compute the output buffer size needed for resampling.
void MD_dtmf_generate(double *output, const char *digits, double sample_rate, unsigned tone_ms, unsigned pause_ms)
Generate a DTMF tone sequence.
void MD_sine_wave(double *output, unsigned N, double amplitude, double freq, double sample_rate)
Generate a sine wave.
unsigned MD_steg_decode_bytes(const double *stego, unsigned signal_len, double sample_rate, unsigned char *data_out, unsigned max_len, int method)
Decode binary data from a stego audio signal.
void MD_impulse(double *output, unsigned N, double amplitude, unsigned position)
Generate a discrete impulse (Kronecker delta).
void MD_Gen_Blackman_Win(double *out, unsigned n)
Generate a Blackman window of length n.
double MD_zero_crossing_rate(const double *a, unsigned N)
Compute the zero-crossing rate of a signal.
void MD_scale_vec(double *in, double *out, unsigned N, double oldmin, double oldmax, double newmin, double newmax)
Map every element of a vector from one range to another.
void MD_mel_energies(const double *signal, unsigned N, double sample_rate, unsigned num_mels, double min_freq_hz, double max_freq_hz, double *mel_out)
Compute mel-band energies from a single frame.
void MD_mfcc(const double *signal, unsigned N, double sample_rate, unsigned num_mels, unsigned num_coeffs, double min_freq_hz, double max_freq_hz, double *mfcc_out)
Compute mel-frequency cepstral coefficients (MFCCs) from a single frame.
void MD_shepard_tone(double *output, unsigned N, double amplitude, double base_freq, double sample_rate, double rate_octaves_per_sec, unsigned num_octaves)
Generate a Shepard tone — the auditory illusion of endlessly rising or falling pitch.
void MD_Gen_Hamming_Win(double *out, unsigned n)
Generate a Hamming window of length n.
void MD_phase_spectrum(const double *signal, unsigned N, double *phase_out)
Compute the one-sided phase spectrum of a real signal.
unsigned MD_steg_decode(const double *stego, unsigned signal_len, double sample_rate, char *message_out, unsigned max_msg_len, int method)
Decode a secret message from a stego audio signal.
void MD_convolution_fft_ola(const double *signal, unsigned signal_len, const double *kernel, unsigned kernel_len, double *out)
Full linear convolution using FFT overlap-add (offline).
double MD_f0_fft(const double *signal, unsigned N, double sample_rate, double min_freq_hz, double max_freq_hz)
Estimate the fundamental frequency (F0) using FFT peak picking.
int MD_vad_process_frame(MD_vad_state *state, const double *signal, unsigned N, double sample_rate, double *score_out, double *features_out)
Process one audio frame and return a binary speech decision.
MD_GCC_WEIGHTING_TYPE
Weighting types for Generalized Cross-Correlation.
@ SIMP
Simple 1/N weighting (basic cross-correlation).
@ PHAT
Phase Transform weighting (sharper peaks, more robust to noise).
double MD_bessel_i0(double x)
Zeroth-order modified Bessel function of the first kind, .
void MD_tremolo(const double *in, double *out, unsigned N, double rate_hz, double depth, double sample_rate)
Tremolo effect (amplitude modulation by a sinusoidal LFO).
unsigned MD_convolution_num_samples(unsigned signal_len, unsigned kernel_len)
Compute the output length of a full linear convolution.
unsigned MD_spectrogram_text(double *output, unsigned max_len, const char *text, double freq_lo, double freq_hi, double duration_sec, double sample_rate)
Synthesise audio that displays readable text in a spectrogram.
double MD_scale(double in, double oldmin, double oldmax, double newmin, double newmax)
Map a single value from one range to another.
void(* MD_ErrorHandler)(MD_ErrorCode code, const char *func_name, const char *message)
Signature for a user-installed error handler.
void MD_Gen_Hann_Win(double *out, unsigned n)
Generate a Hanning (Hann) window of length n.
double MD_energy(const double *a, unsigned N)
Compute signal energy: sum of squared samples.
unsigned MD_resample(const double *input, unsigned input_len, double *output, unsigned max_output_len, double in_rate, double out_rate, unsigned num_zero_crossings, double kaiser_beta)
Resample a signal from one sample rate to another using polyphase sinc interpolation.
void MD_stft(const double *signal, unsigned signal_len, unsigned N, unsigned hop, double *mag_out)
Compute the Short-Time Fourier Transform (STFT) of a real-valued signal.
void MD_design_lowpass_fir(double *coeffs, unsigned num_taps, double cutoff_freq, double sample_rate, double kaiser_beta)
Design a Kaiser-windowed sinc lowpass FIR filter.
void MD_peak_detect(const double *a, unsigned N, double threshold, unsigned min_distance, unsigned *peaks_out, unsigned *num_peaks_out)
Detect peaks (local maxima) in a signal.
unsigned MD_dtmf_signal_length(unsigned num_digits, double sample_rate, unsigned tone_ms, unsigned pause_ms)
Calculate the number of samples needed for MD_dtmf_generate().
unsigned MD_steg_encode(const double *host, double *output, unsigned signal_len, double sample_rate, const char *message, int method)
Encode a secret message into a host audio signal.
void MD_mix(const double *a, const double *b, double *out, unsigned N, double w_a, double w_b)
Mix (weighted sum) two signals.
double MD_entropy(const double *a, unsigned N, bool clip)
Compute the normalized entropy of a distribution.
int MD_steg_detect(const double *signal, unsigned signal_len, double sample_rate, int *payload_type_out)
Detect which steganography method (if any) was used to encode a signal.
double MD_f0_autocorrelation(const double *signal, unsigned N, double sample_rate, double min_freq_hz, double max_freq_hz)
Estimate the fundamental frequency (F0) using autocorrelation.
double MD_sinc(double x)
Normalized sinc function: .
void MD_lowpass_brickwall(double *signal, unsigned len, double cutoff_hz, double sample_rate)
Apply a brickwall lowpass filter to a signal in-place.
void MD_fir_filter(const double *signal, unsigned signal_len, const double *coeffs, unsigned num_taps, double *out)
Apply a causal FIR filter with arbitrary coefficients.
void MD_shutdown(void)
Free all internally cached FFT plans and buffers.
double MD_power_db(const double *a, unsigned N)
Compute signal power in decibels: 10 * log10(power).
void MD_gcc(const double *siga, const double *sigb, unsigned N, double *lagvals, int weightfunc)
Compute the full generalized cross-correlation between two signals.
void MD_convolution_time(const double *signal, unsigned signal_len, const double *kernel, unsigned kernel_len, double *out)
Time-domain full linear convolution (direct sum-of-products).
void MD_set_error_handler(MD_ErrorHandler handler)
Install a custom error handler.
void MD_get_multiple_delays(const double **sigs, unsigned M, unsigned N, unsigned margin, int weightfunc, int *outdelays)
Estimate delays between a reference signal and M-1 other signals.
void MD_delay_echo(const double *in, double *out, unsigned N, unsigned delay_samples, double feedback, double dry, double wet)
Delay line / echo effect using a circular buffer with feedback.
double MD_dot(const double *a, const double *b, unsigned N)
Compute the dot product of two vectors.
void MD_Gen_Rect_Win(double *out, unsigned n)
Generate a rectangular window of length n (all ones).
void MD_sawtooth_wave(double *output, unsigned N, double amplitude, double freq, double sample_rate)
Generate a sawtooth wave.
void MD_moving_average(const double *signal, unsigned signal_len, unsigned window_len, double *out)
Causal moving-average FIR filter with zero-padded startup.
void MD_magnitude_spectrum(const double *signal, unsigned N, double *mag_out)
Compute the magnitude spectrum of a real-valued signal.
void MD_mel_filterbank(unsigned N, double sample_rate, unsigned num_mels, double min_freq_hz, double max_freq_hz, double *filterbank_out)
Build a mel-spaced triangular filterbank matrix.
void MD_comb_reverb(const double *in, double *out, unsigned N, unsigned delay_samples, double feedback, double dry, double wet)
Comb-filter reverb (feedback comb filter with dry/wet mix).
void MD_vad_calibrate(MD_vad_state *state, const double *signal, unsigned N, double sample_rate)
Feed a known-silence frame to seed the adaptive normalization.
void MD_autocorrelation(const double *a, unsigned N, double *out, unsigned max_lag)
Compute the normalised autocorrelation of a signal.
unsigned MD_stft_num_frames(unsigned signal_len, unsigned N, unsigned hop)
Compute the number of STFT frames for the given signal length and parameters.
void MD_fit_within_range(double *in, double *out, unsigned N, double newmin, double newmax)
Fit values within [newmin, newmax].
void MD_vad_init(MD_vad_state *state, const MD_vad_params *params)
Initialize VAD state from params.
double MD_rms(const double *a, unsigned N)
Compute the root mean square (RMS) of a signal.
void MD_square_wave(double *output, unsigned N, double amplitude, double freq, double sample_rate)
Generate a square wave.
int MD_get_delay(const double *siga, const double *sigb, unsigned N, double *ent, unsigned margin, int weightfunc)
Estimate the delay between two signals.
void MD_adjust_dblevel(const double *in, double *out, unsigned N, double dblevel)
Automatic Gain Control: scale a signal so its power matches the requested dB level,...
void MD_chirp_log(double *output, unsigned N, double amplitude, double f_start, double f_end, double sample_rate)
Generate a logarithmic chirp (swept sine with exponentially increasing frequency).
A single detected DTMF tone with timing information.
char digit
Decoded digit: '0'–'9', 'A'–'D', '*', or '#'.
double end_s
Tone offset time in seconds.
double start_s
Tone onset time in seconds.
Parameters for the VAD detector.
double threshold
Decision threshold (0.0–1.0).
double weights[MD_VAD_NUM_FEATURES]
Per-feature weights for scoring.
double band_high_hz
Upper bound of speech band (Hz).
unsigned onset_frames
Consecutive above-threshold frames before speech.
double band_low_hz
Lower bound of speech band (Hz).
double adaptation_rate
EMA rate for min/max tracking (0.0–1.0).
unsigned hangover_frames
Extra speech frames after score drops.
Internal state for the VAD detector.
unsigned onset_counter
Consecutive above-threshold count.
double feat_max[MD_VAD_NUM_FEATURES]
EMA-tracked feature maximums.
MD_vad_params params
Copy of caller params.
int current_decision
Current speech decision (0 or 1).
double feat_min[MD_VAD_NUM_FEATURES]
EMA-tracked feature minimums.
unsigned hangover_counter
Remaining hangover frames.
unsigned frames_processed
Total frames seen.