planetModulator

Planetary audio modulator The audio inputs can be seen as the x/y positions of a planet, which influences the x/y positions of 2 moons. the x/y positions of the moons are used as output. The first 8 controls (x1/y1/x2/y2/x1rate/y1rate/x2rate/y2rate) are the reset positions of the moons. The rate controls control the starting rate at which the moons will move through the map. x1/y1/x2/y2 control where the moons will start. centermw adjusts the volume of the incoming audio (centerx/centery) Mass1/2/center set the mass of the planet and the moons. The higher the frequency, the less mass the moon has and the more it is influenced by the planet/other moon and the less it influences the other moon. The lower the frequency, the more mass the moon has and the less it is influences by the planet/other moon and the more it influences the other moon. Centermass sets the mass of the planet. The planet x/y position isn't influenced by the moons, but it influences the moons depending on it's mass. The lower the frequency of the planet, the "heavier" it is and the more the moons are going to be influenced by it, instead of by each other. damp1 and damp2 dampen the change in x/y positions of the moons and force them to center position. This can also result in drasticly pitch-changing modulations.
Author: Remco van der Most
License: BSD
Github: sss/fx/planetModulator.axo

Inlets

frac32buffer centerx

frac32buffer centery

bool32 reset

Outlets

frac32buffer x1

frac32buffer y1

frac32buffer x2

frac32buffer y2

Parameters

frac32.s.map x1

frac32.s.map y1

frac32.s.map x1rate

frac32.s.map y1rate

frac32.s.map x2

frac32.s.map y2

frac32.s.map x2rate

frac32.s.map y2rate

frac32.s.map centermw

frac32.s.map.pitch mass1

frac32.s.map.pitch mass2

frac32.s.map.pitch centermass

frac32.u.map damp1

frac32.u.map damp2

bool32.mom reset

Declaration
int32_t position1x;
int32_t position1y;
int32_t position2x;
int32_t position2y;
float32_t rate1x;
float32_t rate1y;
float32_t rate2x;
float32_t rate2y;
int reset;
int rtrig;
int32_t Damp1x;
int32_t Damp1y;
int32_t Damp2x;
int32_t Damp2y;
Init
reset = 1;
rate1x = 0;
rate1y = 0;
rate2x = 0;
rate2y = 0;
Control Rate
int32_t mass1 = param_mass1;
int32_t mass2 = param_mass2;
// mass1=___SMMUL(mass1<<3,param_mass1<<2);
// mass2=___SMMUL(mass2<<3,param_mass2<<2);
// int32_t centermass=param_centermass<<1;
int32_t centermass = param_centermass;
MTOFEXTENDED(-mass1, mass1)
MTOFEXTENDED(-mass2, mass2)
MTOFEXTENDED(centermass, centermass)
Audio Rate
int32_t centerx = ___SMMUL(param_centermw << 1, inlet_centerx << 2);
int32_t centery = ___SMMUL(param_centermw << 1, inlet_centery << 2);

float32_t cratio1 =
    ((float32_t)(centermass + 256)) / ((float32_t)((mass1 >> 8) + 256));
float32_t icratio1 = ((float32_t)(1)) / cratio1;
float32_t cratio2 =
    ((float32_t)(centermass + 256)) / ((float32_t)((mass2 >> 8) + 256));
float32_t icratio2 = ((float32_t)(1)) / cratio2;

reset = 0;
if ((param_reset || inlet_reset > 0) && (!(rtrig == 1))) {
  rtrig = 1;
  reset = 1;
} else {
  reset = 0;
  if (!(param_reset || inlet_reset > 0)) {
    rtrig = 0;
  }
}
if (reset > 0) {
  position1x = param_x1;
  position1y = param_y1;
  position2x = param_x2;
  position2y = param_y2;
  rate1x = param_x1rate >> 13;
  rate1y = param_y1rate >> 13;
  rate2x = param_x2rate >> 13;
  rate2y = param_y2rate >> 13;
}

float32_t ratio =
    ((float32_t)((mass1 >> 8) + 256)) / ((float32_t)((mass2 >> 8) + 256));
float32_t iratio = ((float32_t)(1)) / ratio;

position1x = position1x - ___SMMUL(param_damp1, position1x);
position1y = position1y - ___SMMUL(param_damp1, position1y);
position2x = position2x - ___SMMUL(param_damp2, position2x);
position2y = position2y - ___SMMUL(param_damp2, position2y);

Damp1x = Damp1x + ((position1x - Damp1x) >> 4);
position1x = Damp1x;
Damp1y = Damp1y + ((position1y - Damp1y) >> 4);
position1y = Damp1y;
Damp2x = Damp2x + ((position2x - Damp2x) >> 4);
position2x = Damp2x;
Damp2y = Damp2y + ((position2y - Damp2y) >> 4);
position2y = Damp2y;

int32_t diffx = position1x - position2x;
int32_t diffy = position1y - position2y;
int32_t distance =
    ___SMMUL(diffx << 3, diffx << 2) + ___SMMUL(diffy << 3, diffy << 2);
float32_t idist = distance;
idist = idist == 0 ? 1 : idist;
idist = _VSQRTF(idist) * (1 << 7);

int32_t xdist1 = position1x - centerx;
int32_t ydist1 = position1y - centery;
xdist1 =
    ___SMMUL(xdist1 << 3, xdist1 << 2) + ___SMMUL(ydist1 << 3, ydist1 << 2);
float32_t ixdist1 = xdist1;
ixdist1 = ixdist1 == 0 ? 1 : ixdist1;
ixdist1 = _VSQRTF(ixdist1) * (1 << 7);

int32_t xdist2 = position2x - centerx;
int32_t ydist2 = position2y - centery;
xdist2 =
    ___SMMUL(xdist2 << 3, xdist2 << 2) + ___SMMUL(ydist2 << 3, ydist2 << 2);
float32_t ixdist2 = xdist2;
ixdist2 = ixdist2 == 0 ? 1 : ixdist2;
ixdist2 = _VSQRTF(ixdist2) * (1 << 7);

rate1x -= ((float32_t)(diffx)) / (((float32_t)(idist)) * iratio) +
          ((float32_t)(+(position1x - centerx))) /
              (((float32_t)(ixdist1)) * icratio1);
rate1y -= ((float32_t)(diffy)) / (((float32_t)(idist)) * iratio) +
          ((float32_t)(+(position1y - centery))) /
              (((float32_t)(ixdist1)) * icratio1);
rate2x += ((float32_t)(diffx)) / (((float32_t)(idist)) * ratio) +
          ((float32_t)(-(position2x - centerx))) /
              (((float32_t)(ixdist2)) * icratio2);
rate2y += ((float32_t)(diffy)) / (((float32_t)(idist)) * ratio) +
          ((float32_t)(-(position2y - centery))) /
              (((float32_t)(ixdist2)) * icratio2);
outlet_x1 = position1x += rate1x;
outlet_y1 = position1y += rate1y;
outlet_x2 = position2x += rate2x;
outlet_y2 = position2y += rate2y;

position1x = __SSAT(position1x, 27);
position1y = __SSAT(position1y, 27);
position2x = __SSAT(position2x, 27);
position2y = __SSAT(position2y, 27);

// position1x=(position1x<<3)>>3;
// position1y=(position1y<<3)>>3;
// position2x=(position2x<<3)>>3;
// position2y=(position2y<<3)>>3;

Privacy

© 2024 Zrna Research