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

Thread: Audio File playback dependent on time?

  1. #1
    Junior Member
    Join Date
    Mar 2016
    Posts
    7

    Audio File playback dependent on time?

    Hello!

    I am a firefighter looking to improve the life of my crew. Here is the breakdown..... We have a Federal Informer (basically a piece of equipment listening to dispatch that alarms when certain tones are sounded) The problem is that the Informer is only capable of playing pre loaded alarms consisting mainly of insanely intrusive audio files. Not a deal breaker until 2 am when the laser beam effect jolts your heart rate from 60 to 200 in half a second! The informer does have a relay which can be programmed to to stay closed for a programmed length of time. The current Laser beam is set to fire for 8 seconds when triggered. So this brings me to my set of questions that I hope you can help me with.

    1. Is the Arduino script and the Teensy 3 capable of running without error for months on end?
    2. In the event of power failure would the Teensy reboot back to operation once power is restored?
    3. Can I somehow edited a script so that when the teensy senses the relay has been closed (I assume it would simply act as a switch in the tutorial) the teensy would choose between 2 sound files based on the time of day? For example, a louder harsher alarm for day hours and a more subdued alarm for the hours of 10 pm to 7 am? I am not sure how to incorporate the clock but I noticed a shield adapter (here) with clock battery holder. Does this mean the Teensy has the ability to hold time?

    I thank you in advance for your help. I have been trying to use a Rasberry Pi to make this project a reality but after stumbling on the teensy I think this may be a better solution! And I am getting tired of printing "hello world" in Javascript!

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,654
    Quote Originally Posted by snipeworm View Post
    Hello!

    I am a firefighter looking to improve the life of my crew. Here is the breakdown..... We have a Federal Informer (basically a piece of equipment listening to dispatch that alarms when certain tones are sounded) The problem is that the Informer is only capable of playing pre loaded alarms consisting mainly of insanely intrusive audio files. Not a deal breaker until 2 am when the laser beam effect jolts your heart rate from 60 to 200 in half a second! The informer does have a relay which can be programmed to to stay closed for a programmed length of time. The current Laser beam is set to fire for 8 seconds when triggered. So this brings me to my set of questions that I hope you can help me with.

    1. Is the Arduino script and the Teensy 3 capable of running without error for months on end?
    2. In the event of power failure would the Teensy reboot back to operation once power is restored?
    3. Can I somehow edited a script so that when the teensy senses the relay has been closed (I assume it would simply act as a switch in the tutorial) the teensy would choose between 2 sound files based on the time of day? For example, a louder harsher alarm for day hours and a more subdued alarm for the hours of 10 pm to 7 am? I am not sure how to incorporate the clock but I noticed a shield adapter (here) with clock battery holder. Does this mean the Teensy has the ability to hold time?

    I thank you in advance for your help. I have been trying to use a Rasberry Pi to make this project a reality but after stumbling on the teensy I think this may be a better solution! And I am getting tired of printing "hello world" in Javascript!
    Yes to all questions - it would be the best to save the soundfiles in the internal flash.
    How long (in seconds) are they ?

  3. #3
    Junior Member
    Join Date
    Mar 2016
    Posts
    7
    Quote Originally Posted by Frank B View Post
    Yes to all questions - it would be the best to save the soundfiles in the internal flash.
    How long (in seconds) are they ?
    They need to be 8 seconds each. I will manipulate whatever files to ensure they are 8 seconds each. Will 16 seconds of decent quality audio fit in flash?

    Thanks for the help by the way!

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    Nope. You can get 20 seconds at low quality in the internal flash, using 11 kHz ulaw encoded. That can actually sound pretty decent for some things. But sounds like cymbals and snare drums become muddy without more bandwidth.

    You probably need the flash chip.

  5. #5
    Junior Member
    Join Date
    Mar 2016
    Posts
    7
    I think using an sd card would be better in the fact that changing audio files would easier than re writing the script. Firefighters aren't the most tech savy group.

    I'm going to order the teensy, breadboard, and audio shield. Anything else I should get?

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,654
    Might be a Idea to order a SPI Flash (can be soldered to the audiocard) too ? Its more reliable than SD - you can copy the files from SD to it. Perhaps in a later development step.

  7. #7
    Junior Member
    Join Date
    Mar 2016
    Posts
    7
    Ok guys, I am a total noob but I feel like I am getting this a little bit. I have the audio sheild all setup on the teensy and am playing the tutorial files from the SD card. I have tried replacing a wav file with another wav file using the same name but I cannot hear it. The serial monitor says it is playing the file but no audio.... Any idea? Is there a mandatory file set that the teensy needs?

    edit.....Sorry, I just tried a 16bit vs 8 bit and it works now! thanks
    Last edited by snipeworm; 03-24-2016 at 03:13 AM.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    Glad you got it.

    The wav player example (and object within the library) could really use some improvement in giving feedback *why* it can't play a particular file.

  9. #9
    Junior Member
    Join Date
    Mar 2016
    Posts
    7
    Thanks Paul!

    So I am trying to figure this out. I need the button on digital pin 0 to play SD track 1 while pressed and button connected to digital pin 1 to play SD track 2 while pressed and all audio to stop when the buttons are nt pressed. I will also use the anolog pot 2 to control the output level to match the radio traffic level. l also would like to leave the LED blink on the sketch so that it will help verify the unit is running. Can anyone help me tweak this code (which is the do more while playing music tutorial) so that I can get this thing finished up? I appreciate the help... I cannot seem to alter the code into something that will run.


    // Advanced Microcontroller-based Audio Workshop
    //
    // Part 1-5: Respond to Pushbuttons & Volume Knob
    //
    // Do more while playing. Monitor pushbuttons and adjust
    // the volume. Whe the buttons are pressed, stop playing
    // the current file and skip to the next or previous.

    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Bounce.h>

    AudioPlaySdWav playSdWav1;
    AudioOutputI2S i2s1;
    AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
    AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
    AudioControlSGTL5000 sgtl5000_1;

    Bounce button0 = Bounce(0, 15);
    Bounce button2 = Bounce(2, 15); // 15 = 15 ms debounce time

    void setup() {
    Serial.begin(9600);
    AudioMemory(8);
    sgtl5000_1.enable();
    sgtl5000_1.volume(0.5);
    SPI.setMOSI(7);
    SPI.setSCK(14);
    if (!(SD.begin(10))) {
    while (1) {
    Serial.println("Unable to access the SD card");
    delay(500);
    }
    }
    pinMode(13, OUTPUT); // LED on pin 13
    pinMode(0, INPUT_PULLUP);
    pinMode(2, INPUT_PULLUP);
    delay(1000);
    }

    int filenumber = 0; // while file to play

    const char * filelist[4] = {
    "SDTEST1.WAV", "SDTEST2.WAV", "SDTEST3.WAV", "SDTEST4.WAV"
    };

    elapsedMillis blinkTime;

    void loop() {

    if (playSdWav1.isPlaying() == false) {
    const char *filename = filelist[filenumber];
    filenumber = filenumber + 1;
    if (filenumber >= 4) filenumber = 0;
    Serial.print("Start playing ");
    Serial.println(filename);
    playSdWav1.play(filename);
    delay(10); // wait for library to parse WAV info
    }

    // blink the LED without delays
    if (blinkTime < 250) {
    digitalWrite(13, LOW);
    } else if (blinkTime < 500) {
    digitalWrite(13, HIGH);
    } else {
    blinkTime = 0; // start blink cycle over again
    }

    // read pushbuttons
    button0.update();
    if (button0.fallingEdge()) {
    playSdWav1.stop();
    }
    button2.update();
    if (button2.fallingEdge()) {
    playSdWav1.stop();
    filenumber = filenumber - 2;
    if (filenumber < 0) filenumber = filenumber + 4;
    }

    // read the knob position (analog input A2)
    int knob = analogRead(A2);
    float vol = (float)knob / 1280.0;
    sgtl5000_1.volume(vol);
    //Serial.print("volume = ");
    //Serial.println(vol);
    }

  10. #10
    Senior Member
    Join Date
    Oct 2013
    Location
    Rogersville MO
    Posts
    253
    I have implemented all the Informer functions ( using two-tone decoding, a/b and long 'a' oddly enough ) on a bare Teensy using A/D and D/A circuits that Paul recommends. With a little imagination you can generate firefighter approved tones at varying levels. The issue I had was high frequency hiss in the background that was NOT firefighter approved Using the audio shield took care of the hiss but I ran out of time 'retired' before I could deploy it.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    Well, you can use both button0.fallingEdge() and button0.risingEdge(). Just have one start the file playing and the other stop it.

    If this isn't perfectly clear, perhaps start with a dry run where you just put Serial.print("something") in each of those cases and watch the results in the Arduino Serial Monitor while you press the buttons. The key to success in all projects is taking smaller, achievable steps which eventually add up to the solution.

  12. #12
    Junior Member
    Join Date
    Mar 2016
    Posts
    7
    Wow, thats quite a feat! I am just trying to play tracks when triggered, not reengineer such a complicated piece of equipment.... nice work sir!

  13. #13
    Senior Member
    Join Date
    Oct 2013
    Location
    Rogersville MO
    Posts
    253
    BTW: The Teensy can directly generate the Engine 51 tones Which is Quick Call I 2+2 tone format.

  14. #14
    Junior Member
    Join Date
    Mar 2016
    Posts
    7
    I will attempt to do that, thanks. I will need to make each track play with a seperate button press as the button pressed will actually be a relay closing depending on time of day, one track for day hours and the other track for night hours which will be chosen by a mechanical relay with time of day timer. This way it will be easy enough for myself and the other knuckle draggers to reset the time when needed.

Posting Permissions

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