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

Thread: audio file continuous loop

  1. #1

    audio file continuous loop

    I really did try searching and looking through the example files, but couldn't find any examples on how to loop an audio file.
    For example in the Sample Player sketch, I wold like to switch a toggle and have the snare play over and over.

  2. #2
    Junior Member
    Join Date
    Oct 2015
    Posts
    14
    Look at the Audio -> Tutorial -> Part_1_03_Playing_Music example for how to loop a sample. If you want to trigger it to start by a button one way would be to add a flag variable and have the button press set the flag, and only play if it's not currently playing and the flag is set.

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Posts
    302
    I have edited out all the "unecessary" lines from the AudioSnareSample sketch to leave minimum to get the snare play over and over at the touch or toggle of a button........you can add to it to suit.......this is on a teensy3.2 only ....no attached audio board.

    Code:
    #include <Audio.h>
    
    // WAV files converted to code by wav2sketch
    #include "AudioSampleSnare.h"        // http://www.freesound.org/people/KEVOY/sounds/82583/
    
    // Create the Audio components.  These should be created in the
    // order data flows, inputs/sources -> processing -> outputs
    //
    AudioPlayMemory    sound0;
    
    AudioOutputAnalog  dac;     // play to both I2S audio board and on-chip DAC
    
    // Create Audio connections between the components
    //
    
    AudioConnection c1(sound0, 0, dac, 0);
    
    void setup() {
    
      // Audio connections require memory to work.  For more
      // detailed information, see the MemoryAndCpuUsage example
      AudioMemory(10);
    
    }
    
    void loop() {
    
      // Snare plays continuously while the pin is touched.
     
        while(touchRead(1) < 2000);
        
        sound0.play(AudioSampleSnare);
        
        delay(100);    //change the delay ms to suit
     
    }

Posting Permissions

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