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

Thread: LoopPad

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    18

    LoopPad

    Hello everyone, I'm making an audio project and I need some help.
    I have some questis. Here I post my Audio System Design and in case you need the code I will post.
    (
    Code:
     
    
    // GUItool: begin automatically generated code
    AudioSynthWaveform       waveform3;      //xy=88.75,1306.25
    AudioSynthSimpleDrum     drum3;          //xy=90.5,1362.2500610351562
    AudioSynthWavetable      wavetable3;     //xy=90.5,1389.7500610351562
    AudioSynthWavetable      wavetable2;     //xy=91.25,1276.5
    AudioSynthWavetable      wavetable4;     //xy=90.5,1500.2501220703125
    AudioSynthSimpleDrum     drum4;          //xy=91.75,1474.0000915527343
    AudioSynthWaveform       waveform2;      //xy=93.24998474121094,1196.7500305175781
    AudioSynthToneSweep      tonesweep3;     //xy=92.75,1334.25
    AudioSynthWaveform       waveform4;      //xy=93.75,1419.25
    AudioSynthToneSweep      tonesweep2;     //xy=94.75,1227.25
    AudioSynthSimpleDrum     drum1;          //xy=97.75,1141.7500610351562
    AudioSynthWavetable      wavetable1;     //xy=97.74996948242187,1168.0000610351562
    AudioSynthToneSweep      tonesweep1;     //xy=98.75,1116.25
    AudioSynthToneSweep      tonesweep4;     //xy=97.75,1447.25
    AudioSynthSimpleDrum     drum2;          //xy=98.75,1252.75
    AudioSynthWaveform       waveform1;      //xy=99.75,1095.25
    AudioPlaySdRaw           playRaw1;       //xy=100.75,962.25
    AudioPlaySdRaw           playRaw2;       //xy=101.75,993.25
    AudioPlaySdRaw           playRaw3;       //xy=102.75,1024.25
    AudioPlaySdRaw           playRaw4;       //xy=102.75,1055.25
    AudioInputAnalogStereo   adcs1;          //xy=114.75,917.25
    AudioSynthWaveformSineModulated filterSine;     //xy=125.75,734.25
    AudioEffectFreeverb      filterReverb;   //xy=130.75,802.25
    AudioEffectBitcrusher    filterCrush;    //xy=133.75,768.25
    AudioEffectReverb        reverb2;        //xy=233.75003051757812,1202.5
    AudioEffectFade          fade4;          //xy=233.75,1482.4999694824218
    AudioEffectFade          fade3;          //xy=234.99996948242187,1376.25
    AudioEffectFade          fade1;          //xy=237.5,1160
    AudioEffectReverb        reverb4;        //xy=238.75003051757812,1417.5
    AudioEffectReverb        reverb3;        //xy=241.25006103515625,1306.25
    AudioEffectFade          fade2;          //xy=243.75,1260
    AudioEffectReverb        reverb1;        //xy=246.25003051757812,1096.25
    AudioMixer4              mixerGuitar;    //xy=296.75,861.25
    AudioMixer4              mixerTrack;     //xy=316.75,1003.25
    AudioMixer4              mixerTap1;      //xy=394,1125
    AudioMixer4              mixerTap2;      //xy=396.2499694824219,1229.5000305175781
    AudioMixer4              mixerTap4;      //xy=399.25,1435.7499389648437
    AudioMixer4              mixerTap3;      //xy=400.5000305175781,1330.2500915527343
    AudioFilterBiquad        filterBiquad;   //xy=437.75,860.25
    AudioMixer4              mixerSynth;     //xy=621.75,1260.25
    AudioMixer4              mixerOut;       //xy=701.2500610351562,983.75
    AudioMixer4              mixerRecord;    //xy=769.25,756.7500305175781
    AudioRecordQueue         queue1;         //xy=778.75,861.25
    AudioOutputAnalogStereo  dacs1;          //xy=868.0000610351562,985.9999694824219
    AudioConnection          patchCord1(waveform3, reverb3);
    AudioConnection          patchCord2(drum3, 0, mixerTap3, 2);
    AudioConnection          patchCord3(wavetable3, fade3);
    AudioConnection          patchCord4(wavetable2, fade2);
    AudioConnection          patchCord5(wavetable4, fade4);
    AudioConnection          patchCord6(drum4, 0, mixerTap4, 2);
    AudioConnection          patchCord7(waveform2, reverb2);
    AudioConnection          patchCord8(tonesweep3, 0, mixerTap3, 1);
    AudioConnection          patchCord9(waveform4, reverb4);
    AudioConnection          patchCord10(tonesweep2, 0, mixerTap2, 1);
    AudioConnection          patchCord11(drum1, 0, mixerTap1, 2);
    AudioConnection          patchCord12(wavetable1, fade1);
    AudioConnection          patchCord13(tonesweep1, 0, mixerTap1, 1);
    AudioConnection          patchCord14(tonesweep4, 0, mixerTap4, 1);
    AudioConnection          patchCord15(drum2, 0, mixerTap2, 2);
    AudioConnection          patchCord16(waveform1, reverb1);
    AudioConnection          patchCord17(playRaw1, 0, mixerTrack, 0);
    AudioConnection          patchCord18(playRaw2, 0, mixerTrack, 1);
    AudioConnection          patchCord19(playRaw3, 0, mixerTrack, 2);
    AudioConnection          patchCord20(playRaw4, 0, mixerTrack, 3);
    AudioConnection          patchCord21(adcs1, 0, filterSine, 0);
    AudioConnection          patchCord22(adcs1, 0, filterCrush, 0);
    AudioConnection          patchCord23(adcs1, 0, filterReverb, 0);
    AudioConnection          patchCord24(adcs1, 0, mixerGuitar, 0);
    AudioConnection          patchCord25(adcs1, 1, mixerOut, 1);
    AudioConnection          patchCord26(adcs1, 1, mixerRecord, 1);
    AudioConnection          patchCord27(filterSine, 0, mixerGuitar, 1);
    AudioConnection          patchCord28(filterReverb, 0, mixerGuitar, 3);
    AudioConnection          patchCord29(filterCrush, 0, mixerGuitar, 2);
    AudioConnection          patchCord30(reverb2, 0, mixerTap2, 0);
    AudioConnection          patchCord31(fade4, 0, mixerTap4, 3);
    AudioConnection          patchCord32(fade3, 0, mixerTap3, 3);
    AudioConnection          patchCord33(fade1, 0, mixerTap1, 3);
    AudioConnection          patchCord34(reverb4, 0, mixerTap4, 0);
    AudioConnection          patchCord35(reverb3, 0, mixerTap3, 0);
    AudioConnection          patchCord36(fade2, 0, mixerTap2, 3);
    AudioConnection          patchCord37(reverb1, 0, mixerTap1, 0);
    AudioConnection          patchCord38(mixerGuitar, filterBiquad);
    AudioConnection          patchCord39(mixerTrack, 0, mixerOut, 2);
    AudioConnection          patchCord40(mixerTrack, 0, mixerRecord, 2);
    AudioConnection          patchCord41(mixerTap1, 0, mixerSynth, 0);
    AudioConnection          patchCord42(mixerTap2, 0, mixerSynth, 1);
    AudioConnection          patchCord43(mixerTap4, 0, mixerSynth, 3);
    AudioConnection          patchCord44(mixerTap3, 0, mixerSynth, 2);
    AudioConnection          patchCord45(filterBiquad, 0, mixerRecord, 0);
    AudioConnection          patchCord46(filterBiquad, 0, mixerOut, 0);
    AudioConnection          patchCord47(mixerSynth, 0, mixerOut, 3);
    AudioConnection          patchCord48(mixerSynth, 0, mixerRecord, 3);
    AudioConnection          patchCord49(mixerOut, 0, dacs1, 0);
    AudioConnection          patchCord50(mixerOut, 0, dacs1, 1);
    AudioConnection          patchCord51(mixerRecord, queue1);
    AudioControlWM8731       wm8731_1;       //xy=844.25,1093.4999389648437
    // GUItool: end automatically generated code
    )

    1) as you can see I have many audio reproduced at the same time, can it be a problem? In case it is, how can I fix?

    2) My intent is to use virtual pin to comunicate with the board so I bought an HC-05 to comunicate with an android devise. I would like to use Virtuino to develope the control panel. I use VirtuinoBluetooth.h but I don't understand how define the pin in the IDE code

    3) I have a teensy 3.6 and I don't have the audio board ( I use WM8731, is it correct? ). I can use any Analog pin to sample the input sound, isn't? Moreover if I want to connect a guitar jack to the input, do I need to amplify the signal? or the circuit shown in the description of the ADC is sufficient?


    thanks for your help

  2. #2
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    Hi, I'm using teensy 3.6 for this project. here you can see my code:
    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <String.h>
    #include <Bounce.h>
    
    // GUItool: begin automatically generated code
    AudioPlaySdRaw           playRaw1;       //xy=100.75,962.25
    AudioPlaySdRaw           playRaw2;       //xy=101.75,993.25
    AudioPlaySdRaw           playRaw3;       //xy=102.75,1024.25
    AudioPlaySdRaw           playRaw4;       //xy=102.75,1055.25
    AudioInputAnalog         adc1;           //xy=117.49998474121094,902.5
    AudioEffectFreeverb      filterReverb;   //xy=339.5,851.75
    AudioMixer4              mixerTrack;     //xy=455.5,993.2500610351562
    AudioEffectBitcrusher    filterCrush;    //xy=461,893
    AudioSynthWaveformSineModulated filterSine;     //xy=562.75,846
    AudioMixer4              mixerOut;       //xy=701.2500610351562,983.75
    AudioMixer4              mixerRecord;    //xy=769.25,756.7500305175781
    AudioRecordQueue         queue1;         //xy=778.75,861.25
    AudioOutputAnalog        dac1;           //xy=870,980
    AudioConnection          patchCord1(playRaw1, 0, mixerTrack, 0);
    AudioConnection          patchCord2(playRaw2, 0, mixerTrack, 1);
    AudioConnection          patchCord3(playRaw3, 0, mixerTrack, 2);
    AudioConnection          patchCord4(playRaw4, 0, mixerTrack, 3);
    AudioConnection          patchCord5(adc1, filterReverb);
    AudioConnection          patchCord6(adc1, 0, mixerRecord, 1);
    AudioConnection          patchCord7(adc1, 0, mixerOut, 1);
    AudioConnection          patchCord8(filterReverb, filterCrush);
    AudioConnection          patchCord9(mixerTrack, 0, mixerOut, 2);
    AudioConnection          patchCord10(filterCrush, filterSine);
    AudioConnection          patchCord11(filterSine, 0, mixerRecord, 0);
    AudioConnection          patchCord12(filterSine, 0, mixerOut, 0);
    AudioConnection          patchCord13(mixerOut, dac1);
    AudioConnection          patchCord14(mixerRecord, queue1);
    AudioControlWM8731       wm8731_1;       //xy=844.25,1093.4999389648437
    // GUItool: end automatically generated code
    
    
    const int Guitar = A2;         
    const int Mic = A3; 
    const int bottone = 2;
    const int ingressoBottone=3;
    
    // THE VARIABLE
    float valuePoten[4]={};             //valori 0-1 dei potenziometri
    bool modeChange=false;              //utilizzata per il cambio di mode nella LS o nel MENU
    
    //  for LoopStation
    const int numTracks=1;
    String nameTrack[]={"Tr1.RAW" ,"Tr2.RAW" ,"Tr3.RAW" ,"Tr4.RAW" , "Tr5.RAW" ,"Tr6.RAW" ,"Tr7.RAW" ,"Tr8.RAW" , "Tr9.RAW" ,"Tr10.RAW" ,"Tr11.RAW" ,"Tr12.RAW"};
    int nNameTrack=0; // serve per evitare la sovrascrizione d tracce
    int n=0;
    char filename[9];
    int modeLS={};  
    // 0=empty, 1=recording, 2=stopRec&loop 3=stop 4=loop 5=3
    
    //for MENU
    int ingresso=0; // 0=guitar, 1=effected guitar, 2=microfono         CONTROLLARE CON LA MISURA DEI VALORI
    int ingressoPr; // Precedente per evitare ripetizion superflue
    
    //for Info
    int t0;   //salva il momento in cui  iniziato la reg
    int timeTrack=0; // salva le durat delle tracce registrate
    int tL=0;  // serve per la isualizzazione del tempo-metro 
    int temp;
    
    #define SDCARD_CS_PIN    BUILTIN_SDCARD
    File frec;
    
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(60*numTracks);
    
      wm8731_1.enable();
      wm8731_1.inputSelect(Guitar);
      wm8731_1.volume(0.5);
    
      // Initialize the SD card
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
    
      pinMode(2,INPUT);
      pinMode(3,INPUT);
      
     // inizializzo i mixer e i filter
     mixerRecord.gain(0,1);
     mixerRecord.gain(1,0);
     mixerTrack.gain(0,0.25);
     mixerTrack.gain(1,0.25);
     mixerTrack.gain(2,0.25);
     mixerTrack.gain(3,0.25); 
     mixerOut.gain(0,0.5);
     mixerOut.gain(1,0);
     mixerOut.gain(2,0.5);
     filterReverb.roomsize(0);
     filterReverb.damping(1);
     filterSine.amplitude(1);
     filterSine.frequency(0);
     filterCrush.bits(16);
     
    }
    
    void loop() {
      modeChange=false;
      
      if (digitalRead(bottone)==1){    //se  premuto il tasto n-esimo
        modeChange=true;  
        Serial.println("cambio mode");
        delay(200);
      }
    
    if(modeChange){                       //se la modalita cambia
        modeLS=modeLS+1;              //incremento la modeLS
        if (modeLS == 5) modeLS=3;    //rendo le modalita cicliche
        switch (modeLS){                 //in relazione alla mode 
          case 1: startRecording();         //inizio a registrare
                  break;
          case 2: stopRecording();          //fermo la registrazione 
                  startPlaying();           //e inizio la riproduzione
                  break;
          case 3: stopPlaying();            //fermo la riproduzione
                  break;
          case 4: startPlaying();           //inizio la riproduzione
                  break;    
        }
      }
    
      switch (modeLS){
          case 0: break;
          case 1: continueRecording();
                  break;
          case 2: continuePlaying();
                  break;
          case 3: break;
          case 4: continuePlaying();
                  break;
        }
    
    
    ingresso=digitalRead(ingressoBottone);
    if(ingresso!=ingressoPr){
      if(ingresso==0) Serial.println("chitarra");
      if(ingresso==1) Serial.println("microfono");
      ingressoPr=ingresso;
      }
    
      Serial.println(modeLS,DEC);
    
     delay(500);
    }
    
    
    
    void startRecording() {
      Serial.println("StartRecording Track ");
      Serial.print(n, DEC);
      
      nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
    
      while(SD.exists(filename)) {
        nNameTrack=nNameTrack+1;
        nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
      }
      
      if(nNameTrack==9){
        Serial.println("Memoria piena, provveddere allo svuatamento");
        return;
        }
      
      frec = SD.open(filename, FILE_WRITE);
      if (frec) {
        queue1.begin();
      }
    }
    
    void continueRecording() {
      if (queue1.available() >= 2) {
        byte buffer[512];
        // Fetch 2 blocks from the audio library and copy
        // into a 512 byte buffer.  The Arduino SD library
        // is most efficient when full 512 byte sector size
        // writes are used.
        memcpy(buffer, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        memcpy(buffer+256, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        // write all 512 bytes to the SD card
        elapsedMicros usec = 0;
        frec.write(buffer, 512);
      }
    }
    
    void stopRecording() {
      Serial.println("stopRecording track ");
      Serial.print(n, DEC);
      
      queue1.end();
      if (modeLS == 2) {
        while (queue1.available() > 0) {
          frec.write((byte*)queue1.readBuffer(), 256);
          queue1.freeBuffer();
        }
        frec.close();
      }
    }
    
    
    void startPlaying() {
      Serial.println("startPlaying");
      nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
        playRaw1.play(filename);
    }
    
    void continuePlaying() {
      if (!playRaw1.isPlaying())  playRaw1.stop();
    }
    
    void stopPlaying() {
      Serial.println("stopPlaying Track");
      Serial.print(n, DEC);
      playRaw1.stop();
    
    }

    the problem is that it records but the raw file has same issues: when I convert it using Audacity (import raw data 16bit, 44kHz) the resulting audio is significantly smaller than the time I register, moreover I can not listen anything. Please help me

    thanks

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    can someone please say something?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,942
    None of your questions make sense, at least to me, so not sure how to answer. But here is at least a (not useful) reply.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,942
    Ok, here's some attempts at answers, though I really have no idea if I even understood your project.

    Quote Originally Posted by Carlo alfisi View Post
    1) as you can see I have many audio reproduced at the same time, can it be a problem? In case it is, how can I fix?
    The audio library provides functions for *you* to monitor resource usage, so you can evaluate whether you have used too much CPU time.

    https://www.pjrc.com/teensy/td_libs_...ssorUsage.html

    Likewise, Arduino prints a message every time you click Verify or Upload, which shows how much of the memory your program uses.

    These features are meant to allow *you* (and everyone using the software) to easily answer this question for yourself.


    2) My intent is to use virtual pin to comunicate with the board so I bought an HC-05 to comunicate with an android devise. I would like to use Virtuino to develope the control panel. I use VirtuinoBluetooth.h but I don't understand how define the pin in the IDE code
    VirtuinoBluetooth.h is not any of the libraries provided by Teensyduino. I know nothing of this library. You did not even give a link to the library code. Am I supposed to go searching the Internet for this file?


    3) I have a teensy 3.6 and I don't have the audio board ( I use WM8731, is it correct? ).
    The audio shield has SGTL5000. If you wish to use the same chip, then WM8731 is different.

    But WM8731 is also supported by the library. So whether it is "correct" really depends on your point of view. (can you understand how a lack of context means these answer are less helpful - and may also be the reason nobody has taken the time to write answers that ultimately will not be helpful)

    I can use any Analog pin to sample the input sound, isn't?
    I do not understand why you ask about using the anglog pins in the same question as using a chip (rather than the analog pins on Teensy). But yes, if you use the adc input, there is a way to specify which pin. That is documented in the design tool.

    https://www.pjrc.com/teensy/gui/?info=AudioInputAnalog

    After using this link, look at the right-side documentation panel and scroll down to "For example, to use pin A3:"


    Moreover if I want to connect a guitar jack to the input, do I need to amplify the signal?
    It really depends on the specific details of your signal, but probably yes. And before you reply with another question asking for me or anyone else to give you the specific details of the amplifier to use, consider that *you* must at least give some detail about your signal. If you ask a very generic question like this, lacking detail, nobody can really help. That is why nobody replies. When you ask people to give you specific guidance, you need to give enough details and context.


    or the circuit shown in the description of the ADC is sufficient?
    That circuit is meant for a signal which is approx 1 to 1.2 volts peak-to-peak, and driven at a fairly low impedance (common with outputs of most consumer electronics gear), like 1K ohm or less.


    the problem is that it records but the raw file has same issues: when I convert it using Audacity (import raw data 16bit, 44kHz) the resulting audio is significantly smaller than the time I register, moreover I can not listen anything. Please help me
    How do you imagine anyone can help? We can't see your recorded file. We can't see what type of signal you connected. Nobody answers because there really is nothing useful to say, other than to guess you must be doing something wrong somewhere. Maybe try a signal which is in the expected "line level" range?

  6. #6
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,069
    Your first, and major, problem is this delay at the end of the loop() function:
    Code:
     delay(500);
    Your code spends practically all of its time here while it is recording, but during a delay nothing happens. About 86 audio buffers will be created and thrown away because you didn't read them.
    Once you've deleted that delay, the println just before it will make it difficult to read the output because it will be printing 0 or 1 as fast as it can. Delete this as well:
    Code:
      Serial.println(modeLS,DEC);
    I haven't got my T3.6 set up for audio input on the DAC so I can't test this with real audio but at least it does now create an audio file that is over 800kB long (which corresponds to about 10 seconds of recording time).

    I had to modify the code which handles "bottone". You may have it set up with a pulldown resistor but I changed it to use the internal pullup resistor. To do this I changed the pinMode to this:
    Code:
      pinMode(2,INPUT_PULLUP);
    and I changed the way that the button is read in the loop() function:
    Code:
      if (digitalRead(bottone)==0) {   //se  premuto il tasto n-esimo
        modeChange=true;
        Serial.println("cambio mode");
        // Wait for the button to be released
        while(digitalRead(bottone)==0);
      }
    Pete

  7. #7
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    Thank you all very much. Some of your answers clarify my doubts. I'm really sorry for my unclear questions (my english is not quinte good). Tomorrow I'll give you more details about my project (I'll have a friend who will help me for the translation).
    Thanks again

    C.A.

  8. #8
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    The code has changed a little bit, there it is the new one:

    Code:
    #include <VirtuinoBluetooth.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <String.h>
    #include <Bounce.h>
    #include <SoftwareSerial.h>                              //  Disable this line if you want to use hardware serial 
    
    
    SoftwareSerial bluetoothSerial =  SoftwareSerial(9,10);   // arduino RX pin=2  arduino TX pin=3    connect the arduino RX pin to bluetooth module TX pin   -  connect the arduino TX pin to bluetooth module RX pin.  Disable this line if you want to use hardware serial 
    VirtuinoBluetooth virtuino(bluetoothSerial);       // Set SoftwareSerial baud rate.  -  Disable this line if you want to use hardware serial 
    
    
    // GUItool: begin automatically generated code
    AudioPlaySdRaw           playRaw1;       //xy=100.75,962.25
    AudioPlaySdRaw           playRaw2;       //xy=101.75,993.25
    AudioPlaySdRaw           playRaw3;       //xy=102.75,1024.25
    AudioPlaySdRaw           playRaw4;       //xy=102.75,1055.25
    AudioInputAnalog         adc1;           //xy=117.49998474121094,902.5
    AudioEffectFreeverb      filterReverb;   //xy=339.5,851.75
    AudioMixer4              mixerTrack;     //xy=455.5,993.2500610351562
    AudioEffectBitcrusher    filterCrush;    //xy=461,893
    AudioSynthWaveformSineModulated filterSine;     //xy=562.75,846
    AudioMixer4              mixerOut;       //xy=701.2500610351562,983.75
    AudioMixer4              mixerRecord;    //xy=769.25,756.7500305175781
    AudioRecordQueue         queue1;         //xy=778.75,861.25
    AudioOutputAnalog        dac1;           //xy=870,980
    AudioConnection          patchCord1(playRaw1, 0, mixerTrack, 0);
    AudioConnection          patchCord2(playRaw2, 0, mixerTrack, 1);
    AudioConnection          patchCord3(playRaw3, 0, mixerTrack, 2);
    AudioConnection          patchCord4(playRaw4, 0, mixerTrack, 3);
    AudioConnection          patchCord5(adc1, filterReverb);
    AudioConnection          patchCord6(adc1, 0, mixerRecord, 1);
    AudioConnection          patchCord7(adc1, 0, mixerOut, 1);
    AudioConnection          patchCord8(filterReverb, filterCrush);
    AudioConnection          patchCord9(mixerTrack, 0, mixerOut, 2);
    AudioConnection          patchCord10(filterCrush, filterSine);
    AudioConnection          patchCord11(filterSine, 0, mixerRecord, 0);
    AudioConnection          patchCord12(filterSine, 0, mixerOut, 0);
    AudioConnection          patchCord13(mixerOut, dac1);
    AudioConnection          patchCord14(mixerRecord, queue1);
    AudioControlWM8731       wm8731_1;       //xy=844.25,1093.4999389648437
    // GUItool: end automatically generated code
    
    //Virtual Pin
    // V0-V3     Volume Track                                               MENU
    // V4-V7     button Track: they can have a value 0f {0 1 2 3 4 5}       LOOPSTATION
    // V8-V12    Guitar Effect                                              MENU
    // V22       Input switch                                               MENU
    
    
    
    const int Guitar = A2;         
    const int Mic = A3; 
    
    
    // THE VARIABLE
    // float valuePoten[4]={};             //valori 0-1 dei potenziometri
    bool modeChange=false;              //utilizzata per il cambio di mode nella LS o nel MENU
    
    //  for LoopStation
    const int numTracks=4;
    String nameTrack[]={"Tr1.RAW" ,"Tr2.RAW" ,"Tr3.RAW" ,"Tr4.RAW" , "Tr5.RAW" ,"Tr6.RAW" ,"Tr7.RAW" ,"Tr8.RAW" , "Tr9.RAW" ,"Tr10.RAW" ,"Tr11.RAW" ,"Tr12.RAW"};
    int nNameTrack=0; // serve per evitare la sovrascrizione d tracce
    char filename[9];
    int n; // scorre i 4 canali delle track 
    int modeLS [4]= {};  
    // 0=empty, 1=recording, 2=stopRec&loop 3=stop 4=loop 5=3
    
    //for MENU
    int ingresso=0; // 0=guitar, 1=effected guitar, 2=microfono         CONTROLLARE CON LA MISURA DEI VALORI
    int ingressoPr; // Precedente per evitare ripetizioni superflue
    
    //for Info
    //int t0;   //salva il momento in cui  iniziato la reg
    //int timeTrack[4]={}; // salva le durat delle tracce registrate
    //int tL[4]={};  // serve per la isualizzazione del tempo-metro 
    //int temp;
    
    #define SDCARD_CS_PIN    BUILTIN_SDCARD
    File frec;
    
    void setup() {
      virtuino.DEBUG=true;
      Serial.begin(9600);
      Serial2.begin(9600);
      //bluetoothSerial.begin(9600); 
      
      
      // Audio connections require memory, and the record queue
      // uses this memory to buffer incoming audio.
      AudioMemory(60*numTracks);
    
      wm8731_1.enable();
      wm8731_1.inputSelect(Guitar);
      wm8731_1.volume(0.5);
    
      // Initialize the SD card
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
      
     // inizializzo i mixer e i filter
     mixerRecord.gain(0,1);
     mixerRecord.gain(1,0);
     mixerTrack.gain(0,0.25);
     mixerTrack.gain(1,0.25);
     mixerTrack.gain(2,0.25);
     mixerTrack.gain(3,0.25); 
     mixerOut.gain(0,0.5);
     mixerOut.gain(1,0);
     mixerOut.gain(2,0.5);
     filterReverb.roomsize(0);
     filterReverb.damping(1);
     filterSine.amplitude(1);
     filterSine.frequency(0);
     filterCrush.bits(16);
     
     
    }
    
    void loop() {  
      virtuino.run();
    //  while(Serial2.available()){
      LoopStation();                             
      MENU();       
    //INFO();                      
    }
    //}
    
    
    void LoopStation() {                
      modeChange=false;                   
      
      if (virtuino.vMemoryRead(4)!=modeLS[0]){    //if the value of the button V4 is different than the current modeLS
        modeChange=true;               
        n=0;                                      //I will change the n-th track mode
        if(virtuino.vMemoryRead(4)==5){  
          virtuino.vMemoryWrite(4,3);             // this make the value of ButtonTrack cyclic
        }
        modeLS[0]=virtuino.vMemoryRead(4);
        }
        
      if (virtuino.vMemoryRead(5)!=modeLS[1]){ 
        n=1;
        modeChange=true;
        if(virtuino.vMemoryRead(5)==5){
          virtuino.vMemoryWrite(5,3);
        }
        modeLS[1]=virtuino.vMemoryRead(5);
        }
        
          
      if (virtuino.vMemoryRead(6)!=modeLS[2]){ 
        n=2;
        modeChange=true;
        if(virtuino.vMemoryRead(6)==5){
          virtuino.vMemoryWrite(6,3);
        }
        modeLS[2]=virtuino.vMemoryRead(6);
        }
        
         
      if (virtuino.vMemoryRead(7)!=modeLS[3]){ 
        n=3;
        modeChange=true;
        if(virtuino.vMemoryRead(7)==5){
          virtuino.vMemoryWrite(7,3);
        }
        modeLS[3]=virtuino.vMemoryRead(7);
        }
    
        
      if(modeChange){                        //only if the mode change
         switch (modeLS[n]){                
          case 1: startRecording();         
                  break;
          case 2: stopRecording();           
                  startPlaying();           
                  break;
          case 3: stopPlaying();            
                  break;
          case 4: startPlaying();           
                  break;    
        }
      }   
      
      
      for(n = 0; n < 4; n = n + 1 ){        //for all the lines 
        switch (modeLS[n]){
          case 0: break;
          case 1: continueRecording();
                  break;
          case 2: continuePlaying();
                  break;
          case 3: break;
          case 4: continuePlaying();
                  break;
        }
      }
    
      // when using a microphone, continuously adjust gain
      // adjustMicLevel have to be implemented
      //if (Guitar == AUDIO_INPUT_MIC) adjustMicLevel();
    }
    
    
    void MENU() {
    
    
    // ingresso=virtuino.vMemoryRead(22);
     if(ingressoPr!=virtuino.vMemoryRead(22)) { // only if the input is different to the previous 
      if(virtuino.vMemoryRead(22)==0){          // input is guitar and the output is the base guitar  
        wm8731_1.inputSelect(Guitar);
        mixerRecord.gain(0,0);
        mixerRecord.gain(1,1);  
        mixerOut.gain(0,0);
        mixerOut.gain(1,0.5);
        }
      if(virtuino.vMemoryRead(22)==1){          // input is guitar and the output is the effect guitar
        wm8731_1.inputSelect(Guitar);
        mixerRecord.gain(0,1);
        mixerRecord.gain(1,0);
        mixerOut.gain(0,0.5);
        mixerOut.gain(1,1);
        }
      if(virtuino.vMemoryRead(22)==2){          // input is the microphone 
        wm8731_1.inputSelect(Mic);
        mixerRecord.gain(0,0);
        mixerRecord.gain(1,1);
        mixerOut.gain(0,0);
        mixerOut.gain(1,0.5);
        }
        
        ingressoPr=virtuino.vMemoryRead(22);
     } 
    
      
      //regolo il volume delle tracce
      mixerTrack.gain(0,virtuino.vMemoryRead(0)/1023);                
      mixerTrack.gain(1,virtuino.vMemoryRead(1)/1023);                
      mixerTrack.gain(2,virtuino.vMemoryRead(2)/1023);
      mixerTrack.gain(3,virtuino.vMemoryRead(3)/1023);
    
      
    if(ingresso==2){    //controllo dell'effetto alla chitarra
      filterReverb.roomsize(virtuino.vMemoryRead(8)/1023);
      filterReverb.damping(virtuino.vMemoryRead(9)/1023);
      filterSine.amplitude(virtuino.vMemoryRead(10)/1023);
      filterSine.frequency(virtuino.vMemoryRead(11)*11000/1023);
      filterCrush.bits(virtuino.vMemoryRead(12)*16/1023);
    }   
    
    }
    
    
    void startRecording() {
      Serial.println("StartRecording Track ");
      Serial.print(n, DEC);
      
      nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
    
      while(SD.exists(filename)) {
        //SD.remove(filename);
        nNameTrack=nNameTrack+1;
        nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
      }
      
      if(nNameTrack==9){
        Serial.println("Memoria piena, provveddere allo svuatamento");
        return;
        }
      
      frec = SD.open(filename, FILE_WRITE);
      if (frec) {
        queue1.begin();
      }
    }
    
    void continueRecording() { 
      if(modeChange)  Serial.println("Recording");
      if (queue1.available() >= 2) {
        byte buffer[512];
        // Fetch 2 blocks from the audio library and copy
        // into a 512 byte buffer.  The Arduino SD library
        // is most efficient when full 512 byte sector size
        // writes are used.
        memcpy(buffer, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        memcpy(buffer+256, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        // write all 512 bytes to the SD card
        elapsedMicros usec = 0;
        frec.write(buffer, 512);
      }
    }
    
    void stopRecording() {
      Serial.println("stopRecording track ");
      Serial.print(n, DEC);
      
      queue1.end();
      if (modeLS[n] == 2) {
        while (queue1.available() > 0) {
          frec.write((byte*)queue1.readBuffer(), 256);
          queue1.freeBuffer();
        }
        frec.close();
      }
    }
    
    
    void startPlaying() {
      Serial.println("startPlaying");
      if(n==1){ nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
        playRaw1.play(filename);
      }
      if(n==2){ nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
        playRaw2.play(filename);
      }
      if(n==3){ nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
        playRaw3.play(filename);
      }
      if(n==4){ nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
        playRaw4.play(filename);
      }
    }
    
    void continuePlaying() {
      if(modeChange) Serial.println("playing");
      if (!playRaw1.isPlaying())  playRaw1.stop();
      if (!playRaw2.isPlaying())  playRaw2.stop();
      if (!playRaw3.isPlaying())  playRaw3.stop();
      if (!playRaw4.isPlaying())  playRaw4.stop();
        startPlaying();
      }
    
    
    void stopPlaying() {
      Serial.println("stopPlaying Track");
      Serial.print(n, DEC);
      if (n == 1) playRaw1.stop();
      if (n == 2) playRaw2.stop();
      if (n == 3) playRaw3.stop();
      if (n == 4) playRaw4.stop();
    }

    These’re my doubts , I hope I’m making myself clear enough this time.

    1) My task is to sample the signal that comes out from the jack linked to the guitar and then the output of the teensy should go to an Amplifier. The output of the guitar’s pickup is about 10mV; I would use an OpAmp (ls358p chip) to increase the signal to a voltage high enough to make the most the ADC of teensy. What do you think about this? Do you suggest me any precautions?

    2) I don’t want to use the Audio Shield, I shall connect two 3.5mm jack (one for the input, one for the output). In relation to the input one, it will be connected to the Teensy through the circuit recommended by the description of the ACD in the Design Tool. Do you suggest me any precautions regarding the output connection?

    3) I’m not going to use any external chip to manage the In/Out signal, I supposed to not use a control block (ex. Wm8731m), is it correct? How much this can damage the project?

    4) All the buttons and potentiometers will not be physical, in fact they will ecplot the Virtual Pins through the Virtuino app (www.virtuino.com). Teensy will be connected to android phone by the hc05 bluetooth module. Could this connection get worse the sample? If yes, is there something I can do to reduce it (maybe I could decrease the rate of this connection)?

    5) I would like to use a simple battery module (a connector for two AA battery, 1.5 Volt each -> 3V) to power the teensy up. Does the fact that I’m not going to reach 3.3V represent a problem?


    Thank you very much! if I was unclear or I lacked some info, please let me know and I will provide as soon as I can

  9. #9
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,069
    You are trying to get too much working all at once. The more esoteric hardware that you add, such as VirtuinoBluetooth, the less chance that someone will have that same hardware and be able to test your code.
    Go back your first version with simple buttons and get it to record and play back one track. Until you can do that there's no point adding any new features.

    Pete

  10. #10
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    thank el_supremo for the advice. I simplify the code and now there's only one track and real buttons and potentiometers:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <String.h>
    #include <Bounce.h>
    
    
    // GUItool: begin automatically generated code
    AudioPlaySdRaw           playRaw1;       //xy=67,264
    AudioInputAnalog         adc1;           //xy=84,204
    AudioEffectFreeverb      filterReverb;   //xy=306,153
    AudioMixer4              mixerTrack;     //xy=422,295
    AudioEffectBitcrusher    filterCrush;    //xy=428,195
    AudioSynthWaveformSineModulated filterSine;     //xy=529,148
    AudioMixer4              mixerOut;       //xy=668,285
    AudioMixer4              mixerRecord;    //xy=736,58
    AudioRecordQueue         queue1;         //xy=745,163
    AudioOutputAnalog        dac1;           //xy=837,282
    AudioConnection          patchCord1(playRaw1, 0, mixerTrack, 0);
    AudioConnection          patchCord2(adc1, filterReverb);
    AudioConnection          patchCord3(adc1, 0, mixerRecord, 1);
    AudioConnection          patchCord4(adc1, 0, mixerOut, 1);
    AudioConnection          patchCord5(filterReverb, filterCrush);
    AudioConnection          patchCord6(mixerTrack, 0, mixerOut, 2);
    AudioConnection          patchCord7(filterCrush, filterSine);
    AudioConnection          patchCord8(filterSine, 0, mixerRecord, 0);
    AudioConnection          patchCord9(filterSine, 0, mixerOut, 0);
    AudioConnection          patchCord10(mixerOut, dac1);
    AudioConnection          patchCord11(mixerRecord, queue1);
    AudioControlWM8731       wm8731_1;       //xy=811,395
    // GUItool: end automatically generated code
    
    
    
    const int Guitar = A0;         
    
    
    // THE VARIABLE
    // float valuePoten[4]={};             //valori 0-1 dei potenziometri
    bool modeChange=false;              //utilizzata per il cambio di mode nella LS o nel MENU
    
    //  for LoopStation
    int n=0;
    String nameTrack[]={"Tr1.RAW" ,"Tr2.RAW" ,"Tr3.RAW" ,"Tr4.RAW" , "Tr5.RAW" ,"Tr6.RAW" ,"Tr7.RAW" ,"Tr8.RAW" , "Tr9.RAW" ,"Tr10.RAW" ,"Tr11.RAW" ,"Tr12.RAW"};
    int nNameTrack=0; // serve per evitare la sovrascrizione d tracce
    char filename[9];
    int modeLS = 0;  
    int bottone=2;
    int inputSwitch=3;
    // 0=empty, 1=recording, 2=stopRec&loop 3=stop 4=loop 5=3
    
    //for MENU
    int input=0; // 0=guitar, 1=effected guitar, 2=microfono         CONTROLLARE CON LA MISURA DEI VALORI
    int volumePoten=A1;
    int effectPoten=A2;
    
    #define SDCARD_CS_PIN    BUILTIN_SDCARD
    File frec;
    
    
    void setup(){
    Serial.begin(9600);
    AudioMemory(60);
    pinMode(bottone,INPUT_PULLUP);
    pinMode(inputSwitch,INPUT);
    
      wm8731_1.enable();
      wm8731_1.inputSelect(Guitar);
      wm8731_1.volume(0.5);
    
      // Initialize the SD card
      if (!(SD.begin(SDCARD_CS_PIN))) {
        // stop here if no SD card, but print a message
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
      
     // inizializzo i mixer e i filter
     mixerRecord.gain(0,1);
     mixerRecord.gain(1,0);
     mixerTrack.gain(0,0.25);
     mixerTrack.gain(1,0.25);
     mixerTrack.gain(2,0.25);
     mixerTrack.gain(3,0.25); 
     mixerOut.gain(0,0.5);
     mixerOut.gain(1,0);
     mixerOut.gain(2,0.5);
     filterReverb.roomsize(0);
     filterReverb.damping(1);
     filterSine.amplitude(1);
     filterSine.frequency(0);
     filterCrush.bits(16);
     
      }
    
    void loop(){
      LoopStation();                             
      MENU();  
     
     }
    
    
    void LoopStation() {                
      modeChange=false;                   
      
      if (digitalRead(bottone)==1){    //if the value of the button V4 is different than the current modeLS
        modeChange=true;    
        modeLS=modeLS+1;                                              
        if(modeLS==5){  
          modeLS=3;             // this make the value of ButtonTrack cyclic
        }
        }
      
        
      if(modeChange){                        //only if the mode change
         switch (modeLS){                
          case 1: startRecording();         
                  break;
          case 2: stopRecording();           
                  startPlaying();           
                  break;
          case 3: stopPlaying();            
                  break;
          case 4: startPlaying();           
                  break;    
        }
      }   
      
      
        switch (modeLS){
          case 0: break;
          case 1: continueRecording();
                  break;
          case 2: continuePlaying();
                  break;
          case 3: break;
          case 4: continuePlaying();
                  break;
        }
    
      // when using a microphone, continuously adjust gain
      // adjustMicLevel have to be implemented
      //if (Guitar == AUDIO_INPUT_MIC) adjustMicLevel();
    }
    
    void MENU() {
    
     if(input!=digitalRead(inputSwitch)) { // only if the input is different to the previous 
      input=digitalRead(inputSwitch);
      if(input==0){          // input is guitar and the output is the base guitar  
        mixerRecord.gain(0,0);
        mixerRecord.gain(1,1);  
        mixerOut.gain(0,0);
        mixerOut.gain(1,0.5);
        }
      if(input==1){          // input is guitar and the output is the effect guitar
        mixerRecord.gain(0,1);
        mixerRecord.gain(1,0);
        mixerOut.gain(0,0.5);
        mixerOut.gain(1,1);
        }
        
        
     } 
    
      
      //regolo il volume delle tracce
      mixerTrack.gain(0,analogRead(volumePoten)/1023);                
    
    
      
    if(input==1){    //controllo dell'effetto alla chitarra
      filterReverb.roomsize(analogRead(effectPoten)/1023);
    //  filterReverb.damping(virtuino.vMemoryRead(9)/1023);
    //  filterSine.amplitude(virtuino.vMemoryRead(10)/1023);
    //  filterSine.frequency(virtuino.vMemoryRead(11)*11000/1023);
    //  filterCrush.bits(virtuino.vMemoryRead(12)*16/1023);
    }   
    
    }
     
    
    void startRecording() {
      Serial.println("StartRecording ");
     
      
      nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
    
      while(SD.exists(filename)) {
        //SD.remove(filename);
        nNameTrack=nNameTrack+1;
        nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
      }
      
      if(nNameTrack==9){
        Serial.println("Memoria piena, provveddere allo svuatamento");
        return;
        }
      
      frec = SD.open(filename, FILE_WRITE);
      if (frec) {
        queue1.begin();
      }
    }
    
    void continueRecording() { 
      if(modeChange)  Serial.println("Recording");
      if (queue1.available() >= 2) {
        byte buffer[512];
        // Fetch 2 blocks from the audio library and copy
        // into a 512 byte buffer.  The Arduino SD library
        // is most efficient when full 512 byte sector size
        // writes are used.
        memcpy(buffer, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        memcpy(buffer+256, queue1.readBuffer(), 256);
        queue1.freeBuffer();
        // write all 512 bytes to the SD card
        elapsedMicros usec = 0;
        frec.write(buffer, 512);
      }
    }
    
    void stopRecording() {
    //  Serial.println("stopRecording track ");
    //  Serial.print(n, DEC);
      
      queue1.end();
      if (modeLS == 2) {
        while (queue1.available() > 0) {
          frec.write((byte*)queue1.readBuffer(), 256);
          queue1.freeBuffer();
        }
        frec.close();
      }
    }
    
    
    void startPlaying() {
    //  Serial.println("startPlaying");
       nameTrack[n+nNameTrack].toCharArray(filename, sizeof(filename));
       playRaw1.play(filename);
    }
    
    void continuePlaying() {
      if(modeChange) Serial.println("playing");
      if (!playRaw1.isPlaying()){ 
      playRaw1.stop();
      startPlaying();         //IT'S DIFFERENT FROM THE 4-TRACK 
      }
    }
    
    void stopPlaying() {
    //  Serial.println("stopPlaying Track");
    //  Serial.print(n, DEC);
      playRaw1.stop();
      
    }
    thanks a lot for your help

  11. #11
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,069
    When setting up mixerRecord:
    Code:
     // inizializzo i mixer e i filter
     mixerRecord.gain(0,1);
     mixerRecord.gain(1,0);
    The gain for the original input from the adc is set to zero and the filtered signal is passed through with a gain of 1. I'd suggest that, for now, you do the opposite so that you can confirm that the adc signal is getting through. Once you can record this signal, then you can put it through the filters.
    For now, change the code above to:
    Code:
     // inizializzo i mixer e i filter
     mixerRecord.gain(0,0);
     mixerRecord.gain(1,1);
    Pete

  12. #12
    Junior Member
    Join Date
    Dec 2018
    Posts
    18
    Hi, as el_supremo sugested, I changed the micerRecord.gain(), but nothing still has been recorded ( I tried many configurations for input and output ) . Probably it is due to the 3th problem, in the previous post I was uncleare .. sorry
    I’m not going to use any external chip to manage the In/Out signal, thus I supposed to not use a control block (ex. Wm8731m), is it correct? How much this can damage the project? What I meant is: how can manage In/Out without an external chip (if it's possible)? I saw in the two examples, precisely Mono Peak Meter and Stereo Peak Meter (Audio ->Analisys), that the concepts are the same but in the Mono one no SGTL5000 is needed: why? My really question is how to define the pins connected with the ADC and DAC?

    please answer me.

    thanks very much for your help

Posting Permissions

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