COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 12-14-2016, 03:32 PM   #1
CaptnWillie
Human being with feelings
 
Join Date: Dec 2016
Posts: 51
Default Adding Other Source Code

Hi Friends,

Forgive me for such an amateur question, but I am curious how I will go about importing other libraries into WDL.

I have found some very useful source code for dynamic range applications, but I am unsure how to get them to mesh with my existing projects.

For instance, I want these classes, (for instance Limiter.cpp & Limiter.h) to do the DSP for the plugin. Is it as simple as importing the cpp and h in the top of the main project and calling the class where I want the DSP?

Specifically, I am trying to implement the ChunkWare compression in place of the DSP in the DigitalDistortion example.

Any help is greatly appreciated.
CaptnWillie is offline   Reply With Quote
Old 12-14-2016, 04:34 PM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by CaptnWillie View Post
Limiter.h
You will usually need to ensure that file can be found from your include paths. (It isn't enough if you add the header file into your IDE project.)

Otherwise it isn't really possible to say without looking into the library code itself what else might need to be done to make it work within an IPlug plugin.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 12-15-2016, 12:13 PM   #3
CaptnWillie
Human being with feelings
 
Join Date: Dec 2016
Posts: 51
Default

Im seeking to incorporate some of the simple dynamic range source code that can be found here:
https://github.com/music-dsp-collect...r/simpleSource

I have built the simple distortion plugin following Martin Finke's blog here:
http://www.martin-finke.de/blog/arti...al-distortion/

you will notice there is a short section containing the DSP:
void DigitalDistortion::ProcessDoubleReplacing(
double** inputs,
double** outputs,
int nFrames)
{
// Mutex is already locked for us.

int const channelCount = 2;

for (int i = 0; i < channelCount; i++) {
double* input = inputs[i];
double* output = outputs[i];

for (int s = 0; s < nFrames; ++s, ++input, ++output) {
if(*input >= 0) {
// Make sure positive values can't go above the threshold:
*output = fmin(*input, mThreshold);
} else {
// Make sure negative values can't go below the threshold:
*output = fmax(*input, -mThreshold);
}
}
}
}

I want to use the Chunkware compressor to do the DSP in this case. Do I need to #include the simple compressor source, while its in the same path as all the other source code, and bring it in using enum and the class / function calling?

Im pretty new to C++ so i've been following tutorials and taking a very back of the envelope approach. Any help is appreciated!

Thanks
CaptnWillie is offline   Reply With Quote
Old 12-15-2016, 07:44 PM   #4
CaptnWillie
Human being with feelings
 
Join Date: Dec 2016
Posts: 51
Default

I have found another compression source. I wish to implement this to the DSP in IPlug, can I just put this inside of my constructor in my cpp file?


void compress
(
float* wav_in, // signal
int n, // N samples
double threshold, // threshold (percents)
double slope, // slope angle (percents)
int sr, // sample rate (smp/sec)
double tla, // lookahead (ms)
double twnd, // window time (ms)
double tatt, // attack time (ms)
double trel // release time (ms)
)
{
typedef float stereodata[2];
stereodata* wav = (stereodata*) wav_in; // our stereo signal
threshold *= 0.01; // threshold to unity (0...1)
slope *= 0.01; // slope to unity
tla *= 1e-3; // lookahead time to seconds
twnd *= 1e-3; // window time to seconds
tatt *= 1e-3; // attack time to seconds
trel *= 1e-3; // release time to seconds

// attack and release "per sample decay"
double att = (tatt == 0.0) ? (0.0) : exp (-1.0 / (sr * tatt));
double rel = (trel == 0.0) ? (0.0) : exp (-1.0 / (sr * trel));

// envelope
double env = 0.0;

// sample offset to lookahead wnd start
int lhsmp = (int) (sr * tla);

// samples count in lookahead window
int nrms = (int) (sr * twnd);

// for each sample...
for (int i = 0; i < n; ++i)
{
// now compute RMS
double summ = 0;

// for each sample in window
for (int j = 0; j < nrms; ++j)
{
int lki = i + j + lhsmp;
double smp;

// if we in bounds of signal?
// if so, convert to mono
if (lki < n)
smp = 0.5 * wav[lki][0] + 0.5 * wav[lki][1];
else
smp = 0.0; // if we out of bounds we just get zero in smp

summ += smp * smp; // square em..
}

double rms = sqrt (summ / nrms); // root-mean-square

// dynamic selection: attack or release?
double theta = rms > env ? att : rel;

// smoothing with capacitor, envelope extraction...
// here be aware of pIV denormal numbers glitch
env = (1.0 - theta) * rms + theta * env;

// the very easy hard knee 1:N compressor
double gain = 1.0;
if (env > threshold)
gain = gain - (env - threshold) * slope;

// result - two hard kneed compressed channels...
float leftchannel = wav[i][0] * gain;
float rightchannel = wav[i][1] * gain;
}
}
CaptnWillie is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.