Calling multiple sine wave instances

Status
Not open for further replies.

tombola

Member
Hi,

Is there a more elegant way of doing this? (updating 16 sine wave objects from an array containing 16 floats). I'd like to expand it to 32 or 64 without quite so much cutting and pasting!

sine1.frequency(FREQ[0]);
sine2.frequency(FREQ[1]);
sine3.frequency(FREQ[2]);
sine4.frequency(FREQ[3]);
sine5.frequency(FREQ[4]);
sine6.frequency(FREQ[5]);
sine7.frequency(FREQ[6]);
sine8.frequency(FREQ[7]);
sine9.frequency(FREQ[8]);
sine10.frequency(FREQ[9]);
sine11.frequency(FREQ[10]);
sine12.frequency(FREQ[11]);
sine13.frequency(FREQ[12]);
sine14.frequency(FREQ[13]);
sine15.frequency(FREQ[14]);
sine16.frequency(FREQ[15]);
 
That would set sine1 to all the frequencies, in turn. Meanwhile the other 15 oscillators would be sitting there.

Is it possible to have an array of pointers to sine oscillator objects? So you could then use a loop:

sines[x]->.frequency(FREQ[x]);
 
Not sure exactly what sineX is. But it looks like maybe that part of a library?

For multiple stepper motors and the acelstepper library i use something like this for multiple instances
Code:
AccelStepper stepper0(1,15,14); 
AccelStepper stepper1(1,23,22);
AccelStepper stepper2(1,24,22);
AccelStepper stepper3(1,25,22); 
AccelStepper stepper4(1,26,22);
AccelStepper stepper[5]={stepper0,stepper1, stepper2, stepper3, stepper4};

Which I can then loop with, say,

for (i=0;i<5){
stepper.run()
}

Sorry if I am not answering the question correctly. I am a bit of a newb and dont know exactly what is being asked. but it looked like maybe what I was referring to.
 
That would set sine1 to all the frequencies, in turn. Meanwhile the other 15 oscillators would be sitting there.

Is it possible to have an array of pointers to sine oscillator objects? So you could then use a loop:

sines[x]->.frequency(FREQ[x]);

yep, see Examples>Audio>Synthesis>PlaySynthMusic:

Code:
AudioSynthWaveform sine0, sine1, sine2, sine3 .. sine15;

AudioSynthWaveform *waves[16] = {
  &sine0, &sine1, &sine2, &sine3,
  &sine4, &sine5, &sine6, &sine7,
  &sine8, &sine9, &sine10, &sine11,
  &sine12, &sine13, &sine14, &sine15
};

so in this case:

waves[x]->frequency(freq[x]);
 
Last edited:
Status
Not open for further replies.
Back
Top