xxxxxxxxxx
71
let soundSamples = [];
let reverb, delay, filter;
let playbackRates = [0.5, 1, 1.5, 2, 2.5];
let soundDuration = 60000; // 60 seconds
let loopDuration = 5000; // 5 seconds per iteration
function preload() {
// Dynamically load 6 sound samples from the 'ticktock' folder
for (let i = 2; i <= 8; i++) {
soundSamples.push(loadSound(`ticktock/sound${i}.mp3`));
}
}
function setup() {
noCanvas();
userStartAudio();
// Initialize effects
reverb = new p5.Reverb();
delay = new p5.Delay();
filter = new p5.LowPass();
// Set effect parameters
reverb.set(3, 2); // Reverb duration and decay rate
delay.delayTime(0.5);
delay.feedback(0.7);
delay.filter(2300); // Filter frequency for delay
filter.freq(800); // Low-pass cutoff frequency
// Connect sounds to effects using a loop
soundSamples.forEach((sample) => {
sample.disconnect(); // Disconnect default connection to master output
// Apply effects to each sample
filter.process(sample); // Apply low-pass filter
reverb.process(sample); // Apply reverb
delay.process(sample); // Apply delay
});
// Start the algorithmic composition
let compositionInterval = setInterval(algorithmicComposition, loopDuration);
setTimeout(() => {
clearInterval(compositionInterval);
endComposition();
}, soundDuration);
}
function algorithmicComposition() {
soundSamples.forEach((sample, index) => {
if (!sample.isPlaying()) {
// Fixed playback properties
let rate = playbackRates[index % playbackRates.length];
sample.rate(rate);
// Fixed pan and volume
let panValue = 0; // Centered stereo pan
let volumeValue = 0.5; // Medium volume level
sample.pan(panValue);
sample.setVolume(volumeValue);
// Play the sample
sample.play();
}
});
}
function endComposition() {
soundSamples.forEach((sample) => {
sample.stop();
});
}