Vital
Loading...
Searching...
No Matches
trigger_random.cpp
Go to the documentation of this file.
1#include "trigger_random.h"
2
3#include <cstdlib>
4
5namespace vital {
6
8 Processor(1, 1, true), // 1 input (trigger), 1 output, control-rate capable
9 value_(0.0f),
10 random_generator_(0.0f, 1.0f) { }
11
12 void TriggerRandom::process(int /*num_samples*/) {
19 poly_mask trigger_mask = getResetMask(kReset);
20 if (trigger_mask.anyMask()) {
21 // Iterate through voices in pairs (assuming poly_float pack size)
22 for (int i = 0; i < poly_float::kSize; i += 2) {
23 // Check if this voice is triggered
24 if ((poly_float(1.0f) & trigger_mask)[i]) {
25 mono_float rand_value = random_generator_.next();
26 value_.set(i, rand_value);
27 value_.set(i + 1, rand_value);
28 }
29 }
30 }
31
32 output()->buffer[0] = value_;
33 }
34} // namespace vital
Base class for all signal-processing units in Vital.
Definition processor.h:212
force_inline poly_mask getResetMask(int input_index) const
Retrieves a mask indicating which voices triggered a note-on event. Compares the input's trigger_valu...
Definition processor.h:360
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
@ kReset
Definition trigger_random.h:23
TriggerRandom()
Constructs a TriggerRandom processor, initializing the output value and random generator.
Definition trigger_random.cpp:7
virtual void process(int num_samples) override
Processes a block of samples, updating the random output if a trigger event occurs.
Definition trigger_random.cpp:12
force_inline mono_float next()
Returns the next random float in [min, max].
Definition utils.h:85
Contains classes and functions used within the Vital synthesizer framework.
float mono_float
Definition common.h:33
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
force_inline void vector_call set(size_t index, float new_value) noexcept
Sets a specific element in the SIMD register.
Definition poly_values.h:1182
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