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

Thread: is this even possible ?

  1. #1
    Junior Member
    Join Date
    Jul 2021
    Posts
    9

    is this even possible ?

    Hi,
    I want to make a sound output device on a model train using a teensy
    When the train wheel makes one revolution the sound would be triggered "Chuff"

    What I want to know is if I had a sound sample " Chuff "on an SD card that was say 900mS long
    and I triggered it once per second then I can see I would get a chuff and a 100mS pause that would keep repeating
    for as long as the triggers kept coming, so far so good

    but what if the trigger comes every 1/2 second or even faster? the re trigger would happen before the sample had finished
    would it ignore the second trigger because the sample is still playing ? or would it halt the sample playback and restart it playing from the beginning

    What I want is for the sound to retrigger to the beginning of the sample as soon as it gets a trigger so in fact in may be going Chu Chu or ch ch rather than the full Chuff
    What I dont want is that once triggered it must complete the full sample sound even though its being triggered sooner

    So, is it possible can I restart the sample from the beginning whilst it was still playing ? and is it difficult to do ?

    Hope someone can help

    Don

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,358
    What Teensy for generic ref, and what method is used to produce the sound? PJRC Audio library or other?

  3. #3
    Junior Member
    Join Date
    Jul 2021
    Posts
    9
    I have a teensy 3.6 and a teensy 4.1 with matching audio boards, I dont mind which I use any ideas would be appreciated

    Don

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,358
    The Teensy Audio library is in use?

    Not overly practiced or current there - not sure if the Audio Workshop covers this, but recalling isPlaying().
    So testing for isPlaying()
    Code:
    bool AudioPlaySdWav::isPlaying(void)
    {
        // ...
    }
    If that returns true before the playing the next CHUFF it might work to stop() the prior one:
    Code:
    void AudioPlaySdWav::stop(void)
    {
        // ...
    }

  5. #5
    Junior Member
    Join Date
    Jul 2021
    Posts
    9
    Thanks for the help. Never programmed a teensy yet so have lots of reading and learning to do but I follow the
    principal of what your saying.
    on receiving trigger
    Check if sample is playing
    if it is stop it

    start playing sample

    Thanks for the help paul

    Don

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,358
    Paul made a good tutorial for the Audio library: pjrc.com/store/audio_tutorial_kit.html

    It has a varied set of examples and a PDF to look through.

    There are more than a few samples playing sound and responding to buttons like : {local install}\hardware\teensy\avr\libraries\Audio\examples\Tutorial\Part_1_05_Do_Mor e_While_Playing\Part_1_05_Do_More_While_Playing.in o

Posting Permissions

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