Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Dynamic audio patching

  1. #1
    Junior Member
    Join Date
    Jan 2020

    Dynamic audio patching

    Firstly, I want to thank Paul and all contributors for developing this wonderful Audio Library! This is seriously the most advanced audio library for Arduino world.

    I was reading documentation of the Audio Lib and roadmap notes on and noticed this paragraph:

    Today, the audio objects really need to be statically allocated. Some distant future version will feature working object destructors, and constructors capable of adding objects and connections into a live system.
    I do understand that this might not be easily achieved in the current version but could someone provide me with a starting point or a basic example of how one could implement dynamic construction and destruction of audio nodes? E.g. dynamically creating a mixer, an audio connection and re-routing audio through them? At the moment we can only .connect() and .disconnect() AudioConnections on the fly. I could try to implement dynamic audio nodes.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Oh, that's old info. There is now support for changing the connections at runtime.

  3. #3
    Junior Member
    Join Date
    Jan 2020
    I'm able to change the connections, but how about creating a new audio node, like an oscillator?

  4. #4
    Why not create an object pool of desired audio objects? Actually, I'm not sure this approach would make sense in this case. Why don't you figure out the maximal number of oscillators you need and use the amp or mixer to turn a voice off? For example you could use the midisynth example and adapt each voice to have up to 4 oscillators per voice mixer. Then you can simply use the built in polyphony for that sketch and you will have the maximal number of oscillators for your particular teensy

  5. #5 here is an example expanding the mono synth from the Notes and Volts tutorial. You can simply add more oscillators to a given voice i think he has 2 osc + 1 noise per mixer. You could remove the noise and add two more oscillators per voice. Adding unison would be as simple as duplicating a voice on any one of the 16 midi channels. I can't think of a use case where you would really need more than 4 oscillators per voice. I haven't seen many if any synthesizers with more than 4 that aren't FM operators. If for some reason you wanted say 16 osc on one voice though you would simply need to chain the mixers eg 4 4 osc mixers into a mixer = 16 osc, add another mixer layer and you have 64 oscillators, etc
    Last edited by RABB17; 01-30-2020 at 07:24 PM. Reason: clarity

  6. #6
    Using 64 waveform oscillators in such a fashion doesn't really use much of the teensy resources:

    Attachment 18915

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    // GUItool: begin automatically generated code
    AudioSynthWaveform       waveform2;      //xy=64,56
    AudioSynthWaveform       waveform3;      //xy=64,92
    AudioSynthWaveform       waveform4;      //xy=64,125
    AudioSynthWaveform       waveform6; //xy=64,203
    AudioSynthWaveform       waveform7; //xy=64,239
    AudioSynthWaveform       waveform1;      //xy=65,20
    AudioSynthWaveform       waveform8; //xy=64,272
    AudioSynthWaveform       waveform5; //xy=65,167
    AudioSynthWaveform       waveform10; //xy=68,348
    AudioSynthWaveform       waveform11; //xy=68,384
    AudioSynthWaveform       waveform12; //xy=68,417
    AudioSynthWaveform       waveform14; //xy=68,494
    AudioSynthWaveform       waveform15; //xy=68,530
    AudioSynthWaveform       waveform9; //xy=69,312
    AudioSynthWaveform       waveform16; //xy=68,563
    AudioSynthWaveform       waveform13; //xy=69,458
    AudioMixer4              mixer1;         //xy=194,70
    AudioMixer4              mixer2; //xy=194,217
    AudioMixer4              mixer3; //xy=198,362
    AudioMixer4              mixer4; //xy=198,508
    AudioMixer4              mixer5;         //xy=376,294
    AudioSynthWaveform       waveform18; //xy=384,388
    AudioSynthWaveform       waveform19; //xy=384,424
    AudioSynthWaveform       waveform20; //xy=384,457
    AudioSynthWaveform       waveform22; //xy=384,535
    AudioSynthWaveform       waveform23; //xy=384,571
    AudioSynthWaveform       waveform17; //xy=385,352
    AudioSynthWaveform       waveform24; //xy=384,604
    AudioSynthWaveform       waveform21; //xy=385,499
    AudioSynthWaveform       waveform26; //xy=388,680
    AudioSynthWaveform       waveform27; //xy=388,716
    AudioSynthWaveform       waveform28; //xy=388,749
    AudioSynthWaveform       waveform30; //xy=388,826
    AudioSynthWaveform       waveform31; //xy=388,862
    AudioSynthWaveform       waveform25; //xy=389,644
    AudioSynthWaveform       waveform32; //xy=388,895
    AudioSynthWaveform       waveform29; //xy=389,790
    AudioMixer4              mixer6; //xy=514,402
    AudioMixer4              mixer7; //xy=514,549
    AudioMixer4              mixer8; //xy=518,694
    AudioMixer4              mixer9; //xy=518,840
    AudioMixer4              mixer_a; //xy=696,626
    AudioSynthWaveform       waveform34; //xy=701,718
    AudioSynthWaveform       waveform35;  //xy=701,754
    AudioSynthWaveform       waveform36; //xy=701,787
    AudioSynthWaveform       waveform38; //xy=701,865
    AudioSynthWaveform       waveform39; //xy=701,901
    AudioMixer4              mixer_out;         //xy=704,158
    AudioSynthWaveform       waveform33; //xy=702,682
    AudioSynthWaveform       waveform40; //xy=701,934
    AudioSynthWaveform       waveform37; //xy=702,829
    AudioSynthWaveform       waveform42; //xy=705,1010
    AudioSynthWaveform       waveform43; //xy=705,1046
    AudioSynthWaveform       waveform44; //xy=705,1079
    AudioSynthWaveform       waveform46; //xy=705,1156
    AudioSynthWaveform       waveform47; //xy=705,1192
    AudioSynthWaveform       waveform41; //xy=706,974
    AudioSynthWaveform       waveform48; //xy=705,1225
    AudioSynthWaveform       waveform45;  //xy=706,1120
    AudioMixer4              mixer10; //xy=831,732
    AudioMixer4              mixer11; //xy=831,879
    AudioMixer4              mixer12; //xy=835,1024
    AudioMixer4              mixer13; //xy=835,1170
    AudioOutputI2S           i2s1;           //xy=864,158
    AudioMixer4              mixer14; //xy=1013,956
    AudioSynthWaveform       waveform50; //xy=1013,1051
    AudioSynthWaveform       waveform51; //xy=1013,1087
    AudioSynthWaveform       waveform52; //xy=1013,1120
    AudioSynthWaveform       waveform54; //xy=1013,1198
    AudioSynthWaveform       waveform55; //xy=1013,1234
    AudioSynthWaveform       waveform49; //xy=1014,1015
    AudioSynthWaveform       waveform56; //xy=1013,1267
    AudioSynthWaveform       waveform53; //xy=1014,1162
    AudioSynthWaveform       waveform58; //xy=1017,1343
    AudioSynthWaveform       waveform59; //xy=1017,1379
    AudioSynthWaveform       waveform60; //xy=1017,1412
    AudioSynthWaveform       waveform62; //xy=1017,1489
    AudioSynthWaveform       waveform63; //xy=1017,1525
    AudioSynthWaveform       waveform57; //xy=1018,1307
    AudioSynthWaveform       waveform64; //xy=1017,1558
    AudioSynthWaveform       waveform61; //xy=1018,1453
    AudioMixer4              mixer15; //xy=1143,1065
    AudioMixer4              mixer16; //xy=1143,1212
    AudioMixer4              mixer17; //xy=1147,1357
    AudioMixer4              mixer18; //xy=1147,1503
    AudioMixer4              mixer19; //xy=1325,1289
    AudioConnection          patchCord1(waveform2, 0, mixer1, 1);
    AudioConnection          patchCord2(waveform3, 0, mixer1, 2);
    AudioConnection          patchCord3(waveform4, 0, mixer1, 3);
    AudioConnection          patchCord4(waveform6, 0, mixer2, 1);
    AudioConnection          patchCord5(waveform7, 0, mixer2, 2);
    AudioConnection          patchCord6(waveform1, 0, mixer1, 0);
    AudioConnection          patchCord7(waveform8, 0, mixer2, 3);
    AudioConnection          patchCord8(waveform5, 0, mixer2, 0);
    AudioConnection          patchCord9(waveform10, 0, mixer3, 1);
    AudioConnection          patchCord10(waveform11, 0, mixer3, 2);
    AudioConnection          patchCord11(waveform12, 0, mixer3, 3);
    AudioConnection          patchCord12(waveform14, 0, mixer4, 1);
    AudioConnection          patchCord13(waveform15, 0, mixer4, 2);
    AudioConnection          patchCord14(waveform9, 0, mixer3, 0);
    AudioConnection          patchCord15(waveform16, 0, mixer4, 3);
    AudioConnection          patchCord16(waveform13, 0, mixer4, 0);
    AudioConnection          patchCord17(mixer1, 0, mixer5, 0);
    AudioConnection          patchCord18(mixer2, 0, mixer5, 1);
    AudioConnection          patchCord19(mixer3, 0, mixer5, 2);
    AudioConnection          patchCord20(mixer4, 0, mixer5, 3);
    AudioConnection          patchCord21(mixer5, 0, mixer_out, 0);
    AudioConnection          patchCord22(waveform18, 0, mixer6, 1);
    AudioConnection          patchCord23(waveform19, 0, mixer6, 2);
    AudioConnection          patchCord24(waveform20, 0, mixer6, 3);
    AudioConnection          patchCord25(waveform22, 0, mixer7, 1);
    AudioConnection          patchCord26(waveform23, 0, mixer7, 2);
    AudioConnection          patchCord27(waveform17, 0, mixer6, 0);
    AudioConnection          patchCord28(waveform24, 0, mixer7, 3);
    AudioConnection          patchCord29(waveform21, 0, mixer7, 0);
    AudioConnection          patchCord30(waveform26, 0, mixer8, 1);
    AudioConnection          patchCord31(waveform27, 0, mixer8, 2);
    AudioConnection          patchCord32(waveform28, 0, mixer8, 3);
    AudioConnection          patchCord33(waveform30, 0, mixer9, 1);
    AudioConnection          patchCord34(waveform31, 0, mixer9, 2);
    AudioConnection          patchCord35(waveform25, 0, mixer8, 0);
    AudioConnection          patchCord36(waveform32, 0, mixer9, 3);
    AudioConnection          patchCord37(waveform29, 0, mixer9, 0);
    AudioConnection          patchCord38(mixer6, 0, mixer_a, 0);
    AudioConnection          patchCord39(mixer7, 0, mixer_a, 1);
    AudioConnection          patchCord40(mixer8, 0, mixer_a, 2);
    AudioConnection          patchCord41(mixer9, 0, mixer_a, 3);
    AudioConnection          patchCord42(mixer_a, 0, mixer_out, 1);
    AudioConnection          patchCord43(waveform34, 0, mixer10, 1);
    AudioConnection          patchCord44(waveform35, 0, mixer10, 2);
    AudioConnection          patchCord45(waveform36, 0, mixer10, 3);
    AudioConnection          patchCord46(waveform38, 0, mixer11, 1);
    AudioConnection          patchCord47(waveform39, 0, mixer11, 2);
    AudioConnection          patchCord48(mixer_out, 0, i2s1, 0);
    AudioConnection          patchCord49(mixer_out, 0, i2s1, 1);
    AudioConnection          patchCord50(waveform33, 0, mixer10, 0);
    AudioConnection          patchCord51(waveform40, 0, mixer11, 3);
    AudioConnection          patchCord52(waveform37, 0, mixer11, 0);
    AudioConnection          patchCord53(waveform42, 0, mixer12, 1);
    AudioConnection          patchCord54(waveform43, 0, mixer12, 2);
    AudioConnection          patchCord55(waveform44, 0, mixer12, 3);
    AudioConnection          patchCord56(waveform46, 0, mixer13, 1);
    AudioConnection          patchCord57(waveform47, 0, mixer13, 2);
    AudioConnection          patchCord58(waveform41, 0, mixer12, 0);
    AudioConnection          patchCord59(waveform48, 0, mixer13, 3);
    AudioConnection          patchCord60(waveform45, 0, mixer13, 0);
    AudioConnection          patchCord61(mixer10, 0, mixer14, 0);
    AudioConnection          patchCord62(mixer11, 0, mixer14, 1);
    AudioConnection          patchCord63(mixer12, 0, mixer14, 2);
    AudioConnection          patchCord64(mixer13, 0, mixer14, 3);
    AudioConnection          patchCord65(mixer14, 0, mixer_out, 2);
    AudioConnection          patchCord66(waveform50, 0, mixer15, 1);
    AudioConnection          patchCord67(waveform51, 0, mixer15, 2);
    AudioConnection          patchCord68(waveform52, 0, mixer15, 3);
    AudioConnection          patchCord69(waveform54, 0, mixer16, 1);
    AudioConnection          patchCord70(waveform55, 0, mixer16, 2);
    AudioConnection          patchCord71(waveform49, 0, mixer15, 0);
    AudioConnection          patchCord72(waveform56, 0, mixer16, 3);
    AudioConnection          patchCord73(waveform53, 0, mixer16, 0);
    AudioConnection          patchCord74(waveform58, 0, mixer17, 1);
    AudioConnection          patchCord75(waveform59, 0, mixer17, 2);
    AudioConnection          patchCord76(waveform60, 0, mixer17, 3);
    AudioConnection          patchCord77(waveform62, 0, mixer18, 1);
    AudioConnection          patchCord78(waveform63, 0, mixer18, 2);
    AudioConnection          patchCord79(waveform57, 0, mixer17, 0);
    AudioConnection          patchCord80(waveform64, 0, mixer18, 3);
    AudioConnection          patchCord81(waveform61, 0, mixer18, 0);
    AudioConnection          patchCord82(mixer15, 0, mixer19, 0);
    AudioConnection          patchCord83(mixer16, 0, mixer19, 1);
    AudioConnection          patchCord84(mixer17, 0, mixer19, 2);
    AudioConnection          patchCord85(mixer18, 0, mixer19, 3);
    AudioConnection          patchCord86(mixer19, 0, mixer_out, 3);
    AudioControlSGTL5000     sgtl5000_1;     //xy=822,276
    // GUItool: end automatically generated code
    void setup()
    void loop()
    I've included a blank sketch instantiating such a scheme. You can just copy the code and import it into the design tool to see what I mean.

  7. #7
    Unless your objective is more a midi player using the midisynth examples polyphonic setup you can just create a bank of effects and use amps and dynamic patching for your individual voices. 8 - 10 fx banks seems reasonable as you only have 10 fingers. If you are after a midi player specifically as opposed to a synth you might be better off using a raspberry pi 0 and a hifiberry or some similar dac breakout.

  8. #8
    Senior Member
    Join Date
    Feb 2017
    Quote Originally Posted by latedriver View Post
    I'm able to change the connections, but how about creating a new audio node, like an oscillator?
    Since the audio nodes are regular C++ classes, you can instantiate them dynamically using the standard C++ technique (i.e. 'new'). Then, create the links between them.

  9. #9
    Quote Originally Posted by PaulStoffregen View Post
    Oh, that's old info. There is now support for changing the connections at runtime.
    Is there a reference page or document covering this information?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts