Vital
Loading...
Searching...
No Matches
line_map.cpp
Go to the documentation of this file.
1#include "line_map.h"
2
3#include "line_generator.h"
4#include "utils.h"
5
6namespace vital {
7
8 LineMap::LineMap(LineGenerator* source) : Processor(1, kNumOutputs, true), source_(source) { }
9
10 void LineMap::process(int /*num_samples*/) {
17 process(input()->at(0));
18 }
19
29 // Retrieve the line generator's cubic interpolation buffer and resolution.
31 int resolution = source_->resolution();
32
33 // Convert the phase into an index into the buffer.
34 poly_float boost = utils::clamp(phase * resolution, 0.0f, (mono_float)resolution);
35 poly_int indices = utils::clamp(utils::toInt(boost), 0, resolution - 1);
36 poly_float t = boost - utils::toFloat(indices);
37
38 // Compute interpolation matrices and apply cubic interpolation.
39 matrix interpolation_matrix = utils::getPolynomialInterpolationMatrix(t);
40 matrix value_matrix = utils::getValueMatrix(buffer, indices);
41
42 // Transpose the value matrix to align dimensions for multiplication.
43 value_matrix.transpose();
44
45 // Perform matrix multiplication to get the interpolated result.
46 poly_float result = utils::clamp(interpolation_matrix.multiplyAndSumRows(value_matrix), -1.0f, 1.0f);
47
48 // Output the computed value and the original phase.
49 output(kValue)->buffer[0] = result;
50 output(kPhase)->buffer[0] = phase;
51 }
52} // namespace vital
A class for generating and storing a line shape, defined by a series of points and associated powers.
Definition line_generator.h:20
force_inline int resolution() const
Gets the resolution of the line's internal buffer.
Definition line_generator.h:266
force_inline vital::mono_float * getCubicInterpolationBuffer() const
Gets a pointer to the buffer used for cubic interpolation.
Definition line_generator.h:298
void process(int num_samples) override
Processes a given number of samples at the current rate (audio or control).
Definition line_map.cpp:10
LineMap(LineGenerator *source)
Constructs a LineMap processor.
Definition line_map.cpp:8
@ kValue
Definition line_map.h:28
@ kPhase
Definition line_map.h:29
LineGenerator * source_
The associated LineGenerator used for generating the values.
Definition line_map.h:66
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
force_inline poly_float clamp(poly_float value, mono_float min, mono_float max)
Clamps each lane of a vector to [min, max].
Definition poly_utils.h:306
force_inline poly_float toFloat(poly_int integers)
Casts a poly_int to poly_float lane-by-lane.
Definition poly_utils.h:733
force_inline matrix getPolynomialInterpolationMatrix(poly_float t_from)
Creates a matrix for polynomial interpolation given a starting poly_float t_from.
Definition poly_utils.h:205
force_inline matrix getValueMatrix(const mono_float *buffer, poly_int indices)
Creates a matrix of 4 poly_float lanes from a single buffer at varying indices.
Definition poly_utils.h:262
force_inline poly_int toInt(poly_float floats)
Casts a poly_float to poly_int by truncation.
Definition poly_utils.h:748
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
A structure representing a 4x1 matrix of poly_float rows.
Definition matrix.h:19
force_inline poly_float multiplyAndSumRows(const matrix &other)
Multiplies and sums corresponding rows of this matrix with another matrix.
Definition matrix.h:93
force_inline void transpose()
Transposes the matrix in-place.
Definition matrix.h:44
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
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...