fm8xRandom

8x sine wave oscillator with internal FM. generated harmonics and FM routing are random. Harmonics and FM routing can be independently randomised with the buttons and inputs. Range sets the maximum harmonic range.
Author: Remco van der Most
License: BSD
Github: sss/osc/fm8xRandom.axo

Inlets

frac32 fm

bool32 active

frac32.bipolar pitch

frac32buffer frequency

frac32buffer phase

bool32.rising rndFM

bool32.rising rndHrm

Outlets

frac32buffer.bipolar sine wave

Parameters

bool32.mom rndFM

bool32.mom rndHrm

int32 range

int32 voices

frac32.s.map.pitch pitch

frac32.s.map fm

Declaration
int32_t sine[8];
uint32_t phase[8];
int32_t val[8];
int32_t harm[8];
int8_t i;
int32_t freq;
int ntrig;
int strig;
Init
for (i = 0; i < 8; i++) {
  val[i] = (int32_t)(GenerateRandomNumber() % (7));
  harm[i] = (int32_t)(GenerateRandomNumber() % (48));
}
ntrig = 0;
Control Rate
if (inlet_active > 0) {
  if (((param_rndFM + inlet_rndFM) > 0) && !ntrig) {
    for (i = 0; i < 8; i++) {
      val[i] = (int32_t)(GenerateRandomNumber() % (param_voices));
    }
    ntrig = 1;
  } else if (!((param_rndFM + inlet_rndFM) > 0))
    ntrig = 0;

  if (((param_rndHrm + inlet_rndHrm) > 0) && !strig) {
    for (i = 0; i < 8; i++) {
      harm[i] = (int32_t)(GenerateRandomNumber() % (param_range));
    }
    harm[0] = 0;
    strig = 1;
  } else if (!((param_rndHrm + inlet_rndHrm) > 0))
    strig = 0;

  MTOFEXTENDED(param_pitch + inlet_pitch, freq)
}
Audio Rate
if (inlet_active > 0) {
  int32_t sum = 0;
  phase[0] +=
      freq +
      ___SMMUL(
          freq << 3,
          ___SMMUL((param_fm + inlet_fm) << 3, (inlet_freq << 3) + sine[val[0]])
              << 2);
  SINE2TINTERP(phase[0], sine[0])
  for (i = 1; i < param_voices; i++) {
    phase[i] +=
        (freq * (1 + harm[i])) +
        ___SMMUL((freq * (1 + harm[i])) << 3,
                 ___SMMUL((param_fm + inlet_fm) << 3, inlet_freq + sine[val[i]])
                     << 2);
    SINE2TINTERP(phase[i], sine[i])
  }
  for (i = 0; i < param_voices; i++) {
    sum += sine[i] >> 5;
  }

  outlet_wave = sum >> 3;
  // outlet_wave=sum>>3;
}

Privacy

© 2024 Zrna Research