Mixing Oscillators

Hi

I have a harp type instrument with three knitted stretch sensor’s that I’ve made. I am playing around with a sketch using 3 oscillators, with each one’s pitch controlled by one of the sensors. I’m just altering the example oscillator code for now. Normally I have played with pitch by entering the frequency directly. This midi to frequency way is new to me and seems to do some kind of smoothing - my sensors are not very smooth. Would it be doing this?
Also what are the advantages of mtof rather than just using hz?

I have kind of just guessed how to mix them, and it’s working however I am wondering if there is a better way to do this.
the full code is below and here is the line for mixing

out[chn][i] = sig + sig2 + sig3;

– I’ve just altered the oscillator code.

#include "DaisyDuino.h"

DaisyHardware hw;

size_t num_channels;

static Oscillator osc;
static Oscillator osc2;
static Oscillator osc3;

float pitchstringL;
float pitchstringM;
float pitchstringR;

void MyCallback(float **in, float **out, size_t size) {
  // Convert pitchstringL MIDI Note Number to frequency
  osc.SetFreq(mtof(pitchstringL));
  osc2.SetFreq(mtof(pitchstringM));
  osc3.SetFreq(mtof(pitchstringR));
  for (size_t i = 0; i < size; i++) {
    float sig = osc.Process();
    float sig2 = osc2.Process();
    float sig3 = osc3.Process();

    for (size_t chn = 0; chn < num_channels; chn++) {
      out[chn][i] = sig + sig2 + sig3;
    }
  }
}

void setup() {
  float sample_rate;
  // Initialize for Daisy pod at 48kHz
  hw = DAISY.init(DAISY_SEED, AUDIO_SR_48K);
  num_channels = hw.num_channels;
  sample_rate = DAISY.get_samplerate();

  osc.Init(sample_rate);
  osc.SetFreq(440);
  osc.SetAmp(0.5);
  osc.SetWaveform(osc.WAVE_SIN);

  //second oscillator
  osc2.Init(sample_rate);
  osc2.SetFreq(440);
  osc2.SetAmp(0.5);
  osc2.SetWaveform(osc.WAVE_TRI);

  osc3.Init(sample_rate);
  osc3.SetFreq(440);
  osc3.SetAmp(0.5);
  osc3.SetWaveform(osc.WAVE_TRI);

  DAISY.begin(MyCallback);
}

void loop() { 

  pitchstringL = map(analogRead(A6), 910, 1020, 24.0, 100.0);
  pitchstringL = map(analogRead(A5), 910, 1023, 24.0, 100.0);
  pitchstringL = map(analogRead(A4), 910, 1023, 24.0, 100.0);

}

Hello!

Mixing the signals like that should be fine.

As for your other question, I would like to know more about your project (I saw the photos on Discord it looks awesome by the way!).
Are you going to have a specific note for each string and the pluck intensity is mapped to volume?
Or is it going to play a different pitch depending on how much you pluck it? And quantizing to a scale or arpeggio?

Either way, filtering/smoothing that sensor data would be key.
There are resources online about smoothing out analog input data like this that you can try out with your sensor.

With all these being said, I’m wondering about the range of the sensor input. From my own experience of building a pluck-based instrument with limited value range (I think it was around 100 between the minimum and maximum too), it’ll be challenging to get something musical out of it. So see if mapping the sensor value to amplitude like this sounds like.

  pitchstringL = map(analogRead(A6), 910, 1020, 0.0, 1.0);

It honestly would be cool enough to just play a note with a set ADSR whenever the sensor value goes above 1015 and such. And easy hack would be something like adding a distance sensor for each string so that the timbre and/or volume changes where in the string is plucked.

Hi

Thanks for all this info. I have used smoothing code for other similar teensy based projects but it is sounding ok without it at the moment. I’ll probably add smoothing in today.

I will upload a video of what it is doing now - that should help understand.

For some context - sound wise I make harsh noise and other sound that changes a lot and doesn’t necessarily have beats. (www.phantomchips.com has more info - I make several tactile instruments - site needs an update) So being musically playable or in tune isn’t necessary what I am after, I’m looking for chaos :stuck_out_tongue: ! This harp thing used to be wired up to a circuit I had built (it was two notes with pitch change and the middle string changed the speed of gating between them). I thought I’d see what I can do with it with the daisy.

Right now I have put an oscillator on each string and they are all triangle waves. I need to tweak the mapping and also play with the sounds more as it’s not sounding that good right now. Today I’m going to try adding different wave types on the different strings or even a noise gen with the amp being controlled on one of the strings. As for what I am wanting to do - I’m not totally sure - I thought the oscillators would sound cool but they are not yet…

It honestly would be cool enough to just play a note with a set ADSR whenever the sensor value goes above 1015 and such. And easy hack would be something like adding a distance sensor for each string so that the timbre and/or volume changes where in the string is plucked.

yeah that is quite a good idea. I could probably get some good sounds doing this. Although I think it might take me a bit as I’m still getting ok at Arduino coding. I have loads of ldrs here but not sure if I have any ultrasonics on hand

For now I am about to play some shows so if I don’t get something cool working today I’ll just update the old circuit and come back to this when I am less rushed.

Here’s the video, I don’t think it’s sounding good right now and i deffo need to go back and recheck my sensor values. but it gives an idea of what it could do.
https://youtu.be/3EQUUpWChyY

When mixing oscillators, they need to be attenuated to prevent clipping.

Thanks. How would I do that? Is there an example you could point to?

Use the SetAmp() function.
In your case, you are already initializing them all at 0.5, just change that to 0.33f ,

Then the sum of the signals won’t exceed 1.0f

2 Likes