Hauptdemo
CDN v3.0.0

Füge diese Tags zu deiner Seite hinzu — vor </body> oder in <head> :

Synth-Engine
<script src="https://cdn.chiptune-synth.8binami.com/3.0.0/chiptune-synth.min.js"></script>
Sound Font (170+ instruments)
<script src="https://cdn.chiptune-synth.8binami.com/3.0.0/chiptune-sound-font.min.js"></script>

Erste Schritte

Lernen Sie ChiptuneSynth Schritt für Schritt — klicken Sie auf "Ausführen", um jedes Beispiel live zu hören

1

Hallo, Chiptune!

Erstellen Sie einen Synthesizer, initialisieren Sie ihn und spielen Sie Ihren ersten Soundeffekt — alles in 3 Zeilen.

const synth = new ChiptuneSynth();
await synth.init();
synth.playPreset('coin');  // ding!
Der AudioContext erfordert eine Benutzergeste (Klick) zum Starten — deshalb verwenden wir einen Button.
2

Eine Note nach Namen Spielen

Spielen Sie das mittlere C für eine halbe Sekunde auf der Lead-Spur (Spur 0).

synth.playNoteByName('C', 4, 0, 0.5);
// note, octave, track, duration (seconds)
3

Eine Melodie Spielen

Planen Sie mehrere Noten mit Timing, um eine einfache Melodie zu erstellen.

const melody = [
  { note:'C', oct:4, time:0 },
  { note:'E', oct:4, time:0.25 },
  { note:'G', oct:4, time:0.5 },
  { note:'C', oct:5, time:0.75 }
];
melody.forEach(n =>
  setTimeout(() =>
    synth.playNoteByName(n.note, n.oct, 0, 0.3),
    n.time * 1000
  )
);
4

Ein Instrument Laden

Wechseln Sie von der Standard-Rechteckwelle zu einer Geige und spielen Sie eine Note.

synth.loadInstrument('violin', 0);
synth.playNoteByName('A', 4, 0, 1.5);
// Available: piano, violin, cello, flute, organ,
// brass, harmonica, synthLead, synthPad, synthBass,
// marimba, electricGuitar
5

Mehrspur-Schichtung

Spielen Sie verschiedene Instrumente gleichzeitig auf verschiedenen Spuren.

synth.loadInstrument('synthPad', 0);  // Lead
synth.loadInstrument('synthBass', 1); // Bass

// Play a chord on the pad
synth.playNoteByName('C', 4, 0, 2);
synth.playNoteByName('E', 4, 0, 2);
synth.playNoteByName('G', 4, 0, 2);

// Bass note underneath
synth.playNoteByName('C', 2, 1, 2);
6

Den Klang Anpassen

Passen Sie Hüllkurve, Vibrato und Wellenform an, um Ihren Klang zu formen.

// Slow attack pad
synth.updateEnvelope(0, {
  attack: 0.5, decay: 0.3,
  sustain: 0.6, release: 1.0
});

// Add vibrato
synth.updateVibrato(0, {
  rate: 5, depth: 8
});

// Change waveform to sawtooth
synth.updateTrack(0, { type: 'sawtooth' });

synth.playNoteByName('D', 4, 0, 2.5);
7

Spiel-SFX-Kombination

Verketten Sie mehrere Soundeffekte für eine Spielsequenz — Münze sammeln, aufladen, schießen!

synth.playPreset('coin');
setTimeout(() => synth.playPreset('powerup'), 400);
setTimeout(() => synth.playPreset('laser'), 1200);
setTimeout(() => synth.playPreset('explosion'), 1500);
setTimeout(() => synth.playPreset('1up'), 2200);
8

Wellenform-Visualisierung

Zeichnen Sie die Live-Audio-Wellenform auf einem Canvas — ideal für Spiel-Benutzeroberflächen!

function draw() {
  const data = synth.getWaveformData();
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.strokeStyle = '#00f0ff';
  ctx.beginPath();
  data.forEach((v, i) => {
    const x = (i / data.length) * canvas.width;
    const y = (v / 255) * canvas.height;
    i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
  });
  ctx.stroke();
  requestAnimationFrame(draw);
}
draw();