xxxxxxxxxx
63
let soundSamples = [];
let reverb, delay, filter;
let playbackRates = [0.5, 1, 1.5, 2, 0.5, 1, 0.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); // duration, decay rate
delay.process(soundSamples[0], 0.5, 0.7, 2300); // source, delayTime, feedback, filterFreq
filter.freq(800); // Set the frequency cutoff for low-pass filter
// Connect sounds to effects
soundSamples.forEach((sample) => {
sample.disconnect(); // Disconnect from main output to apply effects
filter.process(sample); // Apply low-pass filter
reverb.process(sample); // Apply reverb
});
// Start the algorithmic composition
setInterval(algorithmicComposition, loopDuration);
setTimeout(endComposition, soundDuration);
}
function algorithmicComposition() {
soundSamples.forEach((sample, index) => {
if (!sample.isPlaying()) {
// Set playback rate manually for pitch manipulation
let playbackRate = playbackRates[index % playbackRates.length]; // Deterministic playback rate based on index
sample.rate(playbackRate);
// Adjust pan and volume for variation
let panValue = (index % 2 === 0) ? 1 : -1; // Alternate between left and right pan
sample.pan(panValue); // Set panning (1 for right, -1 for left)
sample.setVolume(0.8); // Set volume
// Play sample
sample.play();
}
});
}
function endComposition() {
soundSamples.forEach((sample) => {
sample.stop(); // Stop all samples
});
}