xxxxxxxxxx
75
// this audio modification was inspired by hindu temples ceremonies where the gods are worshiped with flamed wicks. During the ceremony the musicians play drums, harmoniums, cymbals and tabla. In each ceremony, the same tunes are played but at different amplitures, pitches and volumes. This sketch aims to immitate those ceremonies, however the audio can be changes through the toggles.
let sounds = [];
let NUM = 7;
let sliders = [];
function preload() {
for (let i = 0; i < NUM; i++) {
sounds.push(loadSound("data/" + i + ".mp3"));
}
}
function setup() {
createCanvas(400, 900);
for (let i = 0; i < NUM; i++) {
sliders.push(createSliders(i));
}
}
function draw() {
updateBackground();
for (let i = 0; i < NUM; i++) {
updateSound(sounds[i], sliders[i]);
displayText(sliders[i]);
}
}
function updateBackground() {
// Calculate color based on slider values
let r = map(sliders[0].pitchSlider.value(), 0.5, 2, 0, 255);
let g = map(sliders[1].pitchSlider.value(), 0.5, 2, 0, 255);
let b = map(sliders[2].pitchSlider.value(), 0.5, 2, 0, 255);
background(r, g, b);
}
function createSliders(index) {
const yOffset = index * 120;
const pitchSlider = createSlider(0.5, 2, 1, 0.01);
pitchSlider.position(20, 50 + yOffset);
const volumeSlider = createSlider(0, 1, 0.5, 0.01);
volumeSlider.position(20, 80 + yOffset);
const playButton = createButton('Play/Pause');
playButton.position(20, 110 + yOffset);
playButton.mousePressed(() => toggleAudio(sounds[index]));
return { pitchSlider, volumeSlider, playButton };
}
function updateSound(sound, sliders) {
sound.setVolume(sliders.volumeSlider.value());
sound.rate(sliders.pitchSlider.value());
}
function displayText(sliders) {
fill(0);
textSize(14);
// Display text for Pitch slider
text(`Pitch: ${sliders.pitchSlider.value()}`, sliders.pitchSlider.x + sliders.pitchSlider.width + 10, sliders.pitchSlider.y + 15);
// Display text for Volume slider
text(`Volume: ${sliders.volumeSlider.value()}`, sliders.volumeSlider.x + sliders.volumeSlider.width + 10, sliders.volumeSlider.y + 15);
}
function toggleAudio(audio) {
if (audio.isPlaying()) {
audio.pause();
} else {
audio.loop();
}
}