1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/*
* DISTRHO PingPongPan Plugin, based on PingPongPan by Michael Gruhn
* Copyright (C) 2007 Michael Gruhn <michael-gruhn@web.de>
* Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* For a full copy of the license see the LICENSE file.
*/
#include "DistrhoPluginPingPongPan.hpp"
#include <cmath>
static const float k2PI = 6.283185307f;
START_NAMESPACE_DISTRHO
// -----------------------------------------------------------------------
DistrhoPluginPingPongPan::DistrhoPluginPingPongPan()
: Plugin(paramCount, 1, 0) // 1 program, 0 states
{
// set default values
loadProgram(0);
// reset
deactivate();
}
// -----------------------------------------------------------------------
// Init
void DistrhoPluginPingPongPan::initAudioPort(bool input, uint32_t index, AudioPort& port)
{
port.groupId = kPortGroupStereo;
Plugin::initAudioPort(input, index, port);
}
void DistrhoPluginPingPongPan::initParameter(uint32_t index, Parameter& parameter)
{
switch (index)
{
case paramFreq:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Frequency";
parameter.symbol = "freq";
parameter.ranges.def = 50.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 100.0f;
break;
case paramWidth:
parameter.hints = kParameterIsAutomatable;
parameter.name = "Width";
parameter.symbol = "width";
parameter.unit = "%";
parameter.ranges.def = 75.0f;
parameter.ranges.min = 0.0f;
parameter.ranges.max = 100.0f;
break;
}
}
void DistrhoPluginPingPongPan::initProgramName(uint32_t index, String& programName)
{
if (index != 0)
return;
programName = "Default";
}
// -----------------------------------------------------------------------
// Internal data
float DistrhoPluginPingPongPan::getParameterValue(uint32_t index) const
{
switch (index)
{
case paramFreq:
return fFreq;
case paramWidth:
return fWidth;
default:
return 0.0f;
}
}
void DistrhoPluginPingPongPan::setParameterValue(uint32_t index, float value)
{
if (getSampleRate() <= 0.0)
return;
switch (index)
{
case paramFreq:
fFreq = value;
waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
break;
case paramWidth:
fWidth = value;
break;
}
}
void DistrhoPluginPingPongPan::loadProgram(uint32_t index)
{
if (index != 0)
return;
// Default values
fFreq = 50.0f;
fWidth = 75.0f;
// reset filter values
activate();
}
// -----------------------------------------------------------------------
// Process
void DistrhoPluginPingPongPan::activate()
{
waveSpeed = (k2PI * fFreq / 100.0f)/(float)getSampleRate();
}
void DistrhoPluginPingPongPan::deactivate()
{
wavePos = 0.0f;
}
void DistrhoPluginPingPongPan::run(const float** inputs, float** outputs, uint32_t frames)
{
const float* in1 = inputs[0];
const float* in2 = inputs[1];
float* out1 = outputs[0];
float* out2 = outputs[1];
for (uint32_t i=0; i < frames; ++i)
{
pan = std::fmin(std::fmax(std::sin(wavePos) * (fWidth/100.0f), -1.0f), 1.0f);
if ((wavePos += waveSpeed) >= k2PI)
wavePos -= k2PI;
out1[i] = in1[i] * (pan > 0.0f ? 1.0f-pan : 1.0f);
out2[i] = in2[i] * (pan < 0.0f ? 1.0f+pan : 1.0f);
}
}
// -----------------------------------------------------------------------
Plugin* createPlugin()
{
return new DistrhoPluginPingPongPan();
}
// -----------------------------------------------------------------------
END_NAMESPACE_DISTRHO
|