function compose(ctx) {
var tempo = 120;
var beatDuration = 60 / tempo;
var measureDuration = beatDuration * 4;
var totalDuration = 20;
var melodyNotes = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bassNotes = [130.81, 146.83, 164.81, 196, 220];
function playNote(freq, startTime, duration, volume, type) {
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, startTime);
gain.gain.setValueAtTime(0, startTime);
gain.gain.linearRampToValueAtTime(volume, startTime + 0.02);
gain.gain.linearRampToValueAtTime(0, startTime + duration);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(startTime);
osc.stop(startTime + duration);
}
var currentTime = 0;
// Intro (2 measures): Bass only
for (var i = 0; i < 2; i++) {
playNote(bassNotes[0], currentTime, measureDuration, 0.2, "sine");
currentTime += measureDuration;
}
// Theme (4 measures): Melody + Bass
var themeMelody = [
[261.63, 0.5], [329.63, 0.5], [392, 0.5], [440, 0.5], [392, 1.0],
[329.63, 0.5], [293.66, 0.5], [261.63, 1.0],
[261.63, 0.5], [329.63, 0.5], [392, 0.5], [440, 0.5], [523.25, 1.0],
[440, 0.5], [392, 0.5], [329.63, 1.0]
];
var themeBass = [130.81, 130.81, 146.83, 146.83, 164.81, 164.81, 130.81, 130.81];
var themeStart = currentTime;
for (var m = 0; m < 4; m++) {
var mStart = themeStart + (m * measureDuration);
// Bass pattern
playNote(bassNotes[m % 5], mStart, measureDuration, 0.2, "sine");
// Melody pattern (simplified logic for the loop)
var pattern = (m < 2) ? themeMelody : themeMelody;
var patternOffset = m * 4;
// This is a bit manual to ensure exact timing within 4 measures
}
// Re-implementing loop with precise timing to ensure 20s total
currentTime = 2 * measureDuration; // Start after intro
// Theme
var melodySequence = [
{f: 261.63, d: 0.5}, {f: 329.63, d: 0.5}, {f: 392, d: 0.5}, {f: 440, d: 0.5}, {f: 392, d: 1.0},
{f: 329.63, d: 0.5}, {f: 293.66, d: 0.5}, {f: 261.63, d: 1.0},
{f: 261.63, d: 0.5}, {f: 329.63, d: 0.5}, {f: 392, d: 0.5}, {f: 440, d: 0.5}, {f: 523.25, d: 1.0},
{f: 440, d: 0.5}, {f: 392, d: 0.5}, {f: 329.63, d: 1.0}
];
var melodyTime = currentTime;
for (var j = 0; j < melodySequence.length; j++) {
playNote(melodySequence[j].f, melodyTime, melodySequence[j].d, 0.3, "triangle");
melodyTime += melodySequence[j].d;
}
// Bass for Theme
for (var b = 0; b < 4; b++) {
playNote(bassNotes[b % 5], currentTime + (b * measureDuration), measureDuration, 0.2, "sine");
}
// Variation (2 measures): Melody variation
currentTime += 4 * measureDuration;
var varMelody = [
{f: 392, d: 0.5}, {f: 440, d: 0.5}, {f: 523.25, d: 0.5}, {f: 440, d: 0.5}, {f: 392, d: 1.0},
{f: 523.25, d: 0.5}, {f: 440, d: 0.5}, {f: 329.63, d: 1.0},
{f: 392, d: 0.5}, {f: 440, d: 0.5}, {f: 523.25, d: 0.5}, {f: 440, d: 0.5}, {f: 392, d: 1.0},
{f: 440, d: 0.5}, {f: 392, d: 0.5}, {f: 329.63, d: 1.0}
];
var varTime = currentTime;
for (var k = 0; k < varMelody.length; k++) {
playNote(varMelody[k].f, varTime, varMelody[k].d, 0.3, "triangle");
varTime += varMelody[k].d;
}
for (var vb = 0; vb < 2; vb++) {
playNote(bassNotes[(vb + 2) % 5], currentTime + (vb * measureDuration), measureDuration, 0.2, "sine");
}
// Outro (2 measures): Fade out
currentTime += 2 * measureDuration;
var outroTime = currentTime;
for (var o = 0; o < 4; o++) {
var noteF = melodyNotes[o % 6];
var vol = 0.3 * (1 - (o / 4));
playNote(noteF, outroTime, 1.0, vol, "triangle");
playNote(bassNotes[o % 5], outroTime, 1.0, 0.1, "sine");
outroTime += 1.0;
}
}
xaigrok-4-1-fast-non-reasoning
8.8 s
xaigrok-4-1-fast-non-reasoning
Tokens1 205
Code source2.3 KB
Temps8.8 s
function compose(ctx) {
var frequencies = {
melody: [261.63, 293.66, 329.63, 392, 440, 523.25],
bass: [130.81, 146.83, 164.81, 196, 220]
};
var beatDuration = 0.5;
var measureDuration = 2;
var totalDuration = 20;
function playNote(frequency, startTime, duration, volume, waveform, ctx) {
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.frequency.value = frequency;
osc.type = waveform;
osc.connect(gain);
gain.connect(ctx.destination);
var endTime = startTime + duration;
gain.gain.setValueAtTime(0, startTime);
gain.gain.linearRampToValueAtTime(volume, startTime + 0.02);
gain.gain.linearRampToValueAtTime(0, endTime);
osc.start(startTime);
osc.stop(endTime);
}
var time = 0;
// Intro: 2 mesures basse seule (C3 G3 A3 D3 pattern)
var introBass = [0, 2, 4, 1];
for (var i = 0; i < 8; i++) {
var noteIndex = introBass[i % 4];
playNote(frequencies.bass[noteIndex], time, beatDuration, 0.2, "sine", ctx);
time += beatDuration;
}
// Thème: 4 mesures mélodie + basse (motif: C E G A G E C, avec basse C G A D)
var themeMelody = [0, 2, 3, 4, 3, 2, 0, 5];
var themeBass = [0, 3, 4, 1];
for (var m = 0; m < 4; m++) {
for (var b = 0; b < 4; b++) {
playNote(frequencies.bass[themeBass[b]], time, beatDuration, 0.2, "sine", ctx);
playNote(frequencies.melody[themeMelody[b*2]], time, beatDuration * 0.8, 0.3, "triangle", ctx);
time += beatDuration;
}
}
// Variation: 2 mesures (variation: E G A C5 A G E C, basse même)
var variationMelody = [2, 3, 4, 5, 4, 3, 2, 0];
for (var m = 0; m < 2; m++) {
for (var b = 0; b < 4; b++) {
playNote(frequencies.bass[themeBass[b]], time, beatDuration, 0.2, "sine", ctx);
playNote(frequencies.melody[variationMelody[b*2]], time, beatDuration * 0.8, 0.3, "triangle", ctx);
time += beatDuration;
}
}
// Outro: 2 mesures fondu (répétition thème avec volume décroissant)
var outroVolumeMelody = 0.3;
var outroVolumeBass = 0.2;
for (var m = 0; m < 2; m++) {
for (var b = 0; b < 4; b++) {
playNote(frequencies.bass[themeBass[b]], time, beatDuration, outroVolumeBass, "sine", ctx);
playNote(frequencies.melody[themeMelody[b*2]], time, beatDuration * 0.8, outroVolumeMelody, "triangle", ctx);
outroVolumeMelody *= 0.7;
outroVolumeBass *= 0.7;
time += beatDuration;
}
}
}
function composeTone(transport) {
transport.bpm.value = 120;
var melody = new Tone.Synth({oscillator:{type:"triangle"},envelope:{attack:0.05,decay:0.1,sustain:0.3,release:0.3}}).toDestination();
var bass = new Tone.Synth({oscillator:{type:"sine"},envelope:{attack:0.1,decay:0.2,sustain:0.5,release:0.5}}).toDestination();
var perc = new Tone.MembraneSynth({volume:-10}).toDestination();
var melodyNotes = ["C4", "D4", "E4", "G4", "A4", "C5", "D5", "E5"];
var bassNotes = ["C2", "D2", "E2", "G2", "A2", "C3"];
var i;
for (i = 0; i < 10; i++) {
perc.triggerAttackRelease("C1", "8n", i * 2);
perc.triggerAttackRelease("C1", "8n", i * 2 + 1);
bass.triggerAttackRelease(bassNotes[i % 6], "2n", i * 2);
}
for (i = 0; i < 40; i++) {
var note = melodyNotes[Math.floor(Math.random() * melodyNotes.length)];
var time = i * 0.5;
if (i < 8) {
melody.triggerAttackRelease(note, "8n", time);
} else if (i < 24) {
melody.triggerAttackRelease(note, "4n", time);
} else if (i < 32) {
melody.triggerAttackRelease(note, "4n", time);
} else {
melody.triggerAttackRelease(note, "2n", time);
}
}
transport.start();
}
function composeTone(transport) {
var melody = new Tone.Synth({oscillator:{type:"triangle"},envelope:{attack:0.05,decay:0.1,sustain:0.3,release:0.3}}).toDestination();
var bass = new Tone.Synth({oscillator:{type:"sine"},envelope:{attack:0.1,decay:0.2,sustain:0.5,release:0.5}}).toDestination();
var perc = new Tone.MembraneSynth({volume:-10}).toDestination();
var time = 0;
var notes = ["C4", "D4", "E4", "G4", "A4", "C5", "D5", "E5"];
var bassNotes = ["C2", "D2", "E2", "G2", "A2", "C3"];
melody.triggerAttackRelease("C4", "4n", time);
time += "4n";
melody.triggerAttackRelease("E4", "4n", time);
time += "4n";
melody.triggerAttackRelease("G4", "4n", time);
time += "4n";
melody.triggerAttackRelease("C5", "8n", time);
time += "8n";
melody.triggerAttackRelease("C5", "8n", time);
time += "8n";
melody.triggerAttackRelease("A4", "8n", time);
time += "8n";
melody.triggerAttackRelease("A4", "8n", time);
time += "8n";
melody.triggerAttackRelease("G4", "8n", time);
time += "8n";
melody.triggerAttackRelease("G4", "8n", time);
time += "8n";
melody.triggerAttackRelease("E4", "8n", time);
time += "8n";
melody.triggerAttackRelease("E4", "8n", time);
time += "8n";
melody.triggerAttackRelease("C4", "8n", time);
time += "8n";
melody.triggerAttackRelease("C4", "8n", time);
time += "8n";
for (var i = 0; i < 8; i++) {
bass.triggerAttackRelease(bassNotes[i % bassNotes.length], "1m", time);
time += "1m";
if (i % 2 === 0) {
perc.triggerAttackRelease("C2", "8n", time);
time += "8n";
} else {
time += "8n";
}
}
transport.start();
}
mistralmistral-large-latest
17.2 s
mistralmistral-large-latest
Tokens1 496
Code source3.4 KB
Temps17.2 s
function composeTone(transport) {
var melodyNotes = [
["C4", "8n"], ["D4", "8n"], ["E4", "4n"], ["G4", "8n"], ["A4", "8n"], ["C5", "4n"],
["D5", "8n"], ["E5", "8n"], ["G4", "4n"], ["A4", "8n"], ["C5", "8n"], ["D5", "4n"],
["E5", "8n"], ["D5", "8n"], ["C5", "4n"], ["A4", "8n"], ["G4", "8n"], ["E4", "4n"],
["C4", "8n"], ["D4", "8n"], ["E4", "4n"], ["G4", "8n"], ["A4", "8n"], ["C5", "2n"],
["D5", "8n"], ["E5", "8n"], ["D5", "8n"], ["C5", "8n"], ["A4", "4n"], ["G4", "8n"],
["A4", "8n"], ["C5", "4n"], ["D5", "8n"], ["E5", "8n"], ["G4", "4n"], ["A4", "2n"],
["C4", "4n"], ["E4", "4n"], ["G4", "4n"], ["C5", "4n"], ["D5", "8n"], ["C5", "8n"],
["A4", "4n"], ["G4", "8n"], ["E4", "8n"], ["C4", "2n"]
];
var bassNotes = [
["C2", "1n"], ["C2", "1n"], ["G2", "1n"], ["G2", "1n"],
["A2", "1n"], ["A2", "1n"], ["F2", "1n"], ["F2", "1n"],
["C2", "1n"], ["G2", "1n"], ["A2", "1n"], ["C3", "1n"],
["C2", "1n"], ["G2", "1n"], ["C2", "2n"]
];
var kickTimes = [
0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38
];
transport.bpm.value = 120;
var melody = new Tone.Synth({oscillator:{type:"triangle"},envelope:{attack:0.05,decay:0.1,sustain:0.3,release:0.3}}).toDestination();
var bass = new Tone.Synth({oscillator:{type:"sine"},envelope:{attack:0.1,decay:0.2,sustain:0.5,release:0.5}}).toDestination();
var perc = new Tone.MembraneSynth({volume:-10}).toDestination();
var now = 0;
var measureDuration = 2.0;
var melodyIndex = 0;
var bassIndex = 0;
for (var i = 0; i < 10; i++) {
var measureStart = now + i * measureDuration;
if (i < 2) {
for (var j = 0; j < 6; j++) {
var note = melodyNotes[melodyIndex];
melody.triggerAttackRelease(note[0], note[1], measureStart + j * 0.5);
melodyIndex++;
}
bass.triggerAttackRelease(bassNotes[bassIndex][0], bassNotes[bassIndex][1], measureStart);
bassIndex++;
} else if (i < 6) {
for (var j = 0; j < 6; j++) {
var note = melodyNotes[melodyIndex];
melody.triggerAttackRelease(note[0], note[1], measureStart + j * 0.5);
melodyIndex++;
}
bass.triggerAttackRelease(bassNotes[bassIndex][0], bassNotes[bassIndex][1], measureStart);
bassIndex++;
} else if (i < 8) {
for (var j = 0; j < 6; j++) {
var note = melodyNotes[melodyIndex];
melody.triggerAttackRelease(note[0], note[1], measureStart + j * 0.5);
melodyIndex++;
}
bass.triggerAttackRelease(bassNotes[bassIndex][0], bassNotes[bassIndex][1], measureStart);
bassIndex++;
} else {
for (var j = 0; j < 4; j++) {
var note = melodyNotes[melodyIndex];
melody.triggerAttackRelease(note[0], note[1], measureStart + j * 1.0);
melodyIndex++;
}
bass.triggerAttackRelease(bassNotes[bassIndex][0], bassNotes[bassIndex][1], measureStart);
bassIndex++;
}
}
for (var k = 0; k < kickTimes.length; k++) {
if (kickTimes[k] % 4 === 0) {
perc.triggerAttackRelease("C2", "8n", kickTimes[k] * 0.5);
}
}
transport.start();
}
function composeTone(transport) {
var melody = new Tone.Synth({oscillator:{type:"triangle"},envelope:{attack:0.05,decay:0.1,sustain:0.3,release:0.3}}).toDestination();
var bass = new Tone.Synth({oscillator:{type:"sine"},envelope:{attack:0.1,decay:0.2,sustain:0.5,release:0.5}}).toDestination();
var perc = new Tone.MembraneSynth({volume:-10}).toDestination();
transport.bpm.value = 120;
var notes = ["C4", "D4", "E4", "G4", "A4", "C5", "D5", "E5"];
var bassNotes = ["C2", "D2", "E2", "G2", "A2", "C3"];
var now = Tone.now();
var measure = 60 / transport.bpm.value;
var totalDuration = 20;
var currentTime = now;
for (var i = 0; i < 2; i++) {
bass.triggerAttackRelease(bassNotes[0], "4n", currentTime);
currentTime += measure;
}
for (var i = 0; i < 4; i++) {
var melodyPattern = [notes[0], notes[2], notes[1], notes[0], notes[2], notes[4], notes[2], notes[0]];
for (var j = 0; j < melodyPattern.length; j++) {
melody.triggerAttackRelease(melodyPattern[j], "8n", currentTime + (j * 0.5 * measure));
}
bass.triggerAttackRelease(bassNotes[0], "4n", currentTime);
perc.triggerAttackRelease("C2", "8n", currentTime);
perc.triggerAttackRelease("C2", "8n", currentTime + measure * 0.5);
currentTime += measure;
}
for (var i = 0; i < 2; i++) {
var melodyPattern = [notes[4], notes[2], notes[1], notes[0], notes[2], notes[4], notes[0], notes[2]];
for (var j = 0; j < melodyPattern.length; j++) {
melody.triggerAttackRelease(melodyPattern[j], "8n", currentTime + (j * 0.5 * measure));
}
bass.triggerAttackRelease(bassNotes[2], "4n", currentTime);
perc.triggerAttackRelease("C2", "8n", currentTime);
perc.triggerAttackRelease("C2", "8n", currentTime + measure * 0.5);
currentTime += measure;
}
for (var i = 0; i < 2; i++) {
var melodyPattern = [notes[0], notes[2], notes[4], notes[2], notes[0], notes[1], notes[2], notes[0]];
for (var j = 0; j < melodyPattern.length; j++) {
melody.triggerAttackRelease(melodyPattern[j], "8n", currentTime + (j * 0.5 * measure));
}
bass.triggerAttackRelease(bassNotes[0], "4n", currentTime);
perc.triggerAttackRelease("C2", "8n", currentTime);
perc.triggerAttackRelease("C2", "8n", currentTime + measure * 0.5);
currentTime += measure;
}
transport.start();
}
mistralmistral-tiny-latest
3.6 s
mistralmistral-tiny-latest
Tokens954
Code source1.2 KB
Temps3.6 s
function composeTone(transport) {
var melody = new Tone.Synth({oscillator:{type:"triangle"},envelope:{attack:0.05,decay:0.1,sustain:0.3,release:0.3}}).toDestination();
var bass = new Tone.Synth({oscillator:{type:"sine"},envelope:{attack:0.1,decay:0.2,sustain:0.5,release:0.5}}).toDestination();
var perc = new Tone.MembraneSynth({volume:-10}).toDestination();
transport.bpm.value = 120;
var time = 0;
for (var i = 0; i < 20; i++) {
if (i % 4 === 0 || i % 4 === 3) {
perc.triggerAttackRelease("C2", "8n", time);
}
if (i < 8) {
if (i % 2 === 0) {
melody.triggerAttackRelease("C4", "8n", time);
} else {
melody.triggerAttackRelease("E4", "8n", time);
}
} else if (i < 12) {
if (i % 2 === 0) {
melody.triggerAttackRelease("G4", "8n", time);
} else {
melody.triggerAttackRelease("C5", "8n", time);
}
} else if (i < 16) {
if (i % 2 === 0) {
melody.triggerAttackRelease("A4", "8n", time);
} else {
melody.triggerAttackRelease("C5", "8n", time);
}
} else {
melody.triggerAttackRelease("E4", "8n", time);
}
if (i % 4 === 0) {
bass.triggerAttackRelease("C2", "4n", time);
}
time += 0.5;
}
transport.start();
}
openaigpt-4o-mini
8.3 s
openaigpt-4o-mini
Tokens1 042
Code source1.6 KB
Temps8.3 s
function composeTone(transport) {
transport.bpm.value = 120;
var melody = new Tone.Synth({oscillator:{type:"triangle"},envelope:{attack:0.05,decay:0.1,sustain:0.3,release:0.3}}).toDestination();
var bass = new Tone.Synth({oscillator:{type:"sine"},envelope:{attack:0.1,decay:0.2,sustain:0.5,release:0.5}}).toDestination();
var perc = new Tone.MembraneSynth({volume:-10}).toDestination();
var melodyNotes = ["C4","D4","E4","G4","A4","C5","D5","E5"];
var bassNotes = ["C2","D2","E2","G2","A2","C3"];
var time = 0;
for (var i = 0; i < 2; i++) {
melody.triggerAttackRelease(melodyNotes[Math.floor(Math.random() * melodyNotes.length)], 1, time);
bass.triggerAttackRelease(bassNotes[i], 4, time);
perc.triggerAttack(60, time);
time += 4;
}
for (var i = 0; i < 4; i++) {
melody.triggerAttackRelease(melodyNotes[Math.floor(Math.random() * melodyNotes.length)], 1, time);
bass.triggerAttackRelease(bassNotes[i % 6], 4, time);
perc.triggerAttack(60, time);
time += 4;
}
for (var i = 0; i < 2; i++) {
melody.triggerAttackRelease(melodyNotes[Math.floor(Math.random() * melodyNotes.length)], 1, time);
bass.triggerAttackRelease(bassNotes[1 + i], 4, time);
perc.triggerAttack(60, time);
time += 4;
}
for (var i = 0; i < 2; i++) {
melody.triggerAttackRelease(melodyNotes[Math.floor(Math.random() * melodyNotes.length)], 1, time);
bass.triggerAttackRelease(bassNotes[2], 4, time);
perc.triggerAttack(60, time);
time += 4;
}
transport.start();
}
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var freqs = [130.81, 196, 220, 261.63, 293.66, 329.63, 392, 440, 523.25];
var bassFreqs = [130.81, 196, 220];
var ctx = new OfflineAudioContext(1, 200 * 44100, 44100);
var currentTime = 0;
var melodyIndex = 0;
var bassIndex = 0;
var isLow = true;
for (var t = 0; t < 20; t += 0.5) {
var endTime = t + (rand() > 0.4 ? 0.5 : 0.25);
currentTime = t;
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.frequency.setValueAtTime(freqs[isLow ? melodyIndex % 4 : melodyIndex], currentTime);
osc.type = "triangle";
osc.connect(gain);
gain.gain.setValueAtTime(0, currentTime);
gain.gain.linearRampToValueAtTime(0.3, currentTime + 0.02);
gain.gain.linearRampToValueAtTime(0, endTime);
gain.connect(ctx.destination);
osc.start(currentTime);
osc.stop(endTime);
gain.gain.cancelScheduledValues(endTime);
gain.gain.linearRampToValueAtTime(0, endTime + 0.02);
if (t % 2 === 0) {
currentTime = t;
var oscBass = ctx.createOscillator();
var gainBass = ctx.createGain();
oscBass.frequency.setValueAtTime(bassFreqs[bassIndex], currentTime);
oscBass.type = "sine";
oscBass.connect(gainBass);
gainBass.gain.setValueAtTime(0, currentTime);
gainBass.gain.linearRampToValueAtTime(0.15, currentTime + 0.02);
gainBass.gain.linearRampToValueAtTime(0, 2);
gainBass.connect(ctx.destination);
oscBass.start(currentTime);
oscBass.stop(currentTime + 2);
gainBass.gain.cancelScheduledValues(currentTime + 2);
gainBass.gain.linearRampToValueAtTime(0, currentTime + 2.02);
bassIndex = (bassIndex + 1) % 3;
}
if (isLow && t > 10) {
isLow = false;
}
switch (Math.floor(rand() * 100)) {
case 60:
melodyIndex = (melodyIndex + 1 + 4) % 4;
break;
case 25:
melodyIndex = (melodyIndex + 2 + 4) % 4;
break;
case 15:
melodyIndex = (melodyIndex + 3 + 4) % 4;
break;
default:
melodyIndex = (melodyIndex - 1 + 4) % 4;
}
}
return ctx.startRendering();
}
mistralmistral-large-latest
12.4 s
mistralmistral-large-latest
Tokens1 343
Code source2.6 KB
Temps12.4 s
function compose(ctx) {
var sampleRate = ctx.sampleRate;
var duration = 20;
var tempo = 120;
var beatDuration = 60 / tempo;
var seed = 42;
var pentatonic = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bassNotes = [130.81, 196, 220];
var bassIndex = 0;
var melodyIndex = 0;
var t = 0;
var endTime = 0;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
function getNextMelodyIndex(current) {
var r = rand();
var next;
if (r < 0.6) {
next = current + (rand() > 0.5 ? 1 : -1);
} else if (r < 0.85) {
next = current + (rand() > 0.5 ? 2 : -2);
} else {
next = current + (rand() > 0.5 ? 3 : -3);
}
if (next < 0) next = 0;
if (next >= pentatonic.length) next = pentatonic.length - 1;
return next;
}
while (t < duration) {
var noteDuration;
if (rand() > 0.4) {
noteDuration = beatDuration;
} else {
noteDuration = beatDuration * 0.5;
}
if (t < 10) {
melodyIndex = getNextMelodyIndex(Math.floor(melodyIndex / 2) * 2);
} else {
melodyIndex = getNextMelodyIndex(melodyIndex);
}
var freq = pentatonic[melodyIndex];
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.type = "triangle";
osc.frequency.value = freq;
gain.gain.value = 0;
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(t);
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(0.3, t + 0.02);
gain.gain.linearRampToValueAtTime(0, t + noteDuration);
osc.stop(t + noteDuration);
if (Math.floor(t / (beatDuration * 4)) % 2 === 0 && Math.abs(t - endTime) < 0.01) {
bassIndex = (bassIndex + 1) % bassNotes.length;
endTime = t + beatDuration * 4;
}
var bassFreq = bassNotes[bassIndex];
var bassOsc = ctx.createOscillator();
var bassGain = ctx.createGain();
bassOsc.type = "sine";
bassOsc.frequency.value = bassFreq;
bassGain.gain.value = 0;
bassOsc.connect(bassGain);
bassGain.connect(ctx.destination);
bassOsc.start(t);
bassGain.gain.setValueAtTime(0, t);
bassGain.gain.linearRampToValueAtTime(0.15, t + 0.02);
bassGain.gain.linearRampToValueAtTime(0.15, t + noteDuration - 0.02);
bassGain.gain.linearRampToValueAtTime(0, t + noteDuration);
bassOsc.stop(t + noteDuration);
t += noteDuration;
}
}
mistralmistral-medium-latest
7.8 s
mistralmistral-medium-latest
Tokens1 335
Code source2.6 KB
Temps7.8 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var pentatonic = [261.63, 293.66, 329.63, 392.00, 440.00, 523.25];
var bassNotes = [130.81, 196.00, 220.00];
var tempo = 120;
var beatDuration = 60.0 / tempo;
var measureDuration = 4 * beatDuration;
var totalDuration = 20.0;
var currentMelodyIndex = Math.floor(rand() * pentatonic.length);
var currentBassIndex = 0;
function getNextMelodyIndex(currentIndex, time) {
var useFullRange = time >= 10.0;
var maxIndex = useFullRange ? pentatonic.length - 1 : 3;
var r = rand();
var step;
if (r < 0.60) {
step = Math.floor(rand() * 2) * 2 - 1;
} else if (r < 0.85) {
step = Math.floor(rand() * 2) * 4 - 2;
} else {
step = Math.floor(rand() * 2) * 6 - 3;
}
var newIndex = currentIndex + step;
newIndex = Math.max(0, Math.min(maxIndex, newIndex));
return newIndex;
}
function createNote(ctx, freq, time, duration, type, volume) {
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, time);
gain.gain.setValueAtTime(0, time);
gain.gain.linearRampToValueAtTime(volume, time + 0.02);
gain.gain.linearRampToValueAtTime(0, time + duration - 0.05);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(time);
osc.stop(time + duration);
return { osc: osc, gain: gain };
}
function createBassDrone(ctx, freq, startTime, duration) {
return createNote(ctx, freq, startTime, duration, "sine", 0.15);
}
function createMelodyNote(ctx, freq, startTime, duration) {
return createNote(ctx, freq, startTime, duration, "triangle", 0.3);
}
var currentTime = 0.0;
var bassChangeTime = 0.0;
while (currentTime < totalDuration) {
if (currentTime >= bassChangeTime) {
currentBassIndex = (currentBassIndex + 1) % bassNotes.length;
bassChangeTime += 2 * measureDuration;
createBassDrone(ctx, bassNotes[currentBassIndex], currentTime, 2 * measureDuration);
}
var noteDuration = rand() > 0.4 ? beatDuration : beatDuration / 2;
var melodyFreq = pentatonic[currentMelodyIndex];
createMelodyNote(ctx, melodyFreq, currentTime, noteDuration);
currentMelodyIndex = getNextMelodyIndex(currentMelodyIndex, currentTime);
currentTime += noteDuration;
}
}
mistralmistral-small-latest
5.2 s
mistralmistral-small-latest
Tokens1 341
Code source2.6 KB
Temps5.2 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var pentatonic = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bassNotes = [130.81, 196, 220];
var tempo = 120;
var beatDuration = 60 / tempo;
var totalDuration = 20;
var currentTime = 0;
var currentIndex = 0;
var bassFundamentalIndex = 0;
var bassFundamental = bassNotes[bassFundamentalIndex];
var melodyGain = ctx.createGain();
melodyGain.gain.value = 0;
melodyGain.connect(ctx.destination);
var bassGain = ctx.createGain();
bassGain.gain.value = 0;
bassGain.connect(ctx.destination);
function scheduleMelody() {
var startTime = currentTime;
var endTime = startTime + beatDuration;
if (rand() > 0.4) endTime = startTime + beatDuration / 2;
var useFullRange = currentTime >= 10;
var rangeStart = useFullRange ? 0 : 0;
var rangeEnd = useFullRange ? pentatonic.length - 1 : 3;
var step = 0;
if (rand() < 0.6) step = 1;
else if (rand() < 0.85) step = 2;
else step = 3;
if (rand() < 0.5) step = -step;
var newIndex = currentIndex + step;
if (newIndex < rangeStart) newIndex = rangeStart;
if (newIndex > rangeEnd) newIndex = rangeEnd;
currentIndex = newIndex;
var noteFreq = pentatonic[currentIndex];
var osc = ctx.createOscillator();
osc.type = "triangle";
osc.frequency.value = noteFreq;
osc.connect(melodyGain);
var gain = ctx.createGain();
gain.gain.setValueAtTime(0, currentTime);
gain.gain.linearRampToValueAtTime(0.3, currentTime + 0.02);
gain.gain.linearRampToValueAtTime(0, endTime);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(currentTime);
osc.stop(endTime);
currentTime = endTime;
if (currentTime < totalDuration) scheduleMelody();
}
function scheduleBass() {
var measureDuration = 4 * beatDuration;
var bassChangeTime = Math.floor(currentTime / measureDuration) * measureDuration;
if (bassChangeTime >= currentTime && bassChangeTime < currentTime + measureDuration) {
bassFundamentalIndex = Math.floor(rand() * bassNotes.length);
bassFundamental = bassNotes[bassFundamentalIndex];
}
var bassOsc = ctx.createOscillator();
bassOsc.type = "sine";
bassOsc.frequency.value = bassFundamental;
bassOsc.connect(bassGain);
var bassGainNode = ctx.createGain();
bassGainNode.gain.setValueAtTime(0, currentTime);
bassGainNode.gain.linearRampToValueAtTime(0.15, currentTime + 0.02);
bassGainNode.gain.linearRampToValueAtTime(0, currentTime + beatDuration);
bassOsc.connect(bassGainNode);
bassGainNode.connect(ctx.destination);
bassOsc.start(currentTime);
bassOsc.stop(currentTime + beatDuration);
if (currentTime + beatDuration < totalDuration) {
currentTime += beatDuration;
scheduleBass();
} else {
scheduleMelody();
}
}
scheduleBass();
}
mistralmistral-tiny-latest
5.3 s
mistralmistral-tiny-latest
Tokens1 209
Code source2.1 KB
Temps5.3 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var notes = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bassNotes = [130.81, 196, 220];
var currentNoteIndex = 0;
var currentBassIndex = 0;
var time = 0;
var melodyOsc = ctx.createOscillator();
var bassOsc = ctx.createOscillator();
var melodyGain = ctx.createGain();
var bassGain = ctx.createGain();
melodyOsc.connect(melodyGain);
bassOsc.connect(bassGain);
melodyGain.connect(ctx.destination);
bassGain.connect(ctx.destination);
melodyOsc.type = "triangle";
bassOsc.type = "sine";
melodyGain.gain.value = 0.3;
bassGain.gain.value = 0.15;
function playNote(note, duration, vol) {
var gain = ctx.createGain();
gain.connect(ctx.destination);
var osc = ctx.createOscillator();
osc.connect(gain);
osc.frequency.setValueAtTime(note, time);
gain.gain.setValueAtTime(0, time);
gain.gain.linearRampToValueAtTime(vol, time + 0.02);
gain.gain.linearRampToValueAtTime(0, time + duration);
osc.start(time);
osc.stop(time + duration);
}
function nextNote() {
var index = currentNoteIndex;
if (rand() < 0.6) {
index += Math.floor(rand() * 2) - 1;
} else if (rand() < 0.85) {
index += Math.floor(rand() * 3) - 1;
}
index = (index + notes.length) % notes.length;
return notes[index];
}
function nextBass() {
var index = currentBassIndex;
index = (index + bassNotes.length) % bassNotes.length;
return bassNotes[index];
}
function generateNote() {
var note = nextNote();
var duration = rand() > 0.4 ? 0.5 : 0.25;
playNote(note, duration, melodyGain.gain.value);
time += duration;
if (time > 10 && time < 18) {
currentNoteIndex = Math.floor(rand() * notes.length);
}
}
function generateBass() {
var note = nextBass();
playNote(note, 2, bassGain.gain.value);
time += 2;
currentBassIndex = Math.floor(rand() * bassNotes.length);
}
while (time < 20) {
generateNote();
if (time % 2 === 0) {
generateBass();
}
}
}
openaigpt-4o-mini
14.7 s
openaigpt-4o-mini
Tokens1 194
Code source2.0 KB
Temps14.7 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var notes = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bassNotes = [130.81, 196, 220];
var melodyVolume = 0.3;
var bassVolume = 0.15;
var currentIndex = 0;
var isBass = true;
var measureIndex = 0;
for (var t = 0; t < 20; t += 0.5) {
if (t < 10) {
currentIndex = Math.min(Math.max(currentIndex + (rand() < 0.6 ? (rand() < 0.5 ? 1 : -1) : (rand() < 0.75 ? 2 : 3)), 0), 4);
} else {
currentIndex = Math.min(Math.max(currentIndex + (rand() < 0.6 ? (rand() < 0.5 ? 1 : -1) : (rand() < 0.75 ? 2 : 3)), 0), 5);
}
if (measureIndex % 2 === 0) {
var bassIndex = Math.floor(measureIndex / 2) % 3;
var bassNote = bassNotes[bassIndex];
var bassOscillator = ctx.createOscillator();
var bassGain = ctx.createGain();
bassOscillator.type = 'sine';
bassOscillator.frequency.setValueAtTime(bassNote, t);
bassGain.gain.setValueAtTime(0, t);
bassGain.gain.linearRampToValueAtTime(bassVolume, t + 0.02);
bassGain.gain.linearRampToValueAtTime(0, t + 2);
bassOscillator.connect(bassGain);
bassGain.connect(ctx.destination);
bassOscillator.start(t);
bassOscillator.stop(t + 2);
}
var note = notes[currentIndex];
var oscillator = ctx.createOscillator();
var gain = ctx.createGain();
oscillator.type = 'triangle';
oscillator.frequency.setValueAtTime(note, t);
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(melodyVolume, t + 0.02);
gain.gain.linearRampToValueAtTime(0, t + (rand() > 0.4 ? 0.5 : 0.25));
oscillator.connect(gain);
gain.connect(ctx.destination);
oscillator.start(t);
oscillator.stop(t + (rand() > 0.4 ? 0.5 : 0.25));
measureIndex++;
}
}
openaigpt-5.4
8.7 s
openaigpt-5.4
Tokens1 142
Code source1.8 KB
Temps8.7 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var scale = [261.63, 293.66, 329.63, 392.00, 440.00, 523.25];
var bassRoots = [130.81, 196.00, 220.00];
var tempo = 120;
var beat = 60 / tempo;
var measure = beat * 4;
var total = 20.00;
function clamp(v, a, b) {
if (v < a) {
return a;
}
if (v > b) {
return b;
}
return v;
}
function makeNote(type, freq, t, dur, vol) {
var osc = ctx.createOscillator();
var gain = ctx.createGain();
var end = t + dur;
if (end > total) {
end = total;
}
osc.type = type;
osc.frequency.setValueAtTime(freq, t);
gain.gain.setValueAtTime(0.00, t);
gain.gain.linearRampToValueAtTime(vol, t + 0.02);
gain.gain.linearRampToValueAtTime(0.00, end);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(t);
osc.stop(end);
}
var t = 0.00;
var index = 0;
while (t < total) {
var maxIndex = t < 10.00 ? 3 : scale.length - 1;
if (index > maxIndex) {
index = maxIndex;
}
var r = rand();
var step = 1;
if (r < 0.60) {
step = 1;
} else if (r < 0.85) {
step = 2;
} else {
step = 3;
}
var dir = rand() < 0.5 ? -1 : 1;
index = clamp(index + dir * step, 0, maxIndex);
var dur = rand() > 0.4 ? 0.50 : 0.25;
if (t + dur > total) {
dur = total - t;
}
makeNote("triangle", scale[index], t, dur, 0.30);
t += dur;
}
var bassTime = 0.00;
var segment = measure * 2.00;
while (bassTime < total) {
var root = bassRoots[Math.floor(rand() * bassRoots.length)];
var bassDur = segment;
if (bassTime + bassDur > total) {
bassDur = total - bassTime;
}
makeNote("sine", root, bassTime, bassDur, 0.15);
bassTime += segment;
}
}
openaigpt-5.4-mini
7.0 s
openaigpt-5.4-mini
Tokens1 306
Code source2.5 KB
Temps7.0 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var scale = [
261.63,
293.66,
329.63,
392.0,
440.0,
523.25
];
var bassNotes = [
130.81,
196.0,
220.0
];
var tempoBeat = 0.5;
var totalTime = 20.0;
var melodyOsc = ctx.createOscillator();
melodyOsc.type = "triangle";
var melodyGain = ctx.createGain();
melodyGain.gain.setValueAtTime(0.0, 0.0);
melodyGain.gain.setValueAtTime(0.0, 0.0);
melodyOsc.connect(melodyGain);
melodyGain.connect(ctx.destination);
var bassOsc = ctx.createOscillator();
bassOsc.type = "sine";
var bassGain = ctx.createGain();
bassGain.gain.setValueAtTime(0.0, 0.0);
bassGain.gain.setValueAtTime(0.0, 0.0);
bassOsc.connect(bassGain);
bassGain.connect(ctx.destination);
var currentIndex = 0;
var t = 0.0;
while (t < totalTime) {
var duration = rand() > 0.4 ? 0.25 : 0.5;
if (t + duration > totalTime) {
duration = totalTime - t;
}
var moveRand = rand();
var step = 0;
if (moveRand < 0.60) {
step = rand() > 0.5 ? 1 : -1;
} else if (moveRand < 0.85) {
step = rand() > 0.5 ? 2 : -2;
} else {
step = rand() > 0.5 ? 3 : -3;
}
if (t < 10.0) {
if (currentIndex < 0) currentIndex = 0;
if (currentIndex > 3) currentIndex = 3;
currentIndex += step;
if (currentIndex < 0) currentIndex = 0;
if (currentIndex > 3) currentIndex = 3;
} else {
currentIndex += step;
if (currentIndex < 0) currentIndex = 0;
if (currentIndex > scale.length - 1) currentIndex = scale.length - 1;
}
var freq = scale[currentIndex];
melodyOsc.frequency.setValueAtTime(freq, t);
melodyGain.gain.setValueAtTime(0.0, t);
melodyGain.gain.linearRampToValueAtTime(0.3, t + 0.02);
melodyGain.gain.linearRampToValueAtTime(0.0, t + duration);
t += duration;
}
var bt = 0.0;
var bassIdx = 0;
while (bt < totalTime) {
bassIdx = Math.floor(rand() * 3);
var bassFreq = bassNotes[bassIdx];
var bassDur = 4.0;
if (bt + bassDur > totalTime) {
bassDur = totalTime - bt;
}
bassOsc.frequency.setValueAtTime(bassFreq, bt);
bassGain.gain.setValueAtTime(0.0, bt);
bassGain.gain.linearRampToValueAtTime(0.15, bt + 0.02);
bassGain.gain.linearRampToValueAtTime(0.0, bt + bassDur);
bt += 4.0;
}
melodyOsc.start(0.0);
melodyOsc.stop(totalTime);
bassOsc.start(0.0);
bassOsc.stop(totalTime);
}
openaigpt-5.4-nano
8.8 s
openaigpt-5.4-nano
Tokens1 326
Code source2.6 KB
Temps8.8 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var pentatonic = [261.63, 293.66, 329.63, 392, 440, 523.25];
var lowBass = [130.81, 196, 220]; // C3, G3, A3
var tempoBPM = 120;
var beatDur = 60 / tempoBPM; // 0.5 s
var quarterMeasure = 2; // measure duration = 2 s (given)
var measureDur = 2;
var totalDur = 20;
var t = 0;
var melodyIndex = 2;
var bassIndex = Math.floor(rand() * lowBass.length);
var melodyOscTypes = { wave: "triangle", vol: 0.3 };
var bassOscTypes = { wave: "sine", vol: 0.15 };
function chooseNextIndex(curIndex, maxIndex, minIndex) {
var r = rand();
var nextIndex = curIndex;
if (r < 0.6) {
var dir = rand() < 0.5 ? -1 : 1;
nextIndex = curIndex + dir;
} else if (r < 0.85) {
var dir2 = rand() < 0.5 ? -1 : 1;
nextIndex = curIndex + dir2 * 2;
} else {
var dir3 = rand() < 0.5 ? -1 : 1;
nextIndex = curIndex + dir3 * 3;
}
if (nextIndex < minIndex) nextIndex = minIndex;
if (nextIndex > maxIndex) nextIndex = maxIndex;
return nextIndex;
}
function scheduleNote(freq, oscType, vol, startTime, dur) {
var osc = ctx.createOscillator();
osc.type = oscType;
osc.frequency.value = freq;
var gain = ctx.createGain();
gain.gain.setValueAtTime(0, startTime);
gain.gain.linearRampToValueAtTime(vol, startTime + 0.02);
gain.gain.linearRampToValueAtTime(0, startTime + dur);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(startTime);
osc.stop(startTime + dur + 0.03);
}
function currentMelodyRange(startTime) {
if (startTime < 10) {
return { min: 0, max: 3 };
}
return { min: 0, max: pentatonic.length - 1 };
}
while (t < totalDur - 1e-9) {
var currentMeasure = Math.floor(t / measureDur);
if ((t - currentMeasure * measureDur) < 1e-9) {
bassIndex = Math.floor(rand() * lowBass.length);
}
var bassFreq = lowBass[bassIndex];
var bassDur = beatDur; // update with each note grid; fundamental changes every 2 measures
var melRange = currentMelodyRange(t);
var rDur = rand();
var noteDur = (rDur > 0.4) ? beatDur : beatDur / 2; // 0.5 or 0.25
var safeMelDur = noteDur;
var melodyFreq = pentatonic[melodyIndex];
scheduleNote(bassFreq, bassOscTypes.wave, bassOscTypes.vol, t, bassDur);
scheduleNote(melodyFreq, melodyOscTypes.wave, melodyOscTypes.vol, t, safeMelDur);
melodyIndex = chooseNextIndex(melodyIndex, melRange.max, melRange.min);
t += noteDur;
}
}
openaigpt-5.4-pro
348.6 s
openaigpt-5.4-pro
Tokens1 227
Code source2.2 KB
Temps348.6 s
function compose(ctx) {
var seed = 42;
function rand() { seed = (seed * 16807) % 2147483647; return seed / 2147483647; }
var scale = [261.63, 293.66, 329.63, 392.00, 440.00, 523.25];
var bassRoots = [130.81, 196.00, 220.00];
var total = 20.00;
var attack = 0.02;
function clamp(v, min, max) {
if (v < min) { return min; }
if (v > max) { return max; }
return v;
}
function nextIndex(current, maxIndex) {
var r = rand();
var step;
var dir;
if (r < 0.60) {
step = 1;
} else if (r < 0.85) {
step = 2;
} else {
step = 3;
}
dir = rand() < 0.5 ? -1 : 1;
return clamp(current + dir * step, 0, maxIndex);
}
function schedule(freq, t, dur, type, vol) {
var end = t + dur;
var osc;
var gain;
if (dur <= 0.00 || t >= total) {
return;
}
if (end > total) {
end = total;
}
osc = ctx.createOscillator();
gain = ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, t);
gain.gain.setValueAtTime(0.00, t);
gain.gain.linearRampToValueAtTime(vol, t + 0.02);
gain.gain.linearRampToValueAtTime(0.00, end);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(t);
osc.stop(end);
}
var bassTime = 0.00;
var bassIndex = 0;
var choices;
var i;
while (bassTime < total) {
if (bassTime > 0.00) {
choices = [];
for (i = 0; i < bassRoots.length; i++) {
if (i !== bassIndex) {
choices.push(i);
}
}
bassIndex = choices[Math.floor(rand() * choices.length)];
}
schedule(bassRoots[bassIndex], bassTime, Math.min(4.00, total - bassTime), "sine", 0.15);
bassTime += 4.00;
}
var t = 0.00;
var index = 1;
var maxIndex;
var dur;
while (t < total) {
maxIndex = t < 10.00 ? 3 : 5;
index = clamp(index, 0, maxIndex);
dur = rand() > 0.4 ? 0.50 : 0.25;
if (t < 10.00 && t + dur > 10.00) {
dur = 10.00 - t;
}
if (t + dur > total) {
dur = total - t;
}
schedule(scale[index], t, dur, "triangle", 0.30);
t += dur;
if (t < total) {
maxIndex = t < 10.00 ? 3 : 5;
index = nextIndex(index, maxIndex);
}
}
}
openaigpt-5.5
14.2 s
openaigpt-5.5
Tokens1 119
Code source1.7 KB
Temps14.2 s
function compose(ctx) {
var seed = 42;
function rand() { seed = (seed * 16807) % 2147483647; return seed / 2147483647; }
var scale = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bass = [130.81, 196, 220];
var total = 20;
var t = 0;
var currentIndex = 0;
function playNote(freq, start, end, type, vol) {
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, start);
gain.gain.setValueAtTime(0, start);
gain.gain.linearRampToValueAtTime(vol, start + 0.02);
gain.gain.linearRampToValueAtTime(0, end);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(start);
osc.stop(end);
}
var bt = 0;
var bassIndex = 0;
while (bt < total) {
bassIndex = Math.floor(rand() * bass.length);
playNote(bass[bassIndex], bt, Math.min(bt + 4, total), "sine", 0.15);
bt += 4;
}
while (t < total) {
var maxIndex = t < 10 ? 3 : scale.length - 1;
if (currentIndex > maxIndex) {
currentIndex = maxIndex;
}
var r = rand();
var step = 1;
if (r < 0.6) {
step = 1;
} else if (r < 0.85) {
step = 2;
} else {
step = 3;
}
if (rand() < 0.5) {
step = -step;
}
currentIndex += step;
if (currentIndex < 0) {
currentIndex = 0;
}
if (currentIndex > maxIndex) {
currentIndex = maxIndex;
}
var dur = rand() > 0.4 ? 0.5 : 0.25;
var end = Math.min(t + dur, total);
playNote(scale[currentIndex], t, end, "triangle", 0.3);
t = end;
}
}
openaigpt-5.5-pro
132.1 s
openaigpt-5.5-pro
Tokens1 255
Code source2.3 KB
Temps132.1 s
function compose(ctx) {
var seed = 42;
function rand() { seed = (seed * 16807) % 2147483647; return seed / 2147483647; }
var scale = [261.63, 293.66, 329.63, 392, 440, 523.25];
var basses = [130.81, 196, 220];
var total = 20;
var currentIndex = 0;
function clamp(value, min, max) {
if (value < min) {
return min;
}
if (value > max) {
return max;
}
return value;
}
function play(freq, t, end, type, vol) {
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, t);
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(vol, t + 0.02);
gain.gain.linearRampToValueAtTime(0, end);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(t);
osc.stop(end);
}
var bassTime;
var previousBass = -1;
for (bassTime = 0; bassTime < total; bassTime += 4) {
var bassEnd = bassTime + 4;
var bassIndex = Math.floor(rand() * basses.length);
if (bassIndex === previousBass) {
bassIndex = (bassIndex + 1) % basses.length;
}
if (bassEnd > total) {
bassEnd = total;
}
previousBass = bassIndex;
play(basses[bassIndex], bassTime, bassEnd, "sine", 0.15);
}
var t = 0;
while (t < total) {
var maxIndex = t < 10 ? 3 : scale.length - 1;
var boundary = t < 10 ? 10 : total;
var moveRand = rand();
var stepSize;
var direction;
var dur;
var end;
if (currentIndex > maxIndex) {
currentIndex = maxIndex;
}
if (moveRand < 0.6) {
stepSize = 1;
} else if (moveRand < 0.85) {
stepSize = 2;
} else {
stepSize = 3;
}
direction = rand() < 0.5 ? -1 : 1;
currentIndex = clamp(currentIndex + direction * stepSize, 0, maxIndex);
dur = rand() > 0.4 ? 0.5 : 0.25;
end = t + dur;
if (end > boundary) {
end = boundary;
}
if (end > total) {
end = total;
}
play(scale[currentIndex], t, end, "triangle", 0.3);
t = end;
}
}
productiviamatania-latest
6.1 s
productiviamatania-latest
Tokens1 164
Code source1.9 KB
Temps6.1 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var melodyScale = [261.63, 293.66, 329.63, 392.00, 440.00, 523.25];
var bassScale = [130.81, 196.00, 220.00];
var tempo = 120;
var beatDuration = 0.5;
var totalDuration = 20.0;
var currentMelodyIndex = 0;
var currentTime = 0.0;
function playNote(freq, vol, startTime, duration, type) {
var osc = ctx.createOscillator();
var gain = ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, startTime);
gain.gain.setValueAtTime(0.0, startTime);
gain.gain.linearRampToValueAtTime(vol, startTime + 0.02);
gain.gain.linearRampToValueAtTime(0.0, startTime + duration);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(startTime);
osc.stop(startTime + duration);
}
while (currentTime < totalDuration) {
var isBassNote = rand() > 0.4;
var noteDuration = isBassNote ? 0.5 : 0.25;
if (currentTime + noteDuration > totalDuration) {
break;
}
var r = rand();
var movement = 0;
if (r < 0.60) {
movement = rand() > 0.5 ? 1 : -1;
} else if (r < 0.85) {
movement = rand() > 0.5 ? 2 : -2;
} else {
movement = rand() > 0.5 ? 3 : -3;
}
currentMelodyIndex += movement;
if (currentMelodyIndex < 0) currentMelodyIndex = 0;
if (currentMelodyIndex >= melodyScale.length) currentMelodyIndex = melodyScale.length - 1;
var melodyFreq = melodyScale[currentMelodyIndex];
if (currentTime < 10.0) {
if (currentMelodyIndex > 3) {
melodyFreq = melodyScale[currentMelodyIndex % 4];
}
}
playNote(melodyFreq, 0.3, currentTime, noteDuration, "triangle");
var measureIndex = Math.floor(currentTime / 2.0);
var bassFreq = bassScale[measureIndex % 3];
playNote(bassFreq, 0.15, currentTime, 2.0, "sine");
currentTime += noteDuration;
}
}
xaigrok-4-1-fast-non-reasoning
10.3 s
xaigrok-4-1-fast-non-reasoning
Tokens1 086
Code source1.6 KB
Temps10.3 s
function compose(ctx) {
var sampleRate = ctx.sampleRate;
var frequencies = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bassFreqs = [130.81, 196, 220];
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var melodyIndex = 0;
var bassIndex = 0;
var time = 0;
var duration = 20;
while (time < duration) {
var isHighMelody = time > 10;
var maxMelodyIndex = isHighMelody ? 5 : 3;
if (rand() > 0.4) {
var noteDuration = 0.25;
} else {
var noteDuration = 0.5;
}
if (time > 10 || rand() > 0.5) {
var r = rand();
if (r < 0.6) {
melodyIndex += (rand() > 0.5 ? 1 : -1);
} else if (r < 0.85) {
melodyIndex += (rand() > 0.5 ? 2 : -2);
} else {
melodyIndex += (rand() > 0.5 ? 3 : -3);
}
melodyIndex = Math.max(0, Math.min(maxMelodyIndex, melodyIndex));
var osc = ctx.createOscillator();
osc.type = 'triangle';
osc.frequency.value = frequencies[melodyIndex];
var gain = ctx.createGain();
gain.gain.setValueAtTime(0, time);
gain.gain.linearRampToValueAtTime(0.3, time + 0.02);
gain.gain.linearRampToValueAtTime(0, time + noteDuration);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(time);
osc.stop(time + noteDuration);
}
if (time % 4 < 0.01) {
bassIndex = Math.floor(rand() * 3);
}
var bassOsc = ctx.createOscillator();
bassOsc.type = 'sine';
bassOsc.frequency.value = bassFreqs[bassIndex];
var bassGain = ctx.createGain();
bassGain.gain.setValueAtTime(0, time);
bassGain.gain.linearRampToValueAtTime(0.15, time + 0.02);
bassGain.gain.linearRampToValueAtTime(0, time + 2);
bassOsc.connect(bassGain);
bassGain.connect(ctx.destination);
bassOsc.start(time);
bassOsc.stop(time + 2);
time += noteDuration;
}
}
xaigrok-4-1-fast-reasoning
64.0 s
xaigrok-4-1-fast-reasoning
Tokens1 145
Code source1.8 KB
Temps64.0 s
function compose(ctx) {
var seed = 42;
function rand() {
seed = (seed * 16807) % 2147483647;
return seed / 2147483647;
}
var scale = [261.63, 293.66, 329.63, 392, 440, 523.25];
var bassNotes = [130.81, 196, 220];
var melodyVol = 0.3;
var bassVol = 0.15;
var bassInterval = 4;
var bassT = 0;
for (bassT = 0; bassT < 20; bassT += bassInterval) {
var endT = Math.min(bassT + bassInterval, 20);
var bassFreq = bassNotes[Math.floor(rand() * 3)];
var bassOsc = ctx.createOscillator();
bassOsc.type = 'sine';
bassOsc.frequency.value = bassFreq;
var bassGain = ctx.createGain();
bassGain.gain.setValueAtTime(0, bassT);
bassGain.gain.linearRampToValueAtTime(bassVol, bassT + 0.02);
bassGain.gain.linearRampToValueAtTime(0, endT);
bassOsc.connect(bassGain);
bassGain.connect(ctx.destination);
bassOsc.start(bassT);
bassOsc.stop(endT);
}
var t = 0;
var currentIndex;
while (t < 20) {
var maxIndex = (t >= 10) ? 5 : 3;
if (t === 0) {
currentIndex = Math.floor(rand() * (maxIndex + 1));
} else {
var r = rand();
var step = 1;
if (r >= 0.6) step = 2;
if (r >= 0.85) step = 3;
var dir = (rand() < 0.5) ? -1 : 1;
var delta = dir * step;
var nextIndex = currentIndex + delta;
currentIndex = Math.max(0, Math.min(maxIndex, nextIndex));
}
var freq = scale[currentIndex];
var dur = (rand() > 0.4) ? 0.5 : 0.25;
if (t + dur > 20) dur = 20 - t;
var osc = ctx.createOscillator();
osc.type = 'triangle';
osc.frequency.value = freq;
var gain = ctx.createGain();
gain.gain.setValueAtTime(0, t);
gain.gain.linearRampToValueAtTime(melodyVol, t + 0.02);
gain.gain.linearRampToValueAtTime(0, t + dur);
osc.connect(gain);
gain.connect(ctx.destination);
osc.start(t);
osc.stop(t + dur);
t += dur;
}
}