Axel F - Beverly Hills Cop-v1

Axel F - Beverly Hills Cop

Log in to post a comment.

// Axel F - Beverly Hills Cop (versión DittyToy)
ditty.bpm = 45;

// --- Definir sintetizador: onda de sierra (más cercana al sonido original de Harold Faltermeyer)
const saw = synth.def((phase, env, tick, options) => {
  // Sierra: va de -1 a +1 linealmente
  const wave = 2 * (phase % 1) - 1;
  return wave * env.value;
});

// --- Tus notas originales (formato: [start, midi, end]) ---
const notes = [
  [0.00000, 53.0, 0.25000],
  [0.25000, 56.0, 0.43750],
  [0.43750, 53.0, 0.56250],
  [0.56250, 53.0, 0.62500],
  [0.62500, 58.0, 0.75000],
  [0.75000, 53.0, 0.87500],
  [0.87500, 51.0, 1.00000],
  [1.00000, 53.0, 1.25000],
  [1.25000, 60.0, 1.43750],
  [1.43750, 53.0, 1.56250],
  [1.56250, 53.0, 1.62500],
  [1.62500, 61.0, 1.75000],
  [1.75000, 60.0, 1.87500],
  [1.87500, 56.0, 2.00000],
  [2.00000, 53.0, 2.12500],
  [2.12500, 60.0, 2.25000],
  [2.25000, 65.0, 2.37500],
  [2.37500, 53.0, 2.43750],
  [2.43750, 51.0, 2.56250],
  [2.56250, 51.0, 2.62500],
  [2.62500, 48.0, 2.75000],
  [2.75000, 55.0, 2.87500],
  [2.87500, 53.0, 3.62500],
  [4.37500, 53.0, 4.62500],
  [4.62500, 56.0, 4.81250],
  [4.81250, 53.0, 4.93750],
  [4.93750, 53.0, 5.00000],
  [5.00000, 58.0, 5.12500],
  [5.12500, 53.0, 5.25000],
  [5.25000, 51.0, 5.37500],
  [5.37500, 53.0, 5.62500],
  [5.62500, 60.0, 5.81250],
  [5.81250, 53.0, 5.93750],
  [5.93750, 53.0, 6.00000],
  [6.00000, 61.0, 6.12500],
  [6.12500, 60.0, 6.25000],
  [6.25000, 56.0, 6.37500],
  [6.37500, 53.0, 6.50000],
  [6.50000, 60.0, 6.62500],
  [6.62500, 65.0, 6.75000],
  [6.75000, 53.0, 6.81250],
  [6.81250, 51.0, 6.93750],
  [6.93750, 51.0, 7.00000],
  [7.00000, 48.0, 7.12500],
  [7.12500, 55.0, 7.25000],
  [7.25000, 53.0, 8.00000],
  [8.00000, 29.0, 8.25000],
  [8.25000, 41.0, 8.43750],
  [8.43750, 27.0, 8.56250],
  [8.56250, 39.0, 8.62500],
  [8.62500, 24.0, 8.75000],
  [8.75000, 36.0, 8.87500],
  [8.87500, 27.0, 9.00000],
  [9.00000, 29.0, 9.25000],
  [9.25000, 41.0, 9.43750],
  [9.62500, 24.0, 9.68750],
  [9.68750, 36.0, 9.81250],
  [9.81250, 39.0, 9.93750],
  [9.93750, 41.0, 10.06250],
  [10.06250, 25.0, 10.31250],
  [10.31250, 37.0, 10.50000],
  [10.50000, 27.0, 10.62500],
  [10.62500, 39.0, 10.68750],
  [10.68750, 24.0, 10.81250],
  [10.81250, 36.0, 10.93750],
  [10.93750, 27.0, 11.06250],
  [11.06250, 29.0, 11.31250]
];

// Ordenar por tiempo de inicio
notes.sort((a, b) => a[0] - b[0]);

let noteIndex = 0;
const totalDuration = notes[notes.length - 1][2]; // Duración total

// --- Loop principal ---
loop(() => {
  let currentTime = 0;
  const minStep = 0.0625; // resolución de 1/16 nota

  while (currentTime <= totalDuration + 0.1) {
    // Reproducir todas las notas que comienzan en currentTime
    while (
      noteIndex < notes.length &&
      Math.abs(notes[noteIndex][0] - currentTime) < 1e-5
    ) {
      const [start, midi, end] = notes[noteIndex];
      const duration = end - start;

      // ✅ Reproducir con nuestro sintetizador "saw"
      saw.play(midi, {
        duration: duration,
        attack: 0.02,   // ataque rápido
        decay: 0.3,    // ligera caída
        sustain: 0.05,   // bajo sustain para sonido "pluck"
        release: 0.3,   // liberación corta
        amp: 0.8        // volumen
      });

      noteIndex++;
    }

    sleep(minStep);
    currentTime += minStep;
  }

  // Reiniciar para repetir la melodía
  noteIndex = 0;
}, { name: 'Axel F - Beverly Hills Cop' });