시작하기

ChiptuneSynth를 단계별로 배워보세요 — "실행"을 클릭하면 각 예제를 실시간으로 들어볼 수 있습니다

1

안녕하세요, Chiptune!

신디사이저를 생성하고, 초기화한 다음, 첫 번째 사운드 효과를 재생해 보세요 — 단 3줄로 가능합니다.

const synth = new ChiptuneSynth();
await synth.init();
synth.playPreset('coin');  // ding!
AudioContext는 시작하기 위해 사용자 제스처(클릭)가 필요합니다. 그래서 버튼을 사용합니다.
2

이름으로 음표 재생하기

리드 트랙(트랙 0)에서 중음 C를 0.5초 동안 재생합니다.

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

멜로디 연주

타이밍을 맞춰 여러 음을 배열하여 간단한 곡을 만듭니다.

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

악기 불러오기

기본 사각파에서 바이올린으로 전환한 다음 음을 연주해 보세요.

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

멀티 트랙 레이어링

서로 다른 트랙에서 서로 다른 악기를 동시에 연주해 보세요.

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

사운드 조정

엔벨로프, 비브라토, 파형을 맞춤 설정하여 사운드를 다듬으세요.

// 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

게임 SFX 콤보

게임 시퀀스에 맞춰 여러 사운드 효과를 연결해 보세요 — 코인 수집, 파워업, 사격!

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

파형 시각화

캔버스에 실시간 오디오 파형을 그려보세요 — 게임 UI에 안성맞춤!

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();