2
$\begingroup$

I want to make a seamless sound loop that can play forever, but the consecutive EmitSound commands do not merge as I would like them to; that is, the sound seems to hiccup at the point where the loop restarts. For instance, two consecutive 1-second plays of the same note do not sound the same as a 2-second play of that note. Is there a solution to this problem?

$\endgroup$
  • 2
    $\begingroup$ Can you share the code you tried? $\endgroup$ – Vitaliy Kaurov Sep 20 '18 at 16:06
  • $\begingroup$ Are you talking about a click because the waveforms have a discontinuous phase at the point where the old waveform ends and the new one starts, or a short pause while mathematica does whatever it has to do to load the 'new' sound? If you post the code it may be obvious. $\endgroup$ – N.J.Evans Sep 20 '18 at 16:07
  • $\begingroup$ I had written code that didn't work using a loop and EmitSound. Since I realised that he proposed solution below works, I withdrew the comment with that code. I accepted the answer of kjosborne. $\endgroup$ – user447648 Sep 20 '18 at 17:44
4
$\begingroup$

The AudioStream functions provide a way to do this in 11.3:

snd = Sound[SoundNote["C"]];
aud = Audio[snd];
strm = AudioStream[aud];

AudioPlay[strm, AudioLooping -> True]

starts the playing. When it becomes annoying, you'll want to use AudioStop to stop all playing streams.

$\endgroup$
  • $\begingroup$ I had originally written an objection, but I withdraw it; this actually works. The reason it does not work with sine waves is because of a discrepancy at the point of merge. Thank you! :) $\endgroup$ – user447648 Sep 20 '18 at 17:42
  • $\begingroup$ Glad this worked for you. You might want to unaccept the answer anyway, though. It is typical policy across SE to wait 24 hrs before accepting an answer so that people in all timezones can submit answers. It also increases the possibility someone will write another, better answer. $\endgroup$ – kjosborne Sep 20 '18 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.