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

Thread: where to start to learn programming teensy audio?

  1. #1

    where to start to learn programming teensy audio?

    hi, i m new to world of programming, can anyone send me a link where I could learn how to use teensy audio library please? I already read the workshop tutorial but I need more basic knowledge by exemple learning how to receive midi note from my controller and learn to implement controls to mixer volume or controlling a delay feedback...
    English is not my native language so I d prefer reading than watching video,
    the goal is to make a simple synth then implement more functions step by step.
    thanks for help!

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,735
    There are MIDI examples in :: ...\hardware\teensy\avr\libraries\Audio\examples\S ynthesis\

    Also the online GUI here :: pjrc.com/teensy/gui/?info=AudioSynthWavetable
    That link opens the first SYNTH item in the RIGHT frame - then lower LEFT frame under SYNTH are other SYNTH elements after AudioSynthWavetable that note examples for each in context.

    Hope that helps and one fits the ideas in mind - there may be other better - but not ever worked with Midi here.

  3. #3
    thanks, I have never seen that function were explain a little bit here! I ll try to understand a little bit more with it!
    thank you very much!
    i ll check if I find a way to use midi input

  4. #4
    i start making my code, do you think I m on a good way to declare button and potentiometer?
    does including the playsynthmusic.h will allow me to play midi notes according to fréquemment? it s what I thought I understood.

    ```cpp
    // Waveform Example - Create 2 waveforms with adjustable
    // frequency and phase
    //
    // This example is meant to be used with 3 buttons (pin 0,
    // 1, 2) and 2 knobs (pins 16/A2, 17/A3), which are present
    // on the audio tutorial kit.
    // https://www.pjrc.com/store/audio_tutorial_kit.html
    //
    // Use an oscilloscope to view the 2 waveforms.
    //
    // Button0 changes the waveform shape
    //
    // Knob A2 changes the frequency of both waveforms
    // You should see both waveforms "stretch" as you turn
    //
    // Knob A3 changes the phase of waveform #1
    // You should see the waveform shift horizontally
    //
    // This example code is in the public domain.
    #include <Encoder.h>
    #include <Control_Surface.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Bounce.h>
    #include "PlaySynthMusic.h"

    unsigned char *sp = score;

    USBMIDI_Interface usbmidi;

    AudioControlSGTL5000 sgtl5000_1; //xy=239,232

    // GUItool: begin automatically generated code
    AudioSynthWaveform waveform1; //xy=91,111
    AudioSynthWaveform waveform2; //xy=92,199
    AudioMixer4 mixer1; //xy=241,189
    AudioEffectDelay delay1; //xy=283,351
    AudioOutputI2S i2s2; //xy=305,140
    AudioEffectFreeverb freeverb1; //xy=429,435
    AudioOutputUSB usb1; //xy=567,331
    AudioConnection patchCord1(waveform1, 0, mixer1, 0);
    AudioConnection patchCord2(waveform2, 0, mixer1, 1);
    AudioConnection patchCord3(mixer1, delay1);
    AudioConnection patchCord4(delay1, 0, freeverb1, 0);
    AudioConnection patchCord5(freeverb1, 0, usb1, 0);
    AudioConnection patchCord6(freeverb1, 0, usb1, 1);
    // GUItool: end automatically generated code



    CD74HC4067 mux1 = {//déclare un multiplexeur
    A3, // numéro de broche de l'arduino
    {2, 3, 4, 5} // numéro de pins de l'arduino sur lesquels sont branchés tous les multiplexeurs apellés mux S0, S1, S2,S3
    };
    Bounce button0 = Bounce(mux1.pin(7), 15);
    Bounce button1 = Bounce(mux1.pin(8), 15);
    Bounce button2 = Bounce(mux1.pin(9), 15);
    Bounce button3 = Bounce(mux1.pin(10), 15);
    Bounce button4 = Bounce(mux1.pin(11), 15);
    Bounce button5 = Bounce(mux1.pin(12), 15);
    Bounce button6 = Bounce(mux1.pin(13), 15);
    Bounce button7 = Bounce(mux1.pin(14), 15);
    Bounce button8 = Bounce(mux1.pin(15), 15);

    int current_waveform=0;

    extern const int16_t myWaveform[256]; // defined in myWaveform.ino

    void setup() {
    Control_Surface.begin();
    Serial.begin(9600);
    pinMode(mux1.pin(7), INPUT_PULLUP);
    pinMode(mux1.pin(8), INPUT_PULLUP);
    pinMode(mux1.pin(9), INPUT_PULLUP);
    pinMode(mux1.pin(10), INPUT_PULLUP);
    pinMode(mux1.pin(11), INPUT_PULLUP);
    pinMode(mux1.pin(12), INPUT_PULLUP);
    pinMode(mux1.pin(13), INPUT_PULLUP);
    pinMode(mux1.pin(14), INPUT_PULLUP);
    pinMode(mux1.pin(15), INPUT_PULLUP);

    // Audio connections require memory to work. For more
    // detailed information, see the MemoryAndCpuUsage example
    AudioMemory(10);

    // Comment these out if not using the audio adaptor board.
    // This may wait forever if the SDA & SCL pins lack
    // pullup resistors
    sgtl5000_1.enable();
    sgtl5000_1.volume(0.8); // caution: very loud - use oscilloscope only!

    // Confirgure both to use "myWaveform" for WAVEFORM_ARBITRARY
    waveform1.arbitraryWaveform(myWaveform, 172.0);
    waveform2.arbitraryWaveform(myWaveform, 172.0);

    // configure both waveforms for 440 Hz and maximum amplitude
    waveform1.frequency(440);
    waveform2.frequency(440);
    waveform1.amplitude(0.5);
    waveform2.amplitude(0.5);

    current_waveform = WAVEFORM_TRIANGLE;
    waveform1.begin(current_waveform);
    }
    mixer1.gain(0, 0.5);
    mixer1.gain(1, 0.5);
    CD74HC4067 mux4 = {
    A2
    , // Analog input pin
    {2, 3, 4, 5} // Address pins S0, S1, S2};
    };
    void loop() {
    Control_Surface.loop();
    // Read the buttons and knobs, scale knobs to 0-1.0
    button0.update();
    button1.update();
    button2.update();
    button3.update();
    button4.update();
    button5.update();
    button6.update();
    button7.update();
    button8.update();
    int knob_1 = (float)analogRead(mux4.pin(7)) / 1023.0;
    int knob_2 = (float)analogRead(mux4.pin(6)) / 1023.0;
    int knob_3 = (float)analogRead(mux4.pin(5)) / 1023.0;
    int knob_4 = (float)analogRead(mux4.pin(4)) / 1023.0;
    int knob_5 = (float)analogRead(mux4.pin(3)) / 1023.0;
    int knob_6 = (float)analogRead(mux4.pin(2)) / 1023.0;
    int knob_7 = (float)analogRead(mux4.pin(1)) / 1023.0;
    int knob_8 = (float)analogRead(mux4.pin(0)) / 1023.0;
    int knob_1 = (float)analogRead(mux4.pin(8)) / 1023.0;
    int knob_2 = (float)analogRead(mux4.pin(9)) / 1023.0;
    int knob_3 = (float)analogRead(mux4.pin(10)) / 1023.0;
    int knob_4 = (float)analogRead(mux4.pin(11)) / 1023.0;
    int knob_5 = (float)analogRead(mux4.pin(12)) / 1023.0;
    int knob_6 = (float)analogRead(mux4.pin(13)) / 1023.0;
    int knob_7 = (float)analogRead(mux4.pin(14)) / 1023.0;
    int knob_8 = (float)analogRead(mux4.pin(15)) / 1023.0;

    float gain1 = (float)analogRead(mux4.pin(7)) / 1023.0;
    float gain2 = (float)analogRead(mux4.pin(6)) / 1023.0;
    float knob_3 = (float)analogRead(mux4.pin(5)) / 1023.0;
    float knob_4 = (float)analogRead(mux4.pin(4)) / 1023.0;
    float knob_5 = (float)analogRead(mux4.pin(3)) / 1023.0;
    float knob_6 = (float)analogRead(mux4.pin(2)) / 1023.0;
    float knob_7 = (float)analogRead(mux4.pin(1)) / 1023.0;
    float knob_8 = (float)analogRead(mux4.pin(0)) / 1023.0;
    float knob_1 = (float)analogRead(mux4.pin(8)) / 1023.0;
    float knob_2 = (float)analogRead(mux4.pin(9)) / 1023.0;
    float knob_3 = (float)analogRead(mux4.pin(10)) / 1023.0;
    float knob_4 = (float)analogRead(mux4.pin(11)) / 1023.0;
    float knob_5 = (float)analogRead(mux4.pin(12)) / 1023.0;
    float knob_6 = (float)analogRead(mux4.pin(13)) / 1023.0;
    float knob_7 = (float)analogRead(mux4.pin(14)) / 1023.0;
    float knob_8 = (float)analogRead(mux4.pin(15)) / 1023.0;

    AudioNoInterrupts();
    // use Knob 1 to adjust the frequency of both waveforms
    waveform1.frequency(100.0 + knob_1 * 900.0);
    waveform2.frequency(100.0 + knob_1 * 900.0);

    // use Knob A3 to adjust the phase of only waveform #1
    waveform1.phase(knob_A3 * 360.0);
    AudioInterrupts();

    // Button 0 changes the waveform type
    if (button0.fallingEdge()) {
    switch (current_waveform) {
    case WAVEFORM_SINE:
    current_waveform = WAVEFORM_SAWTOOTH;
    Serial.println("Sawtooth");
    break;
    case WAVEFORM_SAWTOOTH:
    current_waveform = WAVEFORM_SAWTOOTH_REVERSE;
    Serial.println("Reverse Sawtooth");
    break;
    case WAVEFORM_SAWTOOTH_REVERSE:
    current_waveform = WAVEFORM_SQUARE;
    Serial.println("Square");
    break;
    case WAVEFORM_SQUARE:
    current_waveform = WAVEFORM_TRIANGLE;
    Serial.println("Triangle");
    break;
    case WAVEFORM_TRIANGLE:
    current_waveform = WAVEFORM_TRIANGLE_VARIABLE;
    Serial.println("Variable Triangle");
    break;
    case WAVEFORM_TRIANGLE_VARIABLE:
    current_waveform = WAVEFORM_ARBITRARY;
    Serial.println("Arbitary Waveform");
    break;
    case WAVEFORM_ARBITRARY:
    current_waveform = WAVEFORM_PULSE;
    Serial.println("Pulse");
    break;
    case WAVEFORM_PULSE:
    current_waveform = WAVEFORM_SAMPLE_HOLD;
    Serial.println("Sample & Hold");
    break;
    case WAVEFORM_SAMPLE_HOLD:
    current_waveform = WAVEFORM_SINE;
    Serial.println("Sine");
    break;
    }
    AudioNoInterrupts();
    waveform1.begin(current_waveform);
    waveform2.begin(WAVEFORM_SINE);
    AudioInterrupts();
    }

    }

    ```

  5. #5
    Junior Member
    Join Date
    Mar 2015
    Location
    Toulouse, France
    Posts
    4
    Yes it's a video, but with subtitles available and very good explanations : https://www.youtube.com/watch?v=UJcZxyB5rVc

Posting Permissions

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