Forum Rule: Always post complete source code & details to reproduce any issue!
-
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
-
Senior Member+
What Teensy for generic ref, and what method is used to produce the sound? PJRC Audio library or other?
-
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
-
Senior Member+
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)
{
// ...
}
-
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
-
Senior Member+
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
-
Forum Rules