Vital
Loading...
Searching...
No Matches
lookup_table.h
Go to the documentation of this file.
1
10#pragma once
11
12#include "common.h"
13#include "poly_utils.h"
14
15namespace vital {
16
30 template<mono_float(*function)(mono_float), size_t resolution>
32 static constexpr int kExtraValues = 4;
33 public:
38 OneDimLookup(float scale = 1.0f) {
39 scale_ = resolution / scale;
40 for (int i = 0; i < static_cast<int>(resolution) + kExtraValues; ++i) {
41 mono_float t = (i - 1.0f) / (resolution - 1.0f);
42 lookup_[i] = function(t * scale);
43 }
44 }
45
50
62 poly_float boost = value * scale_;
63 poly_int indices = utils::clamp(utils::toInt(boost), 0, static_cast<int>(resolution));
64 poly_float t = boost - utils::toFloat(indices);
65
66 matrix interpolation_matrix = utils::getCatmullInterpolationMatrix(t);
67 matrix value_matrix = utils::getValueMatrix(lookup_, indices);
68 value_matrix.transpose();
69
70 return interpolation_matrix.multiplyAndSumRows(value_matrix);
71 }
72
73 private:
74 mono_float lookup_[resolution + kExtraValues];
75 mono_float scale_;
76
77 JUCE_LEAK_DETECTOR(OneDimLookup)
78 };
79
80} // namespace vital
A one-dimensional lookup table for a given function with a specified resolution.
Definition lookup_table.h:31
force_inline poly_float cubicLookup(poly_float value) const
Performs a cubic interpolation lookup on the precomputed data.
Definition lookup_table.h:61
~OneDimLookup()
Destructor.
Definition lookup_table.h:49
OneDimLookup(float scale=1.0f)
Constructs the lookup table by sampling the given function.
Definition lookup_table.h:38
#define force_inline
Definition common.h:23
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 getCatmullInterpolationMatrix(poly_float t)
Creates a Catmull-Rom interpolation matrix from a poly_float t.
Definition poly_utils.h:227
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
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