grid k

Generates a 2d grid, for further lissajous applications. K-rate .
Author: Sputnki
License: BSD
Github: sptnk/math/grid k.axo

Inlets

frac32 pitch of the oscillator

int32 number of rows, overrides the parameter

int32 number of columns, overrides the parameter

Outlets

frac32 x coordinate

frac32 y coordinate

Parameters

frac32.s.map.pitch pitch of the oscillator

int32 number of rows

int32 number of columns

bool32.tgl bipolar output if checked (rows and columns spanning from -64 to 64 instead of 0 to 64)

Declaration
uint32_t phase = 0;
uint32_t phase_old = 0;
int i = 0;
Control Rate
// begin of k-rate code
int rows = param_rows;
int cols = param_cols;

if (inlet_rows > 1 && inlet_rows < 65)
  rows = inlet_rows;
if (inlet_cols > 1 && inlet_cols < 65)
  cols = inlet_cols;

int rpc = rows + cols;

uint32_t rowspacing = (1 << 27) / (rows - 1);
uint32_t colspacing = (1 << 27) / (cols - 1);

uint32_t freq = MTOFEXTENDED((inlet_pitch + param_pitch), freq);
freq *= rpc;

// begin of k-rate code that you can actually move to s-rate

phase_old = phase;
phase += freq;

// i want to draw row1  -> row2 -> row3 -> .. -> row R -> col 1 -> col2 -> col3
// -> .. -> col N

int i_rows = i - rows;

int32_t x;
int32_t y;
if (i < rows) // draw rows
{
  x = phase >> 5;
  y = i * rowspacing;
} else // draw columns
{
  x = i_rows * colspacing;
  y = phase >> 5;
}

if (phase <= phase_old)
  i++;
if (i >= rpc)
  i = 0;

if (param_bipolar) {
  outlet_x = (x << 1) - (1 << 27);
  outlet_y = (y << 1) - (1 << 27);
} else {
  outlet_x = x;
  outlet_y = y;
}

Privacy

© 2024 Zrna Research