Class thl::dsp::slicing::TransientSlicer#

class TransientSlicer#

Offline transient-based slicing of a sample into N slices.

Analysis

Band-energy flux: mono mixdown, split into low / mid / high with two state-variable filters (crossovers m_low_hz, m_high_hz), RMS per hop over a trailing window, log-compressed per band, positive first difference summed over the bands, a local mean subtracted and half-wave rectified.

Picking

The N-1 strongest local maxima at least m_min_slice_seconds apart (and from both ends) become boundaries. With the audio at hand each is refined: moved to the sharpest short-time energy rise in its hop, back up to m_move_back_seconds to the quietest frame before the attack, and onto a zero crossing within m_zero_cross_seconds. With fewer peaks than needed, the longest gaps are split evenly. Silence or a sample too short for N slices gives the grid.

Real-Time Safety

Not real-time safe: allocates and scans the whole sample. Run it on a loader or worker thread and hand the resulting SliceMap over.

Public Functions

TransientSlicer() = default#
inline explicit TransientSlicer(const Settings &settings)#
inline const Settings &settings() const#
TransientAnalysis analyse(const core::BufferF &buffer, double sample_rate) const#

Onset-strength curve of buffer (all channels mixed to mono).

SliceMap pick(const TransientAnalysis &analysis, size_t count, const core::BufferF *refine = nullptr) const#

Pick count slices from an analysis.

Parameters:

refine – The analysed audio, to refine boundaries against (see class); nullptr keeps the hop-resolution peaks.

Returns:

A valid map of count slices (clamped to 1..k_max_slices and to the analysed frame count), or an empty map (m_count == 0) when the analysis has no frames to cut.

struct Settings#

Public Members

size_t m_hop_frames = {256}#
size_t m_window_hops = {4}#

Trailing RMS window, in hops.

float m_low_hz = {160.0f}#
float m_high_hz = {1600.0f}#
double m_log_gain = {1000.0}#

log1p(gain * rms).

size_t m_local_mean_hops = {10}#
double m_min_slice_seconds = {0.030}#
double m_move_back_seconds = {0.005}#
double m_zero_cross_seconds = {0.002}#
double m_energy_window_seconds = {0.001}#