Audio overlap loop: Difference between revisions

Content added Content deleted
No edit summary
Line 77: Line 77:
=={{header|Julia}}==
=={{header|Julia}}==
Uses Julia's ability to run iterations of a 4 loop in separate threads to play a file 4 times, with each play 0.1 seconds out of sync with the previous play. Requires 4 available threads on the CPU at Julia startup.
Uses Julia's ability to run iterations of a 4 loop in separate threads to play a file 4 times, with each play 0.1 seconds out of sync with the previous play. Requires 4 available threads on the CPU at Julia startup.
<lang julia>soundfile = "loop.wav"
<lang julia>const soundfile = "loop.wav"


if length(ARGS) < 1
@Threads.threads for secs in 0.0:0.1:0.3
println("Usage: give number of repetitions in echo effect as argument to the program.")
begin sleep(secs); run(`play "$soundfile"`); end
else
((repetitions = tryparse(Int, ARGS[1])) != nothing) || (repetitions = 3)
(repetitions < 1) && (repetitions = 3)
(repetitions > Threads.nthreads()) && (repetitions = Threads.nthreads())

@Threads.threads for secs in 0.0:0.1:((repetitions - 1) * 0.1)
begin sleep(secs); run(`play "$soundfile"`); end
end
end
end
</lang>
</lang>