add license headers

This commit is contained in:
2025-11-06 11:05:54 +01:00
parent a362ab6c91
commit 12ae07d115
22 changed files with 739 additions and 108 deletions

View File

@@ -1,9 +1,40 @@
/*
* clip.h
* Copyright (c) 2016 Chris Johnson
* Copyright (c) 2025 Christopher Herb
* Based on ClipOnly2 by Chris Johnson, 2016
* This file is a derivative of the above module.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Changes:
* - 2025-11-06 Christopher Herb:
* - Templated audio buffer i/o
* - Converted to procedural programming style
*/
#pragma once
#include <cmath>
#include <cstdlib>
namespace trnr {
// clipper based on ClipOnly2 by Chris Johnson (MIT License)
struct clip {
double samplerate;
@@ -36,7 +67,8 @@ inline void clip_init(clip& c, double _samplerate)
}
template <typename t_sample>
inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, long sample_frames)
inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs,
long sample_frames)
{
t_sample* in1 = inputs[0];
t_sample* in2 = inputs[1];
@@ -47,7 +79,8 @@ inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, l
overallscale /= 44100.0;
overallscale *= c.samplerate;
int spacing = floor(overallscale); // should give us working basic scaling, usually 2 or 4
int spacing =
floor(overallscale); // should give us working basic scaling, usually 2 or 4
if (spacing < 1) spacing = 1;
if (spacing > 16) spacing = 16;
@@ -55,11 +88,13 @@ inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, l
double input_l = *in1;
double input_r = *in2;
// begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
// begin ClipOnly2 stereo as a little, compressed chunk that can be dropped into
// code
if (input_l > 4.0) input_l = 4.0;
if (input_l < -4.0) input_l = -4.0;
if (c.was_pos_clip_l == true) { // current will be over
if (input_l < c.last_sample_l) c.last_sample_l = 0.7058208 + (input_l * 0.2609148);
if (input_l < c.last_sample_l)
c.last_sample_l = 0.7058208 + (input_l * 0.2609148);
else c.last_sample_l = 0.2491717 + (c.last_sample_l * 0.7390851);
}
c.was_pos_clip_l = false;
@@ -68,7 +103,8 @@ inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, l
input_l = 0.7058208 + (c.last_sample_l * 0.2609148);
}
if (c.was_neg_clip_l == true) { // current will be -over
if (input_l > c.last_sample_l) c.last_sample_l = -0.7058208 + (input_l * 0.2609148);
if (input_l > c.last_sample_l)
c.last_sample_l = -0.7058208 + (input_l * 0.2609148);
else c.last_sample_l = -0.2491717 + (c.last_sample_l * 0.7390851);
}
c.was_neg_clip_l = false;
@@ -77,14 +113,16 @@ inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, l
input_l = -0.7058208 + (c.last_sample_l * 0.2609148);
}
c.intermediate_l[spacing] = input_l;
input_l = c.last_sample_l; // Latency is however many samples equals one 44.1k sample
input_l =
c.last_sample_l; // Latency is however many samples equals one 44.1k sample
for (int x = spacing; x > 0; x--) c.intermediate_l[x - 1] = c.intermediate_l[x];
c.last_sample_l = c.intermediate_l[0]; // run a little buffer to handle this
if (input_r > 4.0) input_r = 4.0;
if (input_r < -4.0) input_r = -4.0;
if (c.was_pos_clip_r == true) { // current will be over
if (input_r < c.last_sample_r) c.last_sample_r = 0.7058208 + (input_r * 0.2609148);
if (input_r < c.last_sample_r)
c.last_sample_r = 0.7058208 + (input_r * 0.2609148);
else c.last_sample_r = 0.2491717 + (c.last_sample_r * 0.7390851);
}
c.was_pos_clip_r = false;
@@ -93,7 +131,8 @@ inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, l
input_r = 0.7058208 + (c.last_sample_r * 0.2609148);
}
if (c.was_neg_clip_r == true) { // current will be -over
if (input_r > c.last_sample_r) c.last_sample_r = -0.7058208 + (input_r * 0.2609148);
if (input_r > c.last_sample_r)
c.last_sample_r = -0.7058208 + (input_r * 0.2609148);
else c.last_sample_r = -0.2491717 + (c.last_sample_r * 0.7390851);
}
c.was_neg_clip_r = false;
@@ -102,10 +141,12 @@ inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, l
input_r = -0.7058208 + (c.last_sample_r * 0.2609148);
}
c.intermediate_r[spacing] = input_r;
input_r = c.last_sample_r; // Latency is however many samples equals one 44.1k sample
input_r =
c.last_sample_r; // Latency is however many samples equals one 44.1k sample
for (int x = spacing; x > 0; x--) c.intermediate_r[x - 1] = c.intermediate_r[x];
c.last_sample_r = c.intermediate_r[0]; // run a little buffer to handle this
// end ClipOnly2 stereo as a little, compressed chunk that can be dropped into code
// end ClipOnly2 stereo as a little, compressed chunk that can be dropped into
// code
*out1 = input_l;
*out2 = input_r;
@@ -116,4 +157,4 @@ inline void clip_process_block(clip& c, t_sample** inputs, t_sample** outputs, l
out2++;
}
}
} // namespace trnr
} // namespace trnr

View File

@@ -1,3 +1,26 @@
/*
* fold.h
* Copyright (c) 2025 Christopher Herb
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
namespace trnr {

View File

@@ -1,11 +1,45 @@
/*
* tube.h
* Copyright (c) 2016 Chris Johnson
* Copyright (c) 2025 Christopher Herb
* Based on Tube2 by Chris Johnson, 2016
* This file is a derivative/major refactor of the above module.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Changes:
* - 2025-11-06 Christopher Herb:
* - Templated audio buffer i/o
* - Converted to procedural programming style
*/
#pragma once
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stdint.h>
using namespace std;
namespace trnr {
// modeled tube preamp based on tube2 by Chris Johnson (MIT License)
struct tube {
double samplerate;
@@ -22,9 +56,9 @@ struct tube {
float input_vol;
float tube_amt;
void set_input(double value) { input_vol = std::clamp(value, 0.0, 1.0); }
void set_input(double value) { input_vol = clamp(value, 0.0, 1.0); }
void set_tube(double value) { tube_amt = std::clamp(value, 0.0, 1.0); }
void set_tube(double value) { tube_amt = clamp(value, 0.0, 1.0); }
};
inline void tube_init(tube& t, double samplerate)
@@ -46,7 +80,8 @@ inline void tube_init(tube& t, double samplerate)
}
template <typename t_sample>
inline void tube_process_block(tube& t, t_sample** inputs, t_sample** outputs, long sampleframes)
inline void tube_process_block(tube& t, t_sample** inputs, t_sample** outputs,
long sampleframes)
{
t_sample* in1 = inputs[0];
t_sample* in2 = inputs[1];
@@ -114,13 +149,15 @@ inline void tube_process_block(tube& t, t_sample** inputs, t_sample** outputs, l
// original Tube algorithm: powerfactor widens the more linear region of the wave
double factor = input_l; // Left channel
for (int x = 0; x < powerfactor; x++) factor *= input_l;
if ((powerfactor % 2 == 1) && (input_l != 0.0)) factor = (factor / input_l) * fabs(input_l);
if ((powerfactor % 2 == 1) && (input_l != 0.0))
factor = (factor / input_l) * fabs(input_l);
factor *= gainscaling;
input_l -= factor;
input_l *= outputscaling;
factor = input_r; // Right channel
for (int x = 0; x < powerfactor; x++) factor *= input_r;
if ((powerfactor % 2 == 1) && (input_r != 0.0)) factor = (factor / input_r) * fabs(input_r);
if ((powerfactor % 2 == 1) && (input_r != 0.0))
factor = (factor / input_r) * fabs(input_r);
factor *= gainscaling;
input_r -= factor;
input_r *= outputscaling;
@@ -174,13 +211,13 @@ inline void tube_process_block(tube& t, t_sample** inputs, t_sample** outputs, l
t.fdp_l ^= t.fdp_l << 13;
t.fdp_l ^= t.fdp_l >> 17;
t.fdp_l ^= t.fdp_l << 5;
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
// frexp((double)inputSampleR, &expon);
// inputSampleL += ((double(fpdL)-uint32_t(0x7fffffff)) * 1.1e-44l *
// pow(2,expon+62)); frexp((double)inputSampleR, &expon);
t.fdp_r ^= t.fdp_r << 13;
t.fdp_r ^= t.fdp_r >> 17;
t.fdp_r ^= t.fdp_r << 5;
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l * pow(2,expon+62));
// end 64 bit stereo floating point dither
// inputSampleR += ((double(fpdR)-uint32_t(0x7fffffff)) * 1.1e-44l *
// pow(2,expon+62)); end 64 bit stereo floating point dither
*out1 = input_l;
*out2 = input_r;
@@ -191,4 +228,4 @@ inline void tube_process_block(tube& t, t_sample** inputs, t_sample** outputs, l
out2++;
}
}
} // namespace trnr
} // namespace trnr