sp500/log_mel.h File Reference#
|
Mobilint REGULUS v4.1
SP500 DSP API
|
Whisper-style log-mel spectrogram on the SP500 DSP. More...
#include <sp500/dsp.h>Go to the source code of this file.
Data Structures | |
| struct | sp500_log_mel_params |
| Front-end parameters. More... | |
| struct | sp500_log_mel_result |
| Values reported by a log-mel call. More... | |
Macros | |
| #define | SP500_LOG_MEL_MAX_MELS 256 |
| Largest supported mel bin count. | |
| #define | SP500_LOG_MEL_MAX_FFT 2048 |
| Largest supported FFT size. | |
Functions | |
| void | sp500_log_mel_params_init (sp500_log_mel_params *params) |
Fill params with the Whisper defaults documented above. | |
| int32_t | sp500_log_mel_num_frames (int32_t n_samples, int32_t hop_length) |
Frames produced for n_samples: n_samples / hop_length, or 0 for non-positive arguments. Use it to size the feature buffer. | |
| int32_t | sp500_log_mel_num_freq (int32_t n_fft) |
Frequency bins for n_fft: n_fft / 2 + 1, or 0 if n_fft is not supported. Use it to size a custom mel_filters bank. | |
| sp500_status | sp500_log_mel (const sp500_buffer *audio, const sp500_log_mel_params *params, sp500_buffer *features, sp500_log_mel_result *result) |
| Compute the log-mel spectrogram of float32 PCM on the DSP. | |
| sp500_status | sp500_log_mel_cpu (const float *audio, const sp500_log_mel_params *params, float *features, int32_t features_count, sp500_log_mel_result *result) |
| Host CPU reference for sp500_log_mel(): same tables, same per-frame maths, no DSP involved. | |
Detailed Description
Whisper-style log-mel spectrogram on the SP500 DSP.
Turns float32 PCM into the log-mel spectrogram that Whisper and Qwen3-ASR encoders consume. The maths follows the Hugging Face WhisperFeatureExtractor exactly: reflect-padded frames of n_fft samples every hop_length, a periodic Hann window, the power spectrum, a slaney mel filter bank, log10(max(1e-10, mel)), then optionally the Whisper normalisation (clamp at max - 8, then (x + 4) / 4).
- Output layout
- The result is frame-major: features[t * n_mels + m] for t < n_frames, with n_frames = n_samples / hop_length - the trailing centred frame is dropped, as Hugging Face does. This is the [n_frames, n_mels] layout the MXQ Whisper models take. Hugging Face's own input_features is the transpose.
- Example
- sp500_dsp_open(0);p.n_samples = 16000 * 30; // 30 s at 16 kHz{// feats.data holds r.n_frames * p.n_mels floats, frame-major.}sp500_buffer_release(&feats);sp500_buffer sp500_buffer_alloc(uint32_t size, uint32_t alignment)Allocate a zero-copy buffer in shared memory.Definition dsp.h:286sp500_status sp500_dsp_open(uint32_t timeout_ms)Attach to the DSP. Must succeed before any other DSP call.void sp500_buffer_release(sp500_buffer *buffer)Release a buffer and reset it to unused.Definition dsp.h:316sp500_buffer sp500_buffer_wrap(void *data, uint32_t size)Wrap memory you already own. The call stages one copy in each direction; nothing is taken over and no...Definition dsp.h:302void sp500_log_mel_params_init(sp500_log_mel_params *params)Fill params with the Whisper defaults documented above.sp500_status sp500_log_mel(const sp500_buffer *audio, const sp500_log_mel_params *params, sp500_buffer *features, sp500_log_mel_result *result)Compute the log-mel spectrogram of float32 PCM on the DSP.int32_t sp500_log_mel_num_frames(int32_t n_samples, int32_t hop_length)Frames produced for n_samples: n_samples / hop_length, or 0 for non-positive arguments....
- Note
- A 30 s clip is a few thousand frames of DSP work. If a call returns SP500_ERR_TIMEOUT, raise the deadline with sp500_set_dsp_timeout_ms() rather than retrying - see the warning on that function.
Definition in file log_mel.h.
Macro Definition Documentation
◆ SP500_LOG_MEL_MAX_MELS
| #define SP500_LOG_MEL_MAX_MELS 256 |
◆ SP500_LOG_MEL_MAX_FFT
| #define SP500_LOG_MEL_MAX_FFT 2048 |
Function Documentation
◆ sp500_log_mel()
| sp500_status sp500_log_mel | ( | const sp500_buffer * | audio, |
| const sp500_log_mel_params * | params, | ||
| sp500_buffer * | features, | ||
| sp500_log_mel_result * | result ) |
Compute the log-mel spectrogram of float32 PCM on the DSP.
- Parameters
-
audio Input samples; at least n_samples * sizeof(float) bytes. 16 kHz mono for Whisper. params Front-end parameters; see sp500_log_mel_params. features Receives n_frames * n_mels float32, frame-major; at least n_frames * n_mels * sizeof(float) bytes. result Receives the frame count and peak. May be NULL.
- Returns
- SP500_OK on success. SP500_ERR_UNSUPPORTED for an
n_fftthe DSP cannot transform, or for a mel bank it cannot run - one whose weights are all zero because the frequency range covers no FFT bin, or one too dense to describe. SP500_ERR_INVALID_ARG for any other bad parameter, SP500_ERR_BUFFER_TOO_SMALL for an undersized buffer, SP500_ERR_NO_MEMORY if shared memory is exhausted, SP500_ERR_NOT_READY, SP500_ERR_TIMEOUT or SP500_ERR_DSP.
- Note
- n_samples < hop_length yields zero frames. That is reported as SP500_OK with result->n_frames == 0 and nothing written.
◆ sp500_log_mel_cpu()
| sp500_status sp500_log_mel_cpu | ( | const float * | audio, |
| const sp500_log_mel_params * | params, | ||
| float * | features, | ||
| int32_t | features_count, | ||
| sp500_log_mel_result * | result ) |
Host CPU reference for sp500_log_mel(): same tables, same per-frame maths, no DSP involved.
Useful during bring-up to check the DSP result, and as a fallback when the DSP is busy. It does not require sp500_dsp_open().
- Parameters
-
audio params->n_samples float32 samples. params The same parameters the DSP call would take. features Receives n_frames * n_mels float32, frame-major. features_count Number of floats featurescan hold.result Receives the frame count and peak. May be NULL; host_seconds is the CPU time of this call.
- Returns
- SP500_OK, SP500_ERR_INVALID_ARG, SP500_ERR_UNSUPPORTED (the same
n_fftand mel-bank cases as the DSP call), SP500_ERR_BUFFER_TOO_SMALL or SP500_ERR_NO_MEMORY. It returns the same status as sp500_log_mel() for the same parameters.
Generated by