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

Thread: Playing very short Sounds gapless

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    2

    Playing very short Sounds gapless

    Hi,
    I'm working at a project that requires to play very short sound-samples (200-300ms) one after another with (nearly) no gap.

    My Dad buit an RC-controlled excavator (Fuchs 301 see here in original) for which I now want to do the sound-module. Therefore we have several sound-samples of the original motor used in this excavator at different loads (~10 samples). Each sample is about 250ms long and has only a few turns of the motor. The idea now is to measure the current used by the motors, decide which of the sample is needed and then play this, but of course wait until the previos sound ended. The sounds are not all from the same length, because with higher rotational speeds they are getting shorter.

    Because the sounds are so short I converted them with WAV2Sketch and imported them into my program. This already works and I can play the Sounds.
    But what I don't like is that I have to check with isPlaying() if a file is still running. Because then I automatically have a short gap to the next sound.
    Is there any other solution you could imagine?
    Some thoughts of me:
    • Because I exactly know how long the sound sample is, i also know when I have to start the next sound, but how can I use this in my program? Because the calculation of the next sound is varying in time
    • Could I perhaps use a AudioPlayQueue and load the data from my samples in there? Then I could possibly realize ZERO gap, by loading directly the bytes of the next sound, but I found no example how to do this
    • Should I use two AudioPlayMemory and "preload" the second one with the next sound


    Sorry for all this (perhaps stupid) questions.
    It would be great if you could give me some hints how you would solve this.

    I can program in C# and Basic, but I have only little experience in C(++) and Arduino.

    Greetings
    Marius

    PS: Sorry for my English, because my native language is german.

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,426
    Quote Originally Posted by Suiram View Post
    But what I don't like is that I have to check with isPlaying() if a file is still running. Because then I automatically have a short gap to the next sound.
    Hm, have you tried it ?
    Maybe you can't imagine, but ... the Teensy so so fast, you will not notice any gap, if you're not using delay() or other artificial waits.
    In addition, there is a small buffer (one "AudioMemory") that helps preventing gaps.

    Preloading is not needed, because if you use wav2sketch, it is in memory, already.

    So...just try it, you will be surprised

    (upload your program here, perhaps as zip, maybe we can help - if you hear clicks or other artifacts - playing samples "gapless" can result in "clicks" if their ends/begins do not fit.. )
    Last edited by Frank B; 12-13-2018 at 07:38 PM.

  3. #3
    Junior Member
    Join Date
    Dec 2018
    Posts
    2
    Thank you for your quick reply.
    I will try to write a program now and post the result here. I also will take a look at the sound signal with the oscilloscope if I can see any gaps ;-)
    All the sound samples start and end at zero crossing, so there should be no "clicks".
    Greetings Marius

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,426
    I think, It's important that they are multiple of 128 samples (one Audioblock) - have not looked at the code, but quite possible that the last block gets filled with 0 for the remaining bytes

Posting Permissions

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