VCV Rack API v2
Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1#pragma once
2#include <common.hpp>
3#include <math.hpp>
4#include <simd/functions.hpp>
5
6
7namespace rack {
8
9
12namespace dsp {
13
14
15// Constants
16
17static const float FREQ_C4 = 261.6256f;
18static const float FREQ_A4 = 440.0000f;
19static const float FREQ_SEMITONE = 1.0594630943592953f;
20
21// Mathematical functions
22
26inline float sinc(float x) {
27 if (x == 0.f)
28 return 1.f;
29 x *= M_PI;
30 return std::sin(x) / x;
31}
32
33template <typename T>
34T sinc(T x) {
35 T zeromask = (x == 0.f);
36 x *= M_PI;
37 x = simd::sin(x) / x;
38 return simd::ifelse(zeromask, 1.f, x);
39}
40
41// Conversion functions
42
43template <typename T>
44T amplitudeToDb(T amp) {
45 return simd::log10(amp) * 20;
46}
47
48template <typename T>
50 return simd::pow(10, db / 20);
51}
52
53// Functions for parameter scaling
54
55template <typename T>
57 return simd::sgn(x) * (x * x);
58}
59
60template <typename T>
61T cubic(T x) {
62 return x * x * x;
63}
64
65template <typename T>
67 return simd::sgn(x) * (x * x * x * x);
68}
69
70template <typename T>
71T quintic(T x) {
72 // optimal with -fassociative-math
73 return x * x * x * x * x;
74}
75
76template <typename T>
78 return simd::sgn(x) * simd::sqrt(x);
79}
80
84template <typename T>
85T exponentialBipolar(T b, T x) {
86 return (simd::pow(b, x) - simd::pow(b, -x)) / (b - 1.f / b);
87}
88
89
91template <size_t CHANNELS, typename T = float>
92struct Frame {
93 T samples[CHANNELS];
94};
95
96
97} // namespace dsp
98} // namespace rack
float sinc(float x)
The normalized sinc function See https://en.wikipedia.org/wiki/Sinc_function.
Definition common.hpp:26
static const float FREQ_A4
Definition common.hpp:18
T amplitudeToDb(T amp)
Definition common.hpp:44
static const float FREQ_SEMITONE
Definition common.hpp:19
T quadraticBipolar(T x)
Definition common.hpp:56
T dbToAmplitude(T db)
Definition common.hpp:49
T sqrtBipolar(T x)
Definition common.hpp:77
T cubic(T x)
Definition common.hpp:61
T quintic(T x)
Definition common.hpp:71
T quarticBipolar(T x)
Definition common.hpp:66
static const float FREQ_C4
Definition common.hpp:17
T exponentialBipolar(T b, T x)
This is pretty much a scaled sinh.
Definition common.hpp:85
float_4 pow(float_4 a, float_4 b)
Definition functions.hpp:227
float_4 sqrt(float_4 x)
Definition functions.hpp:102
float_4 log10(float_4 x)
Definition functions.hpp:114
float_4 sgn(float_4 x)
Definition functions.hpp:269
float ifelse(bool cond, float a, float b)
Definition functions.hpp:49
float_4 sin(float_4 x)
Definition functions.hpp:132
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Useful for storing arrays of samples in ring buffers and casting them to float* to be used by interle...
Definition common.hpp:92
T samples[CHANNELS]
Definition common.hpp:93