Issue with wavetable sound

Status
Not open for further replies.

RABB17

Well-known member
Hey all, I was trying to put together a simple program to test max polyphony of various teensy platforms but I'm getting unexpected results, specifically just clicking noises
I've included my code, can anybody spot what the issue might be?

Thanks

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include "AdventureKid.h"
#include "AcouPiano3_samples.h"

void InitMixers(AudioMixer4 mixerArray[]);
void InitWavetables(AudioSynthWavetable wavetableArray[], AudioSynthWavetable::instrument_data instDataArray[]);
void SetDAC(float volume);
void TestPolyphony(AudioSynthWavetable wavetableArray[], AudioSynthWavetable::instrument_data instDataArray[]);

const int NUMMIXERS = 4;
const int NUMWAVETABLES = 12;

// GUItool: begin automatically generated code
AudioSynthWavetable      wavetable5; //xy=126,227
AudioSynthWavetable      wavetable6; //xy=126,259
AudioSynthWavetable      wavetable7; //xy=126,291
AudioSynthWavetable      wavetable1;     //xy=127,63
AudioSynthWavetable      wavetable8; //xy=126,322
AudioSynthWavetable      wavetable2;     //xy=127,95
AudioSynthWavetable      wavetable3;     //xy=127,127
AudioSynthWavetable      wavetable9; //xy=126,384
AudioSynthWavetable      wavetable4;     //xy=127,158
AudioSynthWavetable      wavetable10; //xy=126,416
AudioSynthWavetable      wavetable11; //xy=126,448
AudioSynthWavetable      wavetable12; //xy=126,479
AudioSynthNoiseWhite     noise1;         //xy=140,550
AudioSynthNoiseWhite     noise2;         //xy=140,582
AudioSynthNoisePink      pink1;          //xy=140,613
AudioSynthNoisePink      pink2;          //xy=140,644
AudioMixer4              mixer2; //xy=286,273
AudioMixer4              mixer1;         //xy=287,109
AudioMixer4              mixer3; //xy=286,430
AudioMixer4              mixer4;         //xy=286,593
AudioMixer4              mixerOut;         //xy=466,345
AudioOutputI2S           i2s1;           //xy=602,343
AudioConnection          patchCord1(wavetable5, 0, mixer2, 0);
AudioConnection          patchCord2(wavetable6, 0, mixer2, 1);
AudioConnection          patchCord3(wavetable7, 0, mixer2, 2);
AudioConnection          patchCord4(wavetable1, 0, mixer1, 0);
AudioConnection          patchCord5(wavetable8, 0, mixer2, 3);
AudioConnection          patchCord6(wavetable2, 0, mixer1, 1);
AudioConnection          patchCord7(wavetable3, 0, mixer1, 2);
AudioConnection          patchCord8(wavetable9, 0, mixer3, 0);
AudioConnection          patchCord9(wavetable4, 0, mixer1, 3);
AudioConnection          patchCord10(wavetable10, 0, mixer3, 1);
AudioConnection          patchCord11(wavetable11, 0, mixer3, 2);
AudioConnection          patchCord12(wavetable12, 0, mixer3, 3);
AudioConnection          patchCord13(noise1, 0, mixer4, 0);
AudioConnection          patchCord14(noise2, 0, mixer4, 1);
AudioConnection          patchCord15(pink1, 0, mixer4, 2);
AudioConnection          patchCord16(pink2, 0, mixer4, 3);
AudioConnection          patchCord17(mixer2, 0, mixerOut, 1);
AudioConnection          patchCord18(mixer1, 0, mixerOut, 0);
AudioConnection          patchCord19(mixer3, 0, mixerOut, 2);
AudioConnection          patchCord20(mixer4, 0, mixerOut, 3);
AudioConnection          patchCord21(mixerOut, 0, i2s1, 0);
AudioConnection          patchCord22(mixerOut, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=519,461
// GUItool: end automatically generated code

AudioMixer4 testMixerArray[] = {mixer1, mixer2, mixer3, mixer4};
AudioSynthWavetable testWavetableArray[] = {wavetable1, wavetable2, wavetable3, wavetable4, wavetable5, wavetable6, wavetable7, wavetable8, wavetable9, wavetable10, wavetable11, wavetable12};
AudioSynthWavetable::instrument_data adventureKid1[] =
{ 
 AKWF_0001, AKWF_0002, AKWF_0003, AKWF_0004, AKWF_0005, AKWF_0006, AKWF_0007, AKWF_0008, AKWF_0009, AKWF_0010, AKWF_0011, AKWF_0012,
 AKWF_0013, AKWF_0014, AKWF_0015, AKWF_0016, AKWF_0017, AKWF_0018, AKWF_0020, AKWF_0021, AKWF_0022, AKWF_0023, AKWF_0024, AKWF_0025, AKWF_0026, AKWF_0027, AKWF_0028, AKWF_0029, AKWF_0030,
 AKWF_0031, AKWF_0032, AKWF_0033, AKWF_0034, AKWF_0035, AKWF_0036, AKWF_0037, AKWF_0038, AKWF_0039, AKWF_0040, AKWF_0041, AKWF_0042, AKWF_0043, AKWF_0044, AKWF_0045, AKWF_0046, AKWF_0047,
 AKWF_0048, AKWF_0049, AKWF_0050, AKWF_0051, AKWF_0052, AKWF_0053, AKWF_0054, AKWF_0055, AKWF_0056, AKWF_0057, AKWF_0058, AKWF_0059, AKWF_0060, AKWF_0061, AKWF_0062, AKWF_0063, AKWF_0064,
 AKWF_0065, AKWF_0066, AKWF_0067, AKWF_0068, AKWF_0069, AKWF_0070, AKWF_0071, AKWF_0072, AKWF_0073, AKWF_0074, AKWF_0075, AKWF_0076, AKWF_0077, AKWF_0078, AKWF_0079, AKWF_0080, AKWF_0081,
 AKWF_0082, AKWF_0083, AKWF_0084, AKWF_0085, AKWF_0086, AKWF_0087, AKWF_0088, AKWF_0089, AKWF_0090, AKWF_0091, AKWF_0092, AKWF_0093, AKWF_0094, AKWF_0095, AKWF_0096, AKWF_0097, AKWF_0098,
 AKWF_0099, AKWF_0100, AKWF_0102, AKWF_0103, AKWF_0104, AKWF_0105, AKWF_0106, AKWF_0107, AKWF_0108, AKWF_0109, AKWF_0110, AKWF_0111, AKWF_0112, AKWF_0113, AKWF_0114, AKWF_0115, AKWF_0116,
 AKWF_0117, AKWF_0118, AKWF_0119, AKWF_0120, AKWF_0121, AKWF_0122, AKWF_0123, AKWF_0124, AKWF_0125, AKWF_0126, AKWF_0127
 };

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);

AudioMemory(128);
SetDAC(1.0);
InitMixers(testMixerArray);
InitWavetables(testWavetableArray, adventureKid1);
TestPolyphony(testWavetableArray, adventureKid1);

}

void loop() {
  // put your main code here, to run repeatedly:
}

void InitMixers(AudioMixer4 mixerArray[])
{
  for(int i = 0; i < NUMMIXERS; i++)
  {
    for(int j = 0; j < 4; j++)
    {
      mixerArray[i].gain(j, .25);
    }
  }
  for(int k = 0; k < 4; k++)
  {
    mixerOut.gain(k, .25);
  }
}

void InitWavetables(AudioSynthWavetable wavetableArray[], AudioSynthWavetable::instrument_data instDataArray[])
{
  for(int i = 0; i < NUMWAVETABLES; i++)
  {
    wavetableArray[i].setInstrument(instDataArray[4*i]);
    wavetableArray[i].amplitude(1);
  }
}

void SetDAC(float volume)
{
  sgtl5000_1.enable();
  sgtl5000_1.volume(volume);
}

void TestPolyphony(AudioSynthWavetable wavetableArray[], AudioSynthWavetable::instrument_data instDataArray[])
{
  for(int i = 0; i < NUMWAVETABLES; i++)
  {
    wavetableArray[i].playNote(60, 127);
    Serial.print((float)AudioProcessorUsage());
    delay(500);
  }
}
 
I ended up just rewriting the code in the most obtuse fashion and it ended up working. If anyone is interested in the results here they are:
T4 @ 600 Mhz ~ approx 391 voices
T4 @ 816 Mhz ~ approx 508 voices
T4 @ 24 Mhz ~ approx 16 voices

Impressive results!
 
Thanks for the report.
Is this with "raw" wavetable only, no modulators?
Not familiar with the Audio Library.
 
Yes this is with wavetables only. I was trying to determine the max # of unisons and wavetable osc sources I could have per voice. 3 osc, with 8 unisons and 10 key polyphony seems quite tenable with plenty of overhead for FX chains. I have already written an FM modulator block which allows for modulation of wavetables, so I will try testing out its performance with my full design here shortly. I hope to release a branch of my additions to the audio library here in a month or two. However, I just got a Daisy in the mail and I'm eager to play with it. Hopefully it won't distract me too much!
 
Yes this is with wavetables only. I was trying to determine the max # of unisons and wavetable osc sources I could have per voice. 3 osc, with 8 unisons and 10 key polyphony seems quite tenable with plenty of overhead for FX chains. I have already written an FM modulator block which allows for modulation of wavetables, so I will try testing out its performance with my full design here shortly. I hope to release a branch of my additions to the audio library here in a month or two. However, I just got a Daisy in the mail and I'm eager to play with it. Hopefully it won't distract me too much!

So what was the resolution to the clicking? Was it a bug you fixed, hardware failure, bad solder joint? Does the sketch you posted work now?

I'll be looking forward to your modulated wavetable module. I'm working on an envelope follower myself.
 
How I ended up resolving the clicking anomaly was simply to write the code as to avoid the fancy clean functions. C++ isn't my native language so I get quickly irritated by its... haha character. I imagine the issue lies somewhere in the instrument struct but it could easily be a simple mistake on my part. Def not a solder joint issue or anything this code was tested on 5 diff teensy. The main purpose of the code was simply to test the limits of the architecture before I committed to my final design, which is a great deal more complicated. The sketch I posted above still isn't working... I was hoping some sharp eyed C++ programmer would point out a rookie mistake but this doesn't seem to be the case. I literally just removed the function calls and manually set up 512 wavetables in the audio tool. Embarrassingly inelegant, I realize, but it wasn't a bug I felt needed to be tracked down for my purpose. I will include a smaller version of the code I wrote that did work, the wavetable resource usage does in fact scale @ the expressed increments so there isn't really a need to expand it further. Excited to see the results of your envelope follower! I plan on releasing my updates as soon as possible which include glissando, FM modulation of wavetable source, a 16 voice unison per osc, wavetable loading from SD to RAM, and wavetable sweeping so stay tuned!
 
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include "AKWF_0036_samples.h"

// GUItool: begin automatically generated code
AudioSynthWavetable      wavetable1;     //xy=65.5,23
AudioSynthWavetable      wavetable5;     //xy=69.5,184
AudioSynthWavetable      wavetable6;     //xy=69.5,216
AudioSynthWavetable      wavetable7;     //xy=69.5,248
AudioSynthWavetable      wavetable8;     //xy=69.5,279
AudioSynthWavetable      wavetable2;     //xy=70.5,52
AudioSynthWavetable      wavetable3;     //xy=70.5,84
AudioSynthWavetable      wavetable9;     //xy=69.5,341
AudioSynthWavetable      wavetable4;     //xy=70.5,115
AudioSynthWavetable      wavetable10;    //xy=69.5,373
AudioSynthWavetable      wavetable11;    //xy=69.5,405
AudioSynthWavetable      wavetable12;    //xy=69.5,436
AudioSynthWavetable      wavetable16;    //xy=80,592
AudioSynthWavetable      wavetable13;    //xy=83,484
AudioSynthWavetable      wavetable14;    //xy=84,515
AudioSynthWavetable      wavetable15;    //xy=85,553
AudioMixer4              mixer2;         //xy=229.5,230
AudioMixer4              mixer1;         //xy=230.5,66
AudioMixer4              mixer3;         //xy=229.5,387
AudioMixer4              mixer4;         //xy=240,528
AudioMixer4              mixerOut;       //xy=490,321
AudioOutputI2S           i2s1;           //xy=626,319
AudioConnection          patchCord1(wavetable1, 0, mixer1, 0);
AudioConnection          patchCord2(wavetable5, 0, mixer2, 0);
AudioConnection          patchCord3(wavetable6, 0, mixer2, 1);
AudioConnection          patchCord4(wavetable7, 0, mixer2, 2);
AudioConnection          patchCord5(wavetable8, 0, mixer2, 3);
AudioConnection          patchCord6(wavetable2, 0, mixer1, 1);
AudioConnection          patchCord7(wavetable3, 0, mixer1, 2);
AudioConnection          patchCord8(wavetable9, 0, mixer3, 0);
AudioConnection          patchCord9(wavetable4, 0, mixer1, 3);
AudioConnection          patchCord10(wavetable10, 0, mixer3, 1);
AudioConnection          patchCord11(wavetable11, 0, mixer3, 2);
AudioConnection          patchCord12(wavetable12, 0, mixer3, 3);
AudioConnection          patchCord13(wavetable16, 0, mixer4, 3);
AudioConnection          patchCord14(wavetable13, 0, mixer4, 0);
AudioConnection          patchCord15(wavetable14, 0, mixer4, 1);
AudioConnection          patchCord16(wavetable15, 0, mixer4, 2);
AudioConnection          patchCord17(mixer2, 0, mixerOut, 1);
AudioConnection          patchCord18(mixer1, 0, mixerOut, 0);
AudioConnection          patchCord19(mixer3, 0, mixerOut, 2);
AudioConnection          patchCord20(mixer4, 0, mixerOut, 3);
AudioConnection          patchCord21(mixerOut, 0, i2s1, 0);
AudioConnection          patchCord22(mixerOut, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=543,437
// GUItool: end automatically generated code


void setup()
{

  //begin serial
  Serial.begin(115200);

  //allocate audio memory
  AudioMemory(128);

  //set DAC
  sgtl5000_1.enable();
  sgtl5000_1.volume(.87);

  //set mixers
  mixer1.gain(0, 0.2);
  mixer1.gain(1, 0.2);
  mixer1.gain(2, 0.2);
  mixer1.gain(3, 0.2);

  mixer2.gain(0, 0.2);
  mixer2.gain(1, 0.2);
  mixer2.gain(2, 0.2);
  mixer2.gain(3, 0.2);

  mixer3.gain(0, 0.2);
  mixer3.gain(1, 0.2);
  mixer3.gain(2, 0.2);
  mixer3.gain(3, 0.2);

  mixer4.gain(0, 0.2);
  mixer4.gain(1, 0.2);
  mixer4.gain(2, 0.2);
  mixer4.gain(3, 0.2);

  mixerOut.gain(0, 0.2);
  mixerOut.gain(1, 0.2);
  mixerOut.gain(2, 0.2);
  mixerOut.gain(3, 0.2);

  //set wavetable instruments
  wavetable1.setInstrument(AKWF_0036);
  wavetable2.setInstrument(AKWF_0036);  
  wavetable3.setInstrument(AKWF_0036);
  wavetable4.setInstrument(AKWF_0036);
  wavetable5.setInstrument(AKWF_0036);
  wavetable6.setInstrument(AKWF_0036);  
  wavetable7.setInstrument(AKWF_0036);
  wavetable8.setInstrument(AKWF_0036);
  wavetable9.setInstrument(AKWF_0036);
  wavetable10.setInstrument(AKWF_0036);  
  wavetable11.setInstrument(AKWF_0036);
  wavetable12.setInstrument(AKWF_0036);
  wavetable13.setInstrument(AKWF_0036);
  wavetable14.setInstrument(AKWF_0036);  
  wavetable15.setInstrument(AKWF_0036);
  wavetable16.setInstrument(AKWF_0036);
  //set wavetable amplitudes
  wavetable1.amplitude(.2);
  wavetable2.amplitude(.2);
  wavetable3.amplitude(.2);
  wavetable4.amplitude(.2);
  wavetable5.amplitude(.2);
  wavetable6.amplitude(.2);
  wavetable7.amplitude(.2);
  wavetable8.amplitude(.2);
  wavetable9.amplitude(.2);
  wavetable10.amplitude(.2);
  wavetable11.amplitude(.2);
  wavetable12.amplitude(.2);
  wavetable13.amplitude(.2);
  wavetable14.amplitude(.2);
  wavetable15.amplitude(.2);
  wavetable16.amplitude(.2);

}

void loop()
{
  //play wavetables simultaneously and output processor usage to serial
  wavetable1.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable2.playNote(62);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable3.playNote(65);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable4.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  Serial.print("\n");
  wavetable5.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable6.playNote(62);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable7.playNote(65);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable8.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable9.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable10.playNote(62);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable11.playNote(65);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable12.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  Serial.print("\n");
  wavetable13.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable14.playNote(62);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable15.playNote(65);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  delay(1000);
  wavetable16.playNote(60);
  Serial.print((float)AudioProcessorUsage());
  Serial.print("\t");
  Serial.print((float)AudioProcessorUsageMax());
  Serial.print("\t");
  delay(1000);
  Serial.print("\n");
  wavetable1.stop();
  wavetable2.stop();
  wavetable3.stop();
  wavetable4.stop();
  wavetable5.stop();
  wavetable6.stop();
  wavetable7.stop();
  wavetable8.stop();
  wavetable9.stop();
  wavetable10.stop();
  wavetable11.stop();
  wavetable12.stop();
  wavetable13.stop();
  wavetable14.stop();
  wavetable15.stop();
  wavetable16.stop();
  delay(1000);
}

you will need the AKWF wavetables I linked above to run this simple example.
 
So what was the resolution to the clicking? Was it a bug you fixed, hardware failure, bad solder joint? Does the sketch you posted work now?

I'll be looking forward to your modulated wavetable module. I'm working on an envelope follower myself.

So it turns out it was the array declaration of the wavetables, I forgot I had encountered this before. For some reason you can't declare wavetables and then place them into array and set them, you have to declare the array of wavetables in an array initially, which unfortunately you have to do manually eg not use the audio tool
 
I did end up getting this working, stupidly forgot I had already encountered this error before a few months back.
Here is the first example working for anyone who might care:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include "AdventureKid.h"
#include "AcouPiano3_samples.h"

void InitMixers(AudioMixer4 mixerArray[]);
void InitWavetables(AudioSynthWavetable wavetableArray[], AudioSynthWavetable::instrument_data instDataArray[]);
void SetDAC(float volume);
void TestPolyphony(AudioSynthWavetable wavetableArray[]);

const int NUMMIXERS = 4;
const int NUMWAVETABLES = 16;

// GUItool: begin automatically generated code
/*
AudioSynthWavetable      wavetable[0];     //xy=69.5,20
AudioSynthWavetable      wavetable[1];     //xy=69.5,52
AudioSynthWavetable      wavetable[2];     //xy=69.5,84
AudioSynthWavetable      wavetable[3];     //xy=69.5,116
AudioSynthWavetable      wavetable[4];     //xy=69.5,151
AudioSynthWavetable      wavetable[5];     //xy=69.5,184
AudioSynthWavetable      wavetable[6];     //xy=69.5,218
AudioSynthWavetable      wavetable[7];     //xy=69.5,251
AudioSynthWavetable      wavetable[8];     //xy=69.5,288
AudioSynthWavetable      wavetable[9];    //xy=69.5,322
AudioSynthWavetable      wavetable[11];    //xy=73,388
AudioSynthWavetable      wavetable[10];    //xy=73.5,355
AudioSynthWavetable      wavetable[12];    //xy=73.5,423
AudioSynthWavetable      wavetable[13];    //xy=73.5,457
AudioSynthWavetable      wavetable[14];    //xy=73.5,490
AudioSynthWavetable      wavetable[15];    //xy=73.5,523
AudioMixer4              mixer[0];         //xy=208.5,70
AudioMixer4              mixer[1];         //xy=208.5,198
AudioMixer4              mixer[2];         //xy=208.5,339
AudioMixer4              mixer[3];         //xy=208,472
*/
AudioMixer4* mixer = new AudioMixer4[4];
AudioSynthWavetable* wavetable = new AudioSynthWavetable[16];
AudioMixer4              mixerOut;       //xy=352,268
AudioOutputI2S           i2s1;           //xy=479,267
AudioConnection          patchCord1(wavetable[0], 0, mixer[0], 0);
AudioConnection          patchCord2(wavetable[1], 0, mixer[0], 1);
AudioConnection          patchCord3(wavetable[2], 0, mixer[0], 2);
AudioConnection          patchCord4(wavetable[3], 0, mixer[0], 3);
AudioConnection          patchCord5(wavetable[4], 0, mixer[1], 0);
AudioConnection          patchCord6(wavetable[5], 0, mixer[1], 1);
AudioConnection          patchCord7(wavetable[6], 0, mixer[1], 2);
AudioConnection          patchCord8(wavetable[7], 0, mixer[1], 3);
AudioConnection          patchCord9(wavetable[8], 0, mixer[2], 0);
AudioConnection          patchCord10(wavetable[9], 0, mixer[2], 1);
AudioConnection          patchCord11(wavetable[11], 0, mixer[2], 3);
AudioConnection          patchCord12(wavetable[10], 0, mixer[2], 2);
AudioConnection          patchCord13(wavetable[12], 0, mixer[3], 0);
AudioConnection          patchCord14(wavetable[13], 0, mixer[3], 1);
AudioConnection          patchCord15(wavetable[14], 0, mixer[3], 2);
AudioConnection          patchCord16(wavetable[15], 0, mixer[3], 3);
AudioConnection          patchCord17(mixer[0], 0, mixerOut, 0);
AudioConnection          patchCord18(mixer[1], 0, mixerOut, 1);
AudioConnection          patchCord19(mixer[2], 0, mixerOut, 2);
AudioConnection          patchCord20(mixer[3], 0, mixerOut, 3);
AudioConnection          patchCord21(mixerOut, 0, i2s1, 0);
AudioConnection          patchCord22(mixerOut, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=543,437
// GUItool: end automatically generated code

AudioSynthWavetable::instrument_data adventureKid1[] =
{ 
 AKWF_0001, AKWF_0002, AKWF_0003, AKWF_0004, AKWF_0005, AKWF_0006, AKWF_0007, AKWF_0008, AKWF_0009, AKWF_0010, AKWF_0011, AKWF_0012,
 AKWF_0013, AKWF_0014, AKWF_0015, AKWF_0016, AKWF_0017, AKWF_0018, AKWF_0020, AKWF_0021, AKWF_0022, AKWF_0023, AKWF_0024, AKWF_0025, AKWF_0026, AKWF_0027, AKWF_0028, AKWF_0029, AKWF_0030,
 AKWF_0031, AKWF_0032, AKWF_0033, AKWF_0034, AKWF_0035, AKWF_0036, AKWF_0037, AKWF_0038, AKWF_0039, AKWF_0040, AKWF_0041, AKWF_0042, AKWF_0043, AKWF_0044, AKWF_0045, AKWF_0046, AKWF_0047,
 AKWF_0048, AKWF_0049, AKWF_0050, AKWF_0051, AKWF_0052, AKWF_0053, AKWF_0054, AKWF_0055, AKWF_0056, AKWF_0057, AKWF_0058, AKWF_0059, AKWF_0060, AKWF_0061, AKWF_0062, AKWF_0063, AKWF_0064,
 AKWF_0065, AKWF_0066, AKWF_0067, AKWF_0068, AKWF_0069, AKWF_0070, AKWF_0071, AKWF_0072, AKWF_0073, AKWF_0074, AKWF_0075, AKWF_0076, AKWF_0077, AKWF_0078, AKWF_0079, AKWF_0080, AKWF_0081,
 AKWF_0082, AKWF_0083, AKWF_0084, AKWF_0085, AKWF_0086, AKWF_0087, AKWF_0088, AKWF_0089, AKWF_0090, AKWF_0091, AKWF_0092, AKWF_0093, AKWF_0094, AKWF_0095, AKWF_0096, AKWF_0097, AKWF_0098,
 AKWF_0099, AKWF_0100, AKWF_0102, AKWF_0103, AKWF_0104, AKWF_0105, AKWF_0106, AKWF_0107, AKWF_0108, AKWF_0109, AKWF_0110, AKWF_0111, AKWF_0112, AKWF_0113, AKWF_0114, AKWF_0115, AKWF_0116,
 AKWF_0117, AKWF_0118, AKWF_0119, AKWF_0120, AKWF_0121, AKWF_0122, AKWF_0123, AKWF_0124, AKWF_0125, AKWF_0126, AKWF_0127
 };

void setup() 
{
Serial.begin(115200);
delay(500);
AudioMemory(128);
SetDAC(1.0);
InitMixers(mixer);
InitWavetables(wavetable, adventureKid1);
}

void loop() 
{
  TestPolyphony(wavetable);
}

void InitMixers(AudioMixer4 mixerArray[])
{
  for(int i = 0; i < NUMMIXERS; i++)
  {
    for(int j = 0; j < 4; j++)
    {
      mixerArray[i].gain(j, .25);
    }
  }
  for(int k = 0; k < 4; k++)
  {
    mixerOut.gain(k, .25);
  }
}

void InitWavetables(AudioSynthWavetable wavetableArray[], AudioSynthWavetable::instrument_data instDataArray[])
{
  for(int i = 0; i < NUMWAVETABLES; i++)
  {
    wavetableArray[i].setInstrument(instDataArray[(i+37)+(i)]);
    wavetableArray[i].amplitude(.2);
  }
}

void SetDAC(float volume)
{
  sgtl5000_1.enable();
  sgtl5000_1.volume(volume);
}

void TestPolyphony(AudioSynthWavetable wavetableArray[])
{
  for(int i = 0; i < NUMWAVETABLES; i++)
  {
    wavetableArray[i].playNote(60+(i%2), 127);
    Serial.print("Current Audioprocessor Load:\t");
    Serial.print((float)AudioProcessorUsage());
    Serial.print("\t");
    Serial.print("Voices:\t");
    Serial.print(i+1);
    Serial.println();
    delay(1000);
  }
  for(int i = 0; i < NUMWAVETABLES; i++)
  {
    wavetableArray[i].stop();
  }
  Serial.println();
  Serial.print("Audioprocessor Max: \t");
  Serial.print((float)AudioProcessorUsageMax());
  Serial.println();
  delay(1000);
}
 
I did end up getting this working, stupidly forgot I had already encountered this error before a few months back.
Here is the first example working for anyone who might care:

Code:
AudioSynthWavetable      wavetable[0];     //xy=69.5,20
AudioSynthWavetable      wavetable[1];     //xy=69.5,52
AudioSynthWavetable      wavetable[2];     //xy=69.5,84
AudioSynthWavetable      wavetable[3];     //xy=69.5,116
AudioSynthWavetable      wavetable[4];     //xy=69.5,151
AudioSynthWavetable      wavetable[5];     //xy=69.5,184
AudioSynthWavetable      wavetable[6];     //xy=69.5,218
AudioSynthWavetable      wavetable[7];     //xy=69.5,251
AudioSynthWavetable      wavetable[8];     //xy=69.5,288
AudioSynthWavetable      wavetable[9];    //xy=69.5,322
AudioSynthWavetable      wavetable[11];    //xy=73,388
AudioSynthWavetable      wavetable[10];    //xy=73.5,355
AudioSynthWavetable      wavetable[12];    //xy=73.5,423
AudioSynthWavetable      wavetable[13];    //xy=73.5,457
AudioSynthWavetable      wavetable[14];    //xy=73.5,490
AudioSynthWavetable      wavetable[15];    //xy=73.5,523
AudioMixer4              mixer[0];         //xy=208.5,70
AudioMixer4              mixer[1];         //xy=208.5,198
AudioMixer4              mixer[2];         //xy=208.5,339
AudioMixer4              mixer[3];         //xy=208,472
*/
}

OK, so basically just putting everything into brackets to make it part of an array?

AudioSynthWavetable wavetable15;

becomes

AudioSynthWavetable wavetable[15];

Makes sense. I just tried naming an object in the GUI Mixer[12] and it works just fine through the copy and paste code export, so shouldn't this just be a matter of naming things properly in the GUI as we sketch it out?

I'm a retired IT guy trying to get my embedded skills back. I think I understand how to make a custom effects module, but I'm not clear at all on how to make Arduino IDE recognize my object names like the others in the Teensy Audio library. I also am really struggling trying to figure out the hardware of the two FlexIO ports, as I am dead certain I can exploit PLL5 and a FlexIO clock pin to make an even simpler teensy SDR.
 
Yes, essentially what you do is use the audio design tool you can just use the bracket notation in the naming scheme to indicate the setup you desire, then in your editor comment out those declarations and declare them as a pointer array ie wavetable[0] wavetable[1] would be commented out and you would instead add the AudioSynthWavetable* wavetable = new AudioSynthWavetable[2]; There are other ways of doing this as well but the above manner is what I use.

Regarding custom library objects have you read the documentation? https://www.pjrc.com/teensy/td_libs_AudioNewObjects.html

I'm afraid I haven't messed with the FlexIO ports at all, although I imagine there are some helpful threads lurking somewhere in the forum.

Cheers!
 
Status
Not open for further replies.
Back
Top