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