This is my first sound test here on DittyToy. The documentation exists, but I don't understand much of it; it's a bit difficult. So I asked the AI chat for help, and this was the result. I hope to make something more personal, and not rely on the AI for help. I hope to understand this language better...!!! :)
Log in to post a comment.
ditty.bpm = 50;
// --- Definir sintetizadores ---
// Sine ya existe, ¡pero por claridad lo dejamos como referencia!
// const sine = synth.def((phase, env, tick, options) => Math.sin(phase * 2 * Math.PI) * env.value);
// Definir onda cuadrada
const square = synth.def((phase, env, tick, options) => {
// phase es un valor entre 0 y 1 (ciclo normalizado)
const wave = (phase % 1 < 0.5) ? 1 : -1;
return wave * env.value;
});
// Definir onda de diente de sierra (opcional)
// const saw = synth.def((phase, env, tick, options) => {
// const wave = 2 * (phase % 1) - 1;
// return wave * env.value;
// });
// --- Tus notas ---
const notes = [
[0.00000, 35.0, 0.75000],
[0.00000, 54.0, 0.06250],
[0.12500, 54.0, 0.25000],
[0.31250, 50.0, 0.43750],
[0.50000, 47.0, 0.62500],
[0.81250, 47.0, 0.93750],
[1.18750, 52.0, 1.43750],
[1.43750, 28.0, 2.43750],
[1.62500, 52.0, 1.75000],
[1.87500, 52.0, 2.00000],
[2.06250, 56.0, 2.12500],
[2.18750, 56.0, 2.25000],
[2.31250, 57.0, 2.43750],
[2.50000, 59.0, 2.75000],
[2.75000, 33.0, 3.75000],
[2.75000, 57.0, 2.87500],
[2.90625, 57.0, 3.03125],
[3.09375, 57.0, 3.28125],
[3.28125, 52.0, 3.53125],
[3.59375, 50.0, 3.71875],
[4.00000, 54.0, 4.25000],
[4.18750, 26.0, 5.18750],
[4.43750, 54.0, 4.50000],
[4.68750, 54.0, 4.75000],
[4.87500, 52.0, 5.00000],
[5.06250, 52.0, 5.18750],
[5.31250, 54.0, 5.43750],
[5.43750, 52.0, 5.56250],
[5.62500, 35.0, 6.62500],
[5.62500, 54.0, 5.68750],
[5.81250, 54.0, 5.93750],
[6.00000, 50.0, 6.18750],
[6.25000, 47.0, 6.37500],
[6.50000, 47.0, 6.62500]
];
notes.sort((a, b) => a[0] - b[0]);
let noteIndex = 0;
const totalDuration = notes[notes.length - 1][2];
// --- Loop principal ---
loop(() => {
let currentTime = 0;
const minStep = 0.0625; // 1/16 de nota
while (currentTime <= totalDuration) {
// Disparar todas las notas que empiezan en este instante
while (noteIndex < notes.length && Math.abs(notes[noteIndex][0] - currentTime) < 1e-4) {
const [start, midi, end] = notes[noteIndex];
const duration = end - start;
// ✅ Aquí usamos nuestro 'square' personalizado
square.play(midi, {
duration: duration,
attack: 0.01,
release: 0.1,
amp: 0.7
});
noteIndex++;
}
sleep(minStep);
currentTime += minStep;
}
noteIndex = 0; // Reiniciar para repetir
}, { name: 'Take On Me - Square' });