Skip to content

Commit

Permalink
add ringmodulator and new pos2osc mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed May 20, 2024
1 parent 80fdfe3 commit 7b0d032
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ AUDIOPLUGINS = delay dummy gate hannenv identity lipsync \
gainramp pulse pink dumplevels feedbackdelay bandpass filter \
level2osc const noise loopmachine pos2osc gain sndfileasync \
addchannel tubesim spkcalib sessiontime flanger timestamp \
burglatticelpc fence transportramp allpass bandlevel2osc level2hsv
burglatticelpc fence transportramp allpass bandlevel2osc level2hsv \
ringmodulator

MASKPLUGINS = fig8 multibeam sampledgain

Expand Down
89 changes: 89 additions & 0 deletions plugins/src/tascar_ap_ringmodulator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* This file is part of the TASCAR software, see <http://tascar.org/>
*
* Copyright (c) 2024 Giso Grimm
*/
/*
* TASCAR is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, version 3 of the License.
*
* TASCAR is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHATABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License, version 3 for more details.
*
* You should have received a copy of the GNU General Public License,
* Version 3 along with TASCAR. If not, see <http://www.gnu.org/licenses/>.
*/

#include "audioplugin.h"
#include "errorhandling.h"

class ringmod_t : public TASCAR::audioplugin_base_t {
public:
ringmod_t(const TASCAR::audioplugin_cfg_t& cfg);
void ap_process(std::vector<TASCAR::wave_t>& chunk, const TASCAR::pos_t& pos,
const TASCAR::zyx_euler_t&, const TASCAR::transport_t& tp);
void add_variables(TASCAR::osc_server_t* srv);
~ringmod_t();

private:
std::vector<float> frange = {300.0f, 2000.0f};
bool active = true;
float depth = 1.0f;
float vco = 0.5f;
double phi = 0.0;
double dphi = 0.0;
};

ringmod_t::ringmod_t(const TASCAR::audioplugin_cfg_t& cfg)
: audioplugin_base_t(cfg)
{
GET_ATTRIBUTE(frange, "Hz", "Frequency range (VCO controlled)");
if(frange.size() != 2)
throw TASCAR::ErrMsg("frange needs two entries");
GET_ATTRIBUTE(depth, "", "Modulation depth amount");
GET_ATTRIBUTE(vco, "", "Voltage control input, start value");
GET_ATTRIBUTE_BOOL(active, "Start activated");
}

ringmod_t::~ringmod_t() {}

void ringmod_t::add_variables(TASCAR::osc_server_t* srv)
{
srv->set_variable_owner(
TASCAR::strrep(TASCAR::tscbasename(__FILE__), ".cc", ""));
srv->add_vector_float("/frange", &frange, "]0,20000]",
"Frequency range (VCO controlled), in Hz");
srv->add_float("/depth", &depth, "[0,1]", "Modulation depth amount");
srv->add_float("/vco", &vco, "[0,1]", "Voltage control input");
srv->add_bool("/active", &active, "Activate ring modulator");
srv->unset_variable_owner();
}

void ringmod_t::ap_process(std::vector<TASCAR::wave_t>& chunk,
const TASCAR::pos_t&, const TASCAR::zyx_euler_t&,
const TASCAR::transport_t&)
{
if(!active)
return;
float f = expf(logf(frange[0]) * (1.0f - vco) + logf(frange[1]) * vco);
dphi = TASCAR_2PI * f * t_sample;
for(uint32_t k = 0; k < chunk[0].n; ++k) {
chunk[0].d[k] *= depth * sin(phi) + 1.0f - depth;
phi += dphi;
}
phi = fmod(phi, TASCAR_2PI);
}

REGISTER_AUDIOPLUGIN(ringmod_t);

/*
* Local Variables:
* mode: c++
* c-basic-offset: 2
* indent-tabs-mode: nil
* compile-command: "make -C .."
* End:
*/
6 changes: 6 additions & 0 deletions plugins/src/tascarmod_pos2osc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ void pos2osc_t::update_local()
RAD2DEG * o.z * oscale, RAD2DEG * o.y * oscale,
RAD2DEG * o.x * oscale);
break;
case 12:
path = "/" + avatar;
TASCAR::pos_t p(0, 0, 1);
p *= o;
lo_send(target, path.c_str(), "f", (float)(1.0 - p.z));
break;
}
}
}
Expand Down

0 comments on commit 7b0d032

Please sign in to comment.