Subversion Repositories DIN Is Noise

Rev

Rev 1695 | Rev 1713 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
* modulator.cc
* DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath
* For more information, please visit https://dinisnoise.org/
*/


#include "multi_curve.h"
#include "modulator.h"
#include "audio.h"
#include "chrono.h"
#include "drone.h"

extern float TWO_PI;
extern const char spc;

mod_params::mod_params (multi_curve* c, int d, point<float>& p, const std::string& n) {

  setdir (d, &p.x, &p.y);

  bv.name = n;
  bv.crv = c;
  bv.setup (aout.samples_per_channel);
  depth = result = initial = 0;

  t = ui_clk ();

}

void mod_params::clear (int reset) {
  depth = 0;
  result = 0;
  initial = 0;
  bv.set_bpm (bv.bpm, aout.samples_per_channel);
}

void mod_params::calc () {
  double t1 = ui_clk ();
  double dt = t1 - t;
  t = t1;
  bv.delta = dt * bv.bps;
  result = depth * bv.sol (bv.now, bv.delta);
  autorot.angle.theta = dt * autorot.dir * autorot.angle.persec;
}

void autorotator::set_rpm (float r) {
  if (r > 0) {
    rpm = r;
    angle.persec = TWO_PI * r / 60.0f;
  } else {
    rpm = 0;
    angle.persec = 0.0f;
  }
}

using namespace std;
ostream& operator<< (ostream& file, autorotator& ar) {
  file << ar.yes << spc << ar.dir << spc << ar.rpm;
  return file;
}

istream& operator>> (istream& file, autorotator& ar) {
  float rpm;
  file >> ar.yes >> ar.dir >> rpm;
  ar.set_rpm (rpm);
  return file;
}

void mod_params::calcdir (drone& dd) {
  float* px [] = {&vertical.x, &horizontal.x, &dd.vx, &dd.vy};
  float* py [] = {&vertical.y, &horizontal.y, &dd.ax, &dd.ay};
  dirx = px[dir];
  diry = py[dir];
}