Skip to content

carrotflakes/fcsynth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fcsynth

Web Audio API based synthesis module.

Usage

// initialize
const ac = new AudioContext();
const nameMap = {f: fcsynth.frequency, tempo: fcsynth.tempo};
const sb = new fcsynth.SynthBuilder(ac, nameMap);
const synth = sb.build(
  fcsynth.makeDefaultModel('y'),
  ac.destination,
  {
    tempo: 120,
    y: 0.75
  });

// synth needs to be update regularly while playing notes.
setInterval(() => {
  synth.update(ac.currentTime);
}, 1000);

// play notes
const note = synth.note({
  f: 440, // frequency
  y: 0.75 // velocity
});
note.on(ac.currentTime);
note.off(ac.currentTime + 1);