# Sound loop without hiccups

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?

• Can you share the code you tried? – Vitaliy Kaurov Sep 20 '18 at 16:06
• 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. – N.J.Evans Sep 20 '18 at 16:07
• 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. – user447648 Sep 20 '18 at 17:44

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.

• 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! :) – user447648 Sep 20 '18 at 17:42
• 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. – kjosborne Sep 20 '18 at 18:46