Vital
Loading...
Searching...
No Matches
value.cpp
Go to the documentation of this file.
1
6#include "value.h"
7#include "utils.h"
8
9namespace vital {
10
11 Value::Value(poly_float value, bool control_rate) : Processor(kNumInputs, 1, control_rate), value_(value) {
12 // Initialize output buffer with the initial value.
13 for (int i = 0; i < output()->buffer_size; ++i)
14 output()->buffer[i] = value_;
15 }
16
17 void Value::set(poly_float value) {
18 // Update the internal value and refill the output buffer.
19 value_ = value;
20 for (int i = 0; i < output()->buffer_size; ++i)
21 output()->buffer[i] = value;
22 }
23
24 void Value::process(int num_samples) {
25 // Check for trigger to update the value.
26 poly_mask trigger_mask = input(kSet)->source->trigger_mask;
27 if (trigger_mask.anyMask()) {
28 poly_float trigger_value = input(kSet)->source->trigger_value;
29 value_ = utils::maskLoad(value_, trigger_value, trigger_mask);
30 }
31
32 // Write the current value to all samples.
33 poly_float* dest = output()->buffer;
34 for (int i = 0; i < num_samples; ++i)
35 dest[i] = value_;
36 }
37
38 void Value::setOversampleAmount(int oversample) {
40 // After changing oversampling, ensure output is still correct.
41 for (int i = 0; i < output()->buffer_size; ++i)
42 output()->buffer[i] = value_;
43 }
44
45 void cr::Value::process(int num_samples) {
46 // At control rate, typically num_samples = 1.
47 poly_mask trigger_mask = input(kSet)->source->trigger_mask;
48 if (trigger_mask.anyMask()) {
49 poly_float trigger_value = input(kSet)->source->trigger_value;
50 value_ = utils::maskLoad(value_, trigger_value, trigger_mask);
51 }
52
53 // Only one sample at control rate.
54 output()->buffer[0] = value_;
55 }
56} // namespace vital
Base class for all signal-processing units in Vital.
Definition processor.h:212
virtual void setOversampleAmount(int oversample)
Sets the oversampling amount and updates the effective sample rate.
Definition processor.h:293
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
@ kSet
Index of the "set value" trigger input.
Definition value.h:27
virtual void setOversampleAmount(int oversample) override
Updates the oversampling amount and ensures the output buffer matches the stored value.
Definition value.cpp:38
virtual void set(poly_float value)
Sets the internal value to a new poly_float.
Definition value.cpp:17
virtual void process(int num_samples) override
Processes a block of samples, writing the constant value to the output buffer.
Definition value.cpp:24
poly_float value_
The constant output value.
Definition value.h:69
Value(poly_float value=0.0f, bool control_rate=false)
Constructs a Value processor.
Definition value.cpp:11
force_inline mono_float value() const
Returns the current mono_float value of the first lane.
Definition value.h:60
void process(int num_samples) override
Processes one "control-rate" sample, updating the output if triggered.
Definition value.cpp:45
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.
const Output * source
The output from which this input reads samples.
Definition processor.h:134
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110
int buffer_size
Current buffer size in samples.
Definition processor.h:114
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
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...
Declares Value processors that output a constant value and can be dynamically set.