5

My loop seems to stop randomly. What could be the issue?

I tried using a looped Tone.Event, and the same thing happens. Perhaps, its my understanding of the way time is interpreted in the Tone.Loop and the inner Transport.scheduleOnce. The loop could stop at any moment, so refresh and rerun the function if it passes about 10 seconds, or let it run until the Tone.Loop eventually stops, but it will likely stop. I can guarantee that. You can let it play while doing something else, you'll know the Loop has stopped when the sound's volume stops dipping in and out. I got around this issue by binding the essence of the Loop directly to the "tick" event of the Tone.Context; all seems to be functioning as expected then. Still, I want to know why the Loop fails.

function testTone(freq) {
        let interval = 0.5,
            maindip = 0.7;
        let osc = new Tone.Oscillator(freq || 100,'sine').sync().start(0),
            gain = new Tone.Gain(),
            postgain = new Tone.Gain(),
            panner = new Tone.Panner3D(-3,-3,-7),
            freeverb = new Tone.Freeverb(1),
            loop = new Tone.Loop((time)=> {
                let div = Math.random(0,1),
                    dip = 1-div*maindip;
                gain.gain.value = dip;
                postgain.gain.value = dip;
                console.log(time);
                Tone.Transport.scheduleOnce((time)=> {
                    console.log('once upon', time);
                    gain.gain.value = 1;
                    postgain.gain.value = 1;
                }, '+'+(interval*div/2));
            }, interval);
        freeverb.wet.value = 0.2;
        freeverb.dampening.value = 500;
        osc.chain(gain, panner, freeverb, postgain, Tone.Master);
        loop.start(0);

        Tone.Transport.start();

        this.osc = osc;
        this.panner = panner;
        this.gain = gain;
        this.loop = loop;
        this.postgain = postgain;
        this.reverb = freeverb;
    }

The Loop should run forever.

0 Answers0