When an audio file has finished

Hey there, I'm using a Teensy v3.1 to play 3 different sounds with a push button. Although I'm not actually using the audio shield or an sd card, just the controllers on-board flash memory.

The problem is:-
When the button is pressed and held down I need the 1st file to be played once to its end.
Then followed by the 2nd file to its end but this file is in a loop.
When the button is released the 3rd file needs to be played once.
The problem I'm having is the files are being cut off short when played due to the bounce update.
How can i get round this problem so the 1st 2 files can be played to the end with the button held down.
Atm all I'm getting a quick messy burst from the speaker.

Many thanks in advance for any help with this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <Bounce.h>
#include "mngs1.h"
#include "mngs2.h"
#include "mngs3.h"

AudioPlayMemory gunSound;  // creates the Audio memory object
AudioOutputAnalog dac;   // play to on-chip DAC
AudioConnection c1(gunSound, 0, dac, 0);
AudioControlSGTL5000 audioShield;
const int buttonPin = 2;
Bounce pushButton = Bounce(buttonPin, 1);   // 1 ms debounce time

void setup()
{
pinMode(2, INPUT_PULLUP); //Sets the digital pin as input:
AudioMemory(1);  //Allocates 1 memory spaces for audio file to be played

// turn on the output
  audioShield.enable();
  audioShield.volume(0.5);
}

byte previousState = HIGH;

void loop()
{
pushButton.update();
   
    if (pushButton.fallingEdge())
      {
       gunSound.play(mngs1);
       pushButton.update();
             while (pushButton.fallingEdge())    
                    {
	             gunSound.play(mngs2);
                    }
                     gunSound.play(mngs3);
      }       
};   
Last edited on
Topic archived. No new replies allowed.