Vital
Loading...
Searching...
No Matches
legato_filter.cpp
Go to the documentation of this file.
1
6#include "legato_filter.h"
7#include "utils.h"
8
9namespace vital {
10
12 : Processor(kNumInputs, kNumOutputs, true),
13 last_value_(kVoiceOff) {
14 }
15
16 void LegatoFilter::process(int num_samples) {
17 // Clear any previous triggers on the output before processing.
19
20 // Get the current trigger mask from the input trigger source.
21 poly_mask trigger_mask = input(kTrigger)->source->trigger_mask;
22 if (trigger_mask.anyMask() == 0)
23 return; // No triggers to process, so return early.
24
25 // Retrieve the trigger value and offset from the input.
26 poly_float trigger_value = input(kTrigger)->source->trigger_value;
27 poly_int trigger_offset = input(kTrigger)->source->trigger_offset;
28
29 // Determine which voices should be retriggered considering the legato state.
30 // legato_mask will be true when we need to block retriggers due to legato rules.
31 poly_mask legato_mask = poly_float::equal(input(kLegato)->at(0), 0.0f);
32 legato_mask |= poly_float::notEqual(trigger_value, kVoiceOn);
33 legato_mask |= poly_float::notEqual(last_value_, kVoiceOn);
34 trigger_mask &= legato_mask;
35
36 // Trigger the output when conditions are met.
37 output(kRetrigger)->trigger(trigger_mask, trigger_value, trigger_offset);
38
39 // Update the last_value_ based on which voices triggered.
40 last_value_ = utils::maskLoad(last_value_, trigger_value, trigger_mask);
41 }
42} // namespace vital
LegatoFilter()
Constructs a new LegatoFilter processor.
Definition legato_filter.cpp:11
@ kRetrigger
Output trigger signal after legato filtering.
Definition legato_filter.h:38
void process(int num_samples) override
Processes a block of samples and applies legato filtering to the trigger signals.
Definition legato_filter.cpp:16
@ kTrigger
Input trigger signal for the voice.
Definition legato_filter.h:29
@ kLegato
Input that determines if legato is enabled.
Definition legato_filter.h:28
Base class for all signal-processing units in Vital.
Definition processor.h:212
force_inline Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
Defines the LegatoFilter class used to handle legato triggering behavior in a voice.
force_inline poly_float maskLoad(poly_float zero_value, poly_float one_value, poly_mask reset_mask)
Selects between two values (zero_value or one_value) based on a mask in each lane.
Definition poly_utils.h:351
Contains classes and functions used within the Vital synthesizer framework.
@ kVoiceOn
Definition common.h:77
@ kVoiceOff
Definition common.h:80
const Output * source
The output from which this input reads samples.
Definition processor.h:134
force_inline void trigger(poly_mask mask, poly_float value, poly_int offset)
Sets trigger values (mask, trigger value, and offset).
Definition processor.h:63
poly_int trigger_offset
Sample offset (per voice) for triggers.
Definition processor.h:117
force_inline void clearTrigger()
Clears the trigger mask, value, and offset.
Definition processor.h:72
poly_mask trigger_mask
Mask for triggered voices.
Definition processor.h:115
poly_float trigger_value
Trigger values for voices.
Definition processor.h:116
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
static force_inline mask_simd_type vector_call equal(simd_type one, simd_type two)
Compares two SIMD float registers for equality, element-wise.
Definition poly_values.h:954
static force_inline mask_simd_type vector_call notEqual(simd_type one, simd_type two)
Compares two SIMD float registers for non-equality, element-wise.
Definition poly_values.h:1003
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56
static force_inline uint32_t vector_call anyMask(simd_type value)
Returns a bitmask that indicates which bytes/elements in the register are non-zero.
Definition poly_values.h:352
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...