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

Thread: Instructions or tutorials for using wav2sketch?

  1. #1

    Instructions or tutorials for using wav2sketch?

    Are there more detailed step by step instructions somewhere for using wav2sketch to convert .wav files to data arrays? "The wav2sketch program can convert WAV files to the data arrays needed by AudioPlayMemory" isn't very illuminating, at least for me who's more of a GUI/WYSIWYG guy. My searches haven't revealed detailed instructions.

    I see links to some C source code and a Window executable. I don't know how you make C source code run in Terminal on a Mac. Initial searches indicate installing developer tools. I don't poke around in Terminal that much; it frightens me a bit.

    I attempted to launch the Windows .exe in Windows 8 in VMWare Fusion, but nothing visible happened when I tried to run the .exe. I'm not a Windows guy, either.

    After a lot of troubleshooting I was able to get a modified version of the SamplePlayer example sketch to play through the Teensy 3.2 DAC and into my little Sparkfun amp and small speaker. My next step is to try to replace those sounds with the two sound effects I need for my project, hence this request for help.

    Thank you.

    Shawn

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,928
    The wav2sketch program looks for *.wav files in your current directory and creates .h and .cpp files to put in your sketch folder.

    So if you download wav2sketch.exe into your windows Downloads folder, then put your .wav files in the Downloads folder and open a command window in the Downloads folder (or cd to it). Then run wav2sketch from the command window

    for linux, compile wav2sketch.c and run it in directory with your .wav files

    https://www.pjrc.com/teensy/td_libs_...layMemory.html
    Last edited by manitou; 02-27-2017 at 01:57 PM.

  3. #3
    Senior Member
    Join Date
    May 2015
    Posts
    338
    It's amazing to me how often people ask a question or talk about I feature, library or tool that I didn't even know existed that is perfect for something I'm about to do. I hadn't yet got into playing waves for canned sounds but just when I start thinking along those lines a post starts with all I could have wanted to know. The same with actual working code to have USB audio without an audio board, the Snooze library and more. A big thanks to Paul and the fantastic community here. Far better that some other arm communities/chip sets I tried in the past.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    You're going to have to run it in Terminal. Here's a copy compiled for macintosh.
    Attached Files Attached Files

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    To use this, first create an empty folder. I made a folder called "wav2sketch" from my home dir. Put the zip file in that folder and extract it. Also put some WAV files in the folder. This program converts whatever WAV files happen to be in the same folder.

    Open Terminal.

    To get set up, you're going to type 3 commands. First use "cd wav2sketch" (or whatever folder name you used) to change the current working directory to the folder you created. Then type "ls -l" to see a list of files. The only reason for "ls -l" it to make sure you've successfully changed to the folder where you put this stuff. If your Terminal opens with you using a different folder, you're going to have to fiddle with "cd" commands until you manage to get to the folder you created.

    Click image for larger version. 

Name:	sc1.png 
Views:	229 
Size:	363.1 KB 
ID:	9848
    (click for full size)

    Once you get to the folder and you can see the files with "ls -l", there's one more prep command to type: "chmod 755 wav2sketch". This sets the execute permission, so you can actually run the file. Like most unix commands "no news is good news", it prints nothing if it works. See the screenshot above.

    Then to run it, type "./wav2sketch". If you get "Permission Denied" the chmod command didn't work. If it works, it'll print a few lines telling you what it did (not the normal "no news" unix approach). You should see something like this:

    Click image for larger version. 

Name:	sc2.png 
Views:	175 
Size:	398.8 KB 
ID:	9849
    (click for full size)

    Probably best to do with with a familiar Finder window open next to Terminal, as I did for these screenshots. When it works, you'll see the Arduino compatible .cpp and .h files appear. Or you can type "ls -l" in Terminal, but at this point you can just quit Terminal and use the files.

  6. #6
    Thanks, Paul, for taking the time to compile the code and create these step-by-step instructions for someone like me who's not savvy working in a command line environment. I appreciate the help.

    I'll give this a go.

    Best.

    Shawn

  7. #7
    Junior Member
    Join Date
    Feb 2018
    Posts
    1
    Oopps I cannot open this mac version, there is no link?

  8. #8
    Junior Member
    Join Date
    Mar 2019
    Posts
    17
    Paul, This is great - thank you so much !!

    A problem I encountered -

    - What is the limit of mem files on a 3.2? I have brought about 8 wav files (each about 11.4 MB), that after conversion to ".cpp", each .cpp file is a bout 8 MB !!! that's not right, right?.

    - I believe this is the reason I can't upload the sketch :

    Code:
    Arduino: 1.8.8 (Mac OS X), TD: 1.45, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"
    
    In file included from /Users/ayalrosenberg/Documents/Arduino/Thesis/Looper_Rec_sampleTest_piano/Looper_Rec_sampleTest_piano.ino:19:0:
    /Users/ayalrosenberg/Documents/Arduino/libraries/FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.002.006
     #    pragma message "FastLED version 3.002.006"
                         ^
    Looper_Rec_sampleTest_piano: In function 'void loop()':
    Looper_Rec_sampleTest_piano:416: warning: comparison between signed and unsigned integer expressions 
     if(blinkTime > millisBPM/4 ){
                  ^
    /Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: /var/folders/3r/yp404b7s4hs9h93s9dk4r7400000gn/T/arduino_build_822099/Looper_Rec_sampleTest_piano.ino.elf section `.text' will not fit in region `FLASH'
    /Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: region `FLASH' overflowed by 22557984 bytes
    collect2: error: ld returned 1 exit status
    Multiple libraries were found for "FastLED.h"
     Used: /Users/ayalrosenberg/Documents/Arduino/libraries/FastLED
     Not used: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/FastLED
    Multiple libraries were found for "SD.h"
     Used: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
     Not used: /Applications/Arduino.app/Contents/Java/libraries/SD
    Error compiling for board Teensy 3.2 / 3.1.
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    I exported the wav files from MuseScore - just a simple piano.
    Is there a way to overcome this besides finding smaller wav files?

    thank you so much

    here's the full code just in case :

    Code:
    // WAV files converted to code by wav2sketch
    #include "AudioSampleSnare.h"        // http://www.freesound.org/people/KEVOY/sounds/82583/
    #include "AudioSampleTomtom.h"       // http://www.freesound.org/people/zgump/sounds/86334/
    #include "AudioSampleHihat.h"        // http://www.freesound.org/people/mhc/sounds/102790/
    #include "AudioSampleKick.h"         // http://www.freesound.org/people/DWSD/sounds/171104/
    #include "AudioSampleGong.h"         // http://www.freesound.org/people/juskiddink/sounds/86773/
    #include "AudioSampleC4.h" // http://www.freesound.org/people/kiddpark/sounds/201159/
    #include "AudioSampleD4.h"
    #include "AudioSampleE4.h"
    #include "AudioSampleF4.h"
    #include "AudioSampleG4.h"
    #include "AudioSampleA4.h"
    #include "AudioSampleB4.h"
    #include "AudioSampleC5.h"
    
    
    /////LED//////
    #include <FastLED.h>
    #define LED_PIN     12
    #define NUM_LEDS    4
    CRGB leds[NUM_LEDS];
    ///////////////////
    
    #include <Bounce.h>
    #include "pitches.h"
    const unsigned int* notes[] = {
      AudioSampleC4, AudioSampleD4, AudioSampleE4, AudioSampleF4, AudioSampleG4, AudioSampleA4, AudioSampleB4, AudioSampleC5
    };
    const unsigned int* melody1[64] = {};
    const unsigned int* melody2[64] = {};
    const unsigned int* melody3[64] = {};
    const unsigned int* melody4[64] = {};
    const unsigned int* melody1Play[64] = {};
    const unsigned int* melody2Play[64] = {};
    const unsigned int* melody3Play[64] = {};
    const unsigned int* melody4Play[64] = {};
    bool arrToggle12 = false;
    bool arrToggle34 = false;
    bool channelToggle = false;
    int play1MemMode = 0;
    int play2MemMode = 0;
    ///////CAP TOUCH///////////////////
    #include <Wire.h>
    #include "Adafruit_MPR121.h"
    #ifndef _BV
    #define _BV(bit) (1 << (bit)) 
    #endif
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioPlayMemory          playMem7;       //xy=81,253
    AudioPlayMemory          playMem3;       //xy=82,88
    AudioPlayMemory          playMem4;       //xy=82,121
    AudioPlayMemory          playMem8;       //xy=82,293
    AudioPlayMemory          playMem5;       //xy=83,166
    AudioPlayMemory          playMem6;       //xy=83,213
    AudioPlayMemory          playMem2;       //xy=84,53
    AudioPlayMemory          playMem1;       //xy=85,20
    AudioPlayMemory          playMem9; //xy=85,349
    AudioPlayMemory          playMem12; //xy=85,464
    AudioPlayMemory          playMem11; //xy=86,424
    AudioPlayMemory          playMem10; //xy=89,381
    AudioPlayMemory          playMem16; //xy=106,644
    AudioPlayMemory          playMem13; //xy=108,535
    AudioPlayMemory          playMem14; //xy=109,568
    AudioPlayMemory          playMem15; //xy=109,611
    AudioMixer4              mixer5; //xy=347,589
    AudioMixer4              mixer4; //xy=348,474
    AudioMixer4              mixer2;         //xy=355,322
    AudioMixer4              mixer1;         //xy=356,207
    AudioMixer4              mixer3;         //xy=568,260
    AudioOutputI2S           i2s1;           //xy=834,218
    AudioConnection          patchCord1(playMem7, 0, mixer2, 2);
    AudioConnection          patchCord2(playMem3, 0, mixer1, 2);
    AudioConnection          patchCord3(playMem4, 0, mixer1, 3);
    AudioConnection          patchCord4(playMem8, 0, mixer2, 3);
    AudioConnection          patchCord5(playMem5, 0, mixer2, 0);
    AudioConnection          patchCord6(playMem6, 0, mixer2, 1);
    AudioConnection          patchCord7(playMem2, 0, mixer1, 1);
    AudioConnection          patchCord8(playMem1, 0, mixer1, 0);
    AudioConnection          patchCord9(playMem9, 0, mixer4, 0);
    AudioConnection          patchCord10(playMem12, 0, mixer4, 3);
    AudioConnection          patchCord11(playMem11, 0, mixer4, 2);
    AudioConnection          patchCord12(playMem10, 0, mixer4, 1);
    AudioConnection          patchCord13(playMem16, 0, mixer5, 3);
    AudioConnection          patchCord14(playMem13, 0, mixer5, 0);
    AudioConnection          patchCord15(playMem14, 0, mixer5, 1);
    AudioConnection          patchCord16(playMem15, 0, mixer5, 2);
    AudioConnection          patchCord17(mixer5, 0, mixer3, 3);
    AudioConnection          patchCord18(mixer4, 0, mixer3, 2);
    AudioConnection          patchCord19(mixer2, 0, mixer3, 1);
    AudioConnection          patchCord20(mixer1, 0, mixer3, 0);
    AudioConnection          patchCord21(mixer3, 0, i2s1, 0);
    AudioConnection          patchCord22(mixer3, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=643,692
    // GUItool: end automatically generated code
    
    
    
    //CAP TOUCH Vars//
    Adafruit_MPR121 cap = Adafruit_MPR121();
    uint16_t lasttouched = 0;
    uint16_t currtouched = 0;
    
    
    
    // Bounce objects to read pushbuttons 
    Bounce rec1Button = Bounce(0, 15);
    Bounce play1Button = Bounce(1, 15);
    Bounce rec2Button = Bounce(2, 15);
    Bounce play2Button = Bounce(3, 15);
    //Bounce button5 = Bounce(4, 15);
    //Bounce button6 = Bounce(5, 15);
    //Bounce button7 = Bounce(6, 15);
    //Bounce button8 = Bounce(8, 15);
    
    //TEMPO Vars//
    elapsedMillis blinkTime;
    elapsedMillis loopTime;
    int tempoPin = A0; 
    int millisBPM = 0;
    int bars;
    int bpm;
    int tempoCounter = 0;
    int barsCounter = 0;
    bool didPlay = false;
    bool didBarPlay = false;
    
    ///////////////////
    
    void setup() {
      Serial.begin(9600);
    
    //int timing[];
    
    ////////LED Vars//////
    FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
    //////////////////
        while (!Serial) { // needed to keep leonardo/micro from starting too fast!
        delay(10);
      }
      
    //  Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 
      
      // Default address is 0x5A, if tied to 3.3V its 0x5B
      // If tied to SDA its 0x5C and if SCL then 0x5D
      if (!cap.begin(0x5A)) {
    //    Serial.println("MPR121 not found, check wiring?");
        while (1);
      }
    //  Serial.println("MPR121 found!");
    
    
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
    //  pinMode(4, INPUT_PULLUP);
    //  pinMode(5, INPUT_PULLUP);
    //  pinMode(6, INPUT_PULLUP);
    //  pinMode(8, INPUT_PULLUP);
      
      AudioMemory(10);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      ///////////MIXERS IN///////////////////
      mixer1.gain(0, 0.4);
      mixer1.gain(1, 0.4);
      mixer1.gain(2, 0.4);
      mixer1.gain(3, 0.4);
      mixer2.gain(0, 0.4);
      mixer2.gain(1, 0.4);
      mixer2.gain(2, 0.4);
      mixer2.gain(3, 0.4);
      mixer4.gain(0, 0.4);
      mixer4.gain(1, 0.4);
      mixer4.gain(2, 0.4);
      mixer4.gain(3, 0.4);
      mixer5.gain(0, 0.4);
      mixer5.gain(1, 0.4);
      mixer5.gain(2, 0.4);
      mixer5.gain(3, 0.4);
    
      ////////////////MIXER OUT////////////
      mixer3.gain(0, 0.4);
      mixer3.gain(1, 0.4);
      mixer3.gain(2, 0.4);
      mixer3.gain(3, 0.4);
      
    
    // //Envelope///
    //  envelope1.attack(0.3);
    //  envelope1.hold(0);
    //  envelope1.decay(0.1);
    //  envelope1.sustain(0.3);
    //  envelope1.release(1000);
    //
    //  envelope2.attack(0.3);
    //  envelope2.hold(0);
    //  envelope2.decay(0.1);
    //  envelope2.sustain(0.3);
    //  envelope2.release(1000);
    }
    
    
    
    
    
    bool preCount = false;
    bool isRec1 = false;
    bool isPlay1 = false;
    bool isRec2 = false;
    bool isPlay2 = false;
    bool rec1Mode = false;//////TOGGLE REC1 AND STOP
    bool rec2Mode = false;//////TOGGLE REC2 AND STOP
    bool play1Mode = false;//////TOGGLE PLAY1 AND STOP
    bool play2Mode = false;//////TOGGLE PLAY2 AND STOP
    
    void loop() {
    ////////////MAKE LEDS BLACK////////////
    if (!isPlay1 && !isRec1 && !isPlay2 && !isRec2){
      for (int i = 0; i < NUM_LEDS; i++){
        leds[i] = CRGB::Black;
        FastLED.show();  
      }
    }
    /////////////////BPM///////////////////////
    bpm = map(analogRead(tempoPin),0,1023,60,140);
    
    millisBPM = 60000/bpm;
    
    bars = millisBPM/4;
    ///////////BUTTON CHECK////////////
    rec1Button.update();
    if (rec1Button.fallingEdge()){
      if (rec1Mode == false){
      preCount = true;
      barsCounter = 0; 
     ///////////////CLEAR THE RECORD AND PLAY ARRAYS//////////////////
      memset(melody1, 0, sizeof(melody1));
      memset(melody2, 0, sizeof(melody2));
      memset(melody1Play, 0, sizeof(melody1Play));
      memset(melody2Play, 0, sizeof(melody2Play));
      Serial.println("record12");
      ////////////////////////////////////////////
      arrToggle12 = false;
      isRec1 = true;
      //////STOP IF PLAY 1 IS PLAYING//////////////
      isPlay1 = false;
      ///////////////
      isRec2 = false;
      } else {
        barsCounter = 0;
    //    envelope1.noteOff();
        for (int i = 0; i < 64; i++){
          melody1Play[i] = melody1[i];
          melody2Play[i] = melody2[i];
         }
         isRec1 = false;
         channelToggle = false;
        Serial.println("stopRecording1");
       }
     rec1Mode = !rec1Mode;
    }
    play1Button.update();
    if (play1Button.fallingEdge()){
      if (!play1Mode){
      ////////DONT REC WHILE PLAY/////////////
      isRec1 = false;
      ///////////////////////
      barsCounter = 0; 
      isPlay1 = true;
        Serial.println("play1");
      } else {
        barsCounter = 0;
        Serial.println("stopPlaying1");  
        isPlay1 = false;
        for (int i = 0; i < NUM_LEDS; i++){
        leds[i] = CRGB::Black;
        FastLED.show();  
      }
        }
      play1Mode = !play1Mode;
    }
    rec2Button.update();
    if (rec2Button.fallingEdge()){
      if (rec2Mode == false){
      preCount = true;
      barsCounter = 0;
      ///////////////CLEAR THE RECORD AND PLAY ARRAYS//////////////////
      memset(melody3, 0, sizeof(melody3));
      memset(melody4, 0, sizeof(melody4));
      memset(melody3Play, 0, sizeof(melody3Play));
      memset(melody4Play, 0, sizeof(melody4Play));
      Serial.println("record34");
      ///////////////////////////////////////
      arrToggle34 = false;
      //////STOP IF PLAY 1 IS PLAYING//////////////
      isPlay2 = false;
      ///////////////
      isRec2 = true;
      isRec1 = false;
      } else {  
        barsCounter = 0;
    //    envelope2.noteOff();
        for (int i = 0; i < 64; i++){
          melody3Play[i] = melody3[i];
          melody4Play[i] = melody4[i];
        }
        isRec2 = false;
        channelToggle = true;
        Serial.println("stopRecording2");
       }
       rec2Mode = !rec2Mode;
    }
    play2Button.update();
    if (play2Button.fallingEdge()){
       if (!play2Mode){
     ////////DONT REC WHILE PLAY/////////////
      isRec2 = false;
      ///////////////////////
      barsCounter = 0; 
      isPlay2 = true;
        Serial.println("play2");
      } else {
        barsCounter = 0;
        Serial.println("stopPlaying2");
        isPlay2 = false;
        for (int i = 0; i < NUM_LEDS; i++){
        leds[i] = CRGB::Black;
        FastLED.show();  
      }
        }
      play2Mode = !play2Mode;
    }
    //recButton.update();
    //if (recButton.fallingEdge()){
    //  preCount = true;
    //  barsCounter = 0; 
    //  memset(melody1, 0, sizeof(melody1));
    //  memset(melody2, 0, sizeof(melody2));
    //    Serial.println("record");
    //  arrToggle = false;
    //}
    //playButton.update();
    //if (playButton.fallingEdge()){
    //  barsCounter = 0; 
    //  isPlay = true;
    //    Serial.println("play");
    //}
    //stopButton.update();
    //if (stopButton.fallingEdge()){
    //  isPlay = false;
    //  isRec = false;
    //  tempoCounter = 0;
    //  barsCounter = 0;
    //  envelope1.noteOff();
    //  for (int i = 0; i < 64; i++){
    //    melody1Play[i] = melody1[i];
    //    melody2Play[i] = melody2[i];
    //    }
    //    Serial.println("stop");
    //}
    //channelButton.update();
    //if(channelButton.fallingEdge()){
    //    channelToggle = !channelToggle;
    //  }
    ////////////PRECOUNT/////////////////////
    if (preCount){
         playMem1.play(AudioSampleTomtom);
       leds[0] = CRGB::Red;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleTomtom);
       leds[0] = CRGB::Red;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
       playMem1.play(AudioSampleSnare);
       leds[0] = CRGB::Green;
          FastLED.show();  
       delay(millisBPM);
        
    }
      preCount = false;
      
    ///////////////////SEQUENCE////////////////////
    if(isRec1 || isPlay1 || isRec2 || isPlay2){
      
    //////////////////Couner of bars///////////
    if(blinkTime > millisBPM/4 ){
          barsCounter ++;
          didPlay = false;
          didBarPlay = false;
          blinkTime = 0;
    //      envelope1.noteOff();
          Serial.println(barsCounter);
          }
    ///////////////////CLICK////////////////////
      if (barsCounter == 4 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
    //        playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show(); 
      } else if (barsCounter == 8 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 12 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 16 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      } else if(barsCounter == 20 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
    //        playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show();  
        
      } else if (barsCounter == 24 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 28 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 32 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      }else if(barsCounter == 36 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
    //        playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show();  
        
      } else if (barsCounter == 40 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 44 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 48 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      }else if(barsCounter == 52 && !didPlay){
        leds[3] = CRGB::Black;
    //    Serial.println('!');
    //    Serial.println(bpm);
    //        playMem1.play(AudioSampleTomtom);
        didPlay = true;
        leds[0] = CRGB::Red;
        FastLED.show();  
        
      } else if (barsCounter == 56 && !didPlay){
        leds[0] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[1] = CRGB::Green;
        FastLED.show();  
        
      } else if (barsCounter == 60 && !didPlay){
        leds[1] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[2] = CRGB::Green;
        FastLED.show(); 
         
      } else if (barsCounter == 64 && !didPlay){
        leds[2] = CRGB::Black;
    //    Serial.println('/');
    //        playMem1.play(AudioSampleSnare);
        didPlay = true;
        leds[3] = CRGB::Green;
        FastLED.show();  
      }
      
    
    }
    ///////////////////PLAY THE LOOP//////////////////
    if (isPlay1){
      if(didBarPlay == false){
        if(arrToggle12 == true){
          if(melody1Play[barsCounter]!= NULL){
           if (play1MemMode == 0 && !playMem1.isPlaying()){
            playMem1.play(melody1Play[barsCounter]); 
            } else if (play1MemMode == 1 && !playMem2.isPlaying()){
              playMem2.play(melody1Play[barsCounter]);
             } else if (play1MemMode == 2 && !playMem3.isPlaying()){
              playMem3.play(melody1Play[barsCounter]);
              } else if (play1MemMode == 3 && !playMem4.isPlaying()){
              playMem4.play(melody1Play[barsCounter]);
              } else if (play1MemMode == 4 && !playMem5.isPlaying()){
              playMem5.play(melody1Play[barsCounter]);
             } else if (play1MemMode == 5 && !playMem6.isPlaying()){
              playMem6.play(melody1Play[barsCounter]);
              } else if (play1MemMode == 6 && !playMem7.isPlaying()){
              playMem7.play(melody1Play[barsCounter]);
              }else if (play1MemMode == 7 && !playMem8.isPlaying()){
              playMem8.play(melody1Play[barsCounter]);
              }
            play1MemMode ++; 
        }
       }else if(arrToggle12 == false){
        if(melody2Play[barsCounter]!= NULL){
          if (play1MemMode == 0 && !playMem1.isPlaying()){
            playMem1.play(melody2Play[barsCounter]); 
            } else if (play1MemMode == 1 && !playMem2.isPlaying()){
              playMem2.play(melody2Play[barsCounter]);
             } else if (play1MemMode == 2 && !playMem3.isPlaying()){
              playMem3.play(melody2Play[barsCounter]);
              } else if (play1MemMode == 3 && !playMem4.isPlaying()){
              playMem4.play(melody2Play[barsCounter]);
              } else if (play1MemMode == 4 && !playMem5.isPlaying()){
              playMem5.play(melody2Play[barsCounter]);
             } else if (play1MemMode == 5 && !playMem6.isPlaying()){
              playMem6.play(melody2Play[barsCounter]);
              } else if (play1MemMode == 6 && !playMem7.isPlaying()){
              playMem7.play(melody2Play[barsCounter]);
              }else if (play1MemMode == 7 && !playMem8.isPlaying()){
              playMem8.play(melody2Play[barsCounter]);
              }
            play1MemMode ++; 
        }
       }
      }
      
      } 
      if (isPlay2){
        if(didBarPlay == false){
        if(arrToggle34 == true){
          if(melody3Play[barsCounter]!= NULL){
           if (play2MemMode == 0 && !playMem9.isPlaying()){
            playMem9.play(melody3Play[barsCounter]); 
            } else if (play2MemMode == 1 && !playMem10.isPlaying()){
              playMem10.play(melody3Play[barsCounter]);
             } else if (play2MemMode == 2 && !playMem11.isPlaying()){
              playMem11.play(melody3Play[barsCounter]);
              } else if (play2MemMode == 3 && !playMem12.isPlaying()){
              playMem12.play(melody3Play[barsCounter]);
              } else if (play2MemMode == 4 && !playMem13.isPlaying()){
              playMem13.play(melody3Play[barsCounter]);
             } else if (play2MemMode == 5 && !playMem14.isPlaying()){
              playMem14.play(melody3Play[barsCounter]);
              } else if (play2MemMode == 6 && !playMem15.isPlaying()){
              playMem15.play(melody3Play[barsCounter]);
              }else if (play2MemMode == 7 && !playMem16.isPlaying()){
              playMem16.play(melody3Play[barsCounter]);
              }
            play2MemMode ++;
        }
       }else if(arrToggle34 == false){
        if(melody4Play[barsCounter]!= NULL){
           if (play2MemMode == 0 && !playMem9.isPlaying()){
            playMem9.play(melody4Play[barsCounter]); 
            } else if (play2MemMode == 1 && !playMem10.isPlaying()){
              playMem10.play(melody4Play[barsCounter]);
             } else if (play2MemMode == 2 && !playMem11.isPlaying()){
              playMem11.play(melody4Play[barsCounter]);
              } else if (play2MemMode == 3 && !playMem12.isPlaying()){
              playMem12.play(melody4Play[barsCounter]);
              } else if (play2MemMode == 4 && !playMem13.isPlaying()){
              playMem13.play(melody4Play[barsCounter]);
             } else if (play2MemMode == 5 && !playMem14.isPlaying()){
              playMem14.play(melody4Play[barsCounter]);
              } else if (play2MemMode == 6 && !playMem15.isPlaying()){
              playMem15.play(melody4Play[barsCounter]);
              }else if (play2MemMode == 7 && !playMem16.isPlaying()){
              playMem16.play(melody4Play[barsCounter]);
              }
            play2MemMode ++;
          }
        }
        
       }
        
      }
      didBarPlay = true;
    ////////////////Counter reset/////////////////
        if (barsCounter >= 64){
          barsCounter = 0;
          if (isPlay1){
            if (arrToggle12){
            Serial.println("playing array 1");
    //      for(int i = 0; i < sizeof(melody1); i++){
    //        Serial.println(melody1[i]);
    //        
    //      }
            } else {
              Serial.println("playing array 2");
              }
            }
            if (isPlay2){
              if (arrToggle34){
            Serial.println("playing array 3");
    //      for(int i = 0; i < sizeof(melody1); i++){
    //        Serial.println(melody1[i]);
    //        
    //      }
            } else {
              Serial.println("playing array 4");
              }
              } 
         
    
          if (isRec1){
            arrToggle12 = !arrToggle12;  
            if (arrToggle12){
               memset(melody2, 0, sizeof(melody2));
              }else {
              memset(melody1, 0, sizeof(melody1));
              } 
            }
            if (isRec2){
            arrToggle34 = !arrToggle34;  
            if (arrToggle34){
               memset(melody4, 0, sizeof(melody4));
              }else {
              memset(melody3, 0, sizeof(melody3));
              } 
            } 
          }
    
    
    //////////////KEYBOARD////////////////////
    currtouched = cap.touched();
    
     for (uint8_t i=0; i<12; i++) {
    
      
      //////////////////KEYBOARD PLAY////////////////////////
     
        if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { 
         if(isPlay1){   
          if (play2MemMode == 0 && !playMem9.isPlaying()){
            playMem9.play(notes[i]); 
            } else if (play2MemMode == 1 && !playMem10.isPlaying()){
              playMem10.play(notes[i]);
             } else if (play2MemMode == 2 && !playMem11.isPlaying()){
              playMem11.play(notes[i]);
              } else if (play2MemMode == 3 && !playMem12.isPlaying()){
              playMem12.play(notes[i]);
              } else if (play2MemMode == 4 && !playMem13.isPlaying()){
              playMem13.play(notes[i]);
             } else if (play2MemMode == 5 && !playMem14.isPlaying()){
              playMem14.play(notes[i]);
              } else if (play2MemMode == 6 && !playMem15.isPlaying()){
              playMem15.play(notes[i]);
              }else if (play2MemMode == 7 && !playMem16.isPlaying()){
              playMem16.play(notes[i]);
              }
            play2MemMode ++;
            
        }else if (isPlay2){
          if (play1MemMode == 0 && !playMem1.isPlaying()){
            playMem1.play(notes[i]); 
            } else if (play1MemMode == 1 && !playMem2.isPlaying()){
              playMem2.play(notes[i]);
             } else if (play1MemMode == 2 && !playMem3.isPlaying()){
              playMem3.play(notes[i]);
              } else if (play1MemMode == 3 && !playMem4.isPlaying()){
              playMem4.play(notes[i]);
              } else if (play1MemMode == 4 && !playMem5.isPlaying()){
              playMem5.play(notes[i]);
             } else if (play1MemMode == 5 && !playMem6.isPlaying()){
              playMem6.play(notes[i]);
              } else if (play1MemMode == 6 && !playMem7.isPlaying()){
              playMem7.play(notes[i]);
              }else if (play1MemMode == 7 && !playMem8.isPlaying()){
              playMem8.play(notes[i]);
              }
            play1MemMode ++; 
        }    
    //    if (play1MemMode > 7){
    //      play1MemMode = 0;
    //      }
    
        else {
         
          if (play1MemMode == 0 && !playMem1.isPlaying()){
            playMem1.play(notes[i]); 
            } else if (play1MemMode == 1 && !playMem2.isPlaying()){
              playMem2.play(notes[i]);
             } else if (play1MemMode == 2 && !playMem3.isPlaying()){
              playMem3.play(notes[i]);
              } else if (play1MemMode == 3 && !playMem4.isPlaying()){
              playMem4.play(notes[i]);
              } else if (play1MemMode == 4 && !playMem5.isPlaying()){
              playMem5.play(notes[i]);
             } else if (play1MemMode == 5 && !playMem6.isPlaying()){
              playMem6.play(notes[i]);
              } else if (play1MemMode == 6 && !playMem7.isPlaying()){
              playMem7.play(notes[i]);
              }else if (play1MemMode == 7 && !playMem8.isPlaying()){
              playMem8.play(notes[i]);
              }
            play1MemMode ++; 
        }
    ////////////////////////KEYBOARD RECORD////////////////////////
          if (isRec2){
            if (!arrToggle34){
              melody3[barsCounter] = notes[i];
             }else{
              melody4[barsCounter] = notes[i];
             }
            } else if (isRec1){
              if (!arrToggle12){
              melody1[barsCounter] = notes[i];
              }else{
              melody2[barsCounter] = notes[i];
             }
            }
    //    if (play1MemMode > 7){
    //      play1MemMode = 0;
    //      }
          }
          ////////////////BURNING THE SAMPLES TO THE ARRAYS/////////////////
    //    if(isRec1){ 
    //       
    //       if((currtouched & _BV(i))){
    //          if (!arrToggle12){
    //          melody1[barsCounter] = notes[i];
    //         }else{
    //          melody2[barsCounter] = notes[i];
    //         }
    //        }
    //      } 
    //      if (isRec2){
    //         if((currtouched & _BV(i))){
    //          if (!arrToggle34){
    //          melody3[barsCounter] = notes[i];
    //         }else{
    //          melody4[barsCounter] = notes[i];
    //         }
    //        }
    //       }
      }
        if (play1MemMode > 7){
          play1MemMode = 0;
          }
        if (play2MemMode > 7){
          play2MemMode = 0;
          }
      // reset our state
      lasttouched = currtouched;
    
    
    }

  9. #9
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,069
    each .cpp file is a bout 8 MB !!! that's not right, right?.
    I would have expected an 11.4MB WAV to produce a .cpp file much larger than 8MB, unless perhaps the input was a stereo file and the output was reduced to mono.

    The T3.2 has 256kB of flash memory and 64kB of ram. Files of over a megabyte aren't going to fit and is why you got the error message
    ... section `.text' will not fit in region `FLASH'
    ... region `FLASH' overflowed by 22557984 bytes
    A T3.6 has 1MB of flash and 256kB of ram so those files won't even fit in the largest Teensy available.

    Pete

  10. #10
    Junior Member
    Join Date
    Mar 2019
    Posts
    17
    Thanks for the response Pete..

    I managed to bring in smaller files - checkout this thread : https://forum.pjrc.com/threads/55627...yMemory-limits

    if you'll go there you'll see that I still ran into the same problem

    I am not very knowledgable in flash memory and ram - does this mean that the accumulated .cpp files should not exceed 256kb? or is it the .h files?

    I wish to use many samples - should I use the SDplayer?

    Thank you so much

  11. #11
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,567
    Quote Originally Posted by Ayal View Post
    I am not very knowledgable in flash memory and ram - does this mean that the accumulated .cpp files should not exceed 256kb? or is it the .h files?
    Best would be to learn the absolute basics before. At least learn what a compiler (esp. gcc) is, and what it does

    The size of the .cpp files does not matter. The binary file size (before converting the files to .cpp) matters.

    Quote Originally Posted by Ayal View Post
    I wish to use many samples - should I use the SDplayer?
    No, use a SPI Flash. SD does not allow to play many samples simultanously.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    To estimate the data size, look at the array definition. For example:

    Code:
    #include "AudioSampleCashregister.h"
    #include <Arduino.h>
    // Converted from cashregister.wav, using 22050 Hz, u-law encoding
    PROGMEM
    const unsigned int AudioSampleCashregister[5809] = {
    0x02005AB4,0x82060707,0x03010301,0x08038287,0x81820200,0x09120407,0x15091108,0x02080611,
    0x0D050D11,0x8008150C,0x93810480,0x000D8890,0x0A060406,0x06000681,0x80828702,0x89928405,
    0x04820983,0x8C860D05,0x880D0004,0x84000B0B,0x8C8D8C8F,0x84829181,0x14860600,0x0A0C080C,
    In this case the array is 5809 items, and each item is a 4 byte integer, so the size is 23236 bytes.

    If your sounds are long, I'm afraid the limited internal program memory probably isn't going to be enough, no matter what you do. But if you want to try, editing the sound in Audacity or other programs, to reduce the sample rate and trim off any silence or very low amplitude trailing sound is usually the best way to save space. But the 256K internal flash is really only enough for a small collection of very short samples.

    For longer sound clips, add a SPI flash chip.

  13. #13
    Junior Member
    Join Date
    Mar 2019
    Posts
    17
    For longer sound clips, add a SPI flash chip.
    Should I just play from the SD? if this is a step-sequencer - would the SD latency be significant?

    if so - I guess the best way about it would be to get the 3.6, right?

    Thank you all, it's very reassuring to know that I can find answers here.

  14. #14
    Junior Member
    Join Date
    Mar 2019
    Posts
    17
    The binary file size (before converting the files to .cpp) matters
    I'm sorry if this is still a very basic one - how do I control the binary file size? is this the ".wav" file before conversion?

    Thanks F.B

  15. #15
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,567
    Quote Originally Posted by Ayal View Post
    I'm sorry if this is still a very basic one - how do I control the binary file size? is this the ".wav" file before conversion?

    Thanks F.B
    More or less - *.wav has some overhead - Paul wrote the most exact method.

Posting Permissions

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