0
$\begingroup$

(Many of the Audio* symbols and functionality are still mostly experimental, so I understand that not all the kinks might be worked out yet. Still, I'd like to try to make this work!)

As far as I know, there are two ways to play and loop audio, but each either 1) isn't able to be looped automatically (via evaluation) in an obvious way, or 2) doesn't loop samples well (by inserting a small gap between each playback), respectively:

Audio

When you create an Audio object as output, you have the option to click to expand the output, then click on the "loop" symbol, and play it back looped. E.g.

AudioGenerator[{"Sin", Quantity[110, "Hz"], 0}]

the default audio outputthe expanded audio output with an arrow pointing to the looping button

(Apologies for the large images; feel free to shrink them if you know how.)

This loops seamlessly. However, the only way I know to get this behavior is by clicking on the output manually.

AudioStream

On the other hand, if you create an AudioStream via e.g. AudioPlay, and set Looping -> True, it plays and loops automatically upon evaluation, but the audio features an unpleasant skip when it loops back to the beginning.

AudioPlay[AudioGenerator[{"Sin", Quantity[110, "Hz"], 0}], Looping -> True]

(I still haven't updated from 12.3.0 to 12.3.1, so if this happens to have been fixed in the 0.0.1 difference, let me know :) )


I'd like a way to loop audio automatically without clicking and free of skipping (in particular, for dynamic purposes). So, I'd like either

  • a way to interface with Audio output objects without mouse inputs that lets me trigger playback and enable looping automatically, preferably while hiding the output form visually as well

  • a way to eliminate the skip heard in looped AudioStreams, so that (when possible) it loops seamlessly

  • a totally separate workaround that lets me play back and loop audio programmatically and seamlessly.

(It would also be great to be able to manipulate the audio as its playing—e.g. to change the frequency—so if pursuing one of these directions over another is more amenable to that end goal, I'd appreciate any insight. But that's not strictly necessary.)

Thanks!

$\endgroup$
2
  • $\begingroup$ Try AudioGenerator[{"Sin", Quantity[110.1, "Hz"], 0}] -- this does not loop seemlessly... your example only does so because the length of the sample is an exact multiple of 110 Hz and so the Sin wave is continuous across the loop. Unless you are going to have some silence at the end (or beginning) you are not going to get seamless looping for a general sound. $\endgroup$
    – bill s
    Commented Sep 6, 2021 at 0:45
  • $\begingroup$ @bills True, I should clarify that I'm not asking to be able to loop a general sound seamlessly. I only intend to loop samples that I know are loopable seamlessly, such as integral-frequency pure tones for an integral number of seconds. AudioStream objects fail to do even that, while Audio output objects succeed, but require manual operation. $\endgroup$
    – thorimur
    Commented Sep 6, 2021 at 0:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.