Class thl::dsp::utils::HannWindow#

class HannWindow#

HannWindow envelope generator class.

This class implements a Hann (raised cosine) window function for granular synthesis. It provides a smooth bell-shaped envelope that is particularly well-suited for grain envelopes in granular synthesis as it eliminates discontinuities at the grain boundaries.

Public Types

enum class State#

HannWindow envelope state.

Values:

enumerator IDLE#
enumerator ACTIVE#

Public Functions

HannWindow()#
void set_duration(float duration_ms)#

Set the total window duration.

Parameters:

duration_ms – Duration of the window in milliseconds

void set_sample_rate(float sample_rate)#

Set sample rate for timing calculations.

Parameters:

sample_rate – The sample rate in Hz

void start()#

Start the envelope.

void reset()#

Reset the envelope to IDLE state.

float process()#

Process a single sample and return the envelope value at the current position.

Returns:

The current envelope amplitude (0.0-1.0)

float process_at_position(float position)#

Process a sample at a specific normalized position in the window.

Parameters:

position – Normalized position in the window (0.0-1.0)

Returns:

The envelope amplitude at the given position (0.0-1.0)

bool is_active() const#

Check if the envelope is active.

Returns:

True if the envelope is active

State get_state() const#

Get the current state of the envelope.

Returns:

The current state