sf2-synth-audio-worklet
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

sf2-synth-audio-worklet

license npm npm downloads ci

An Audio Worklet-based SoundFont2 synthesizer for the browser.

Installation

npm install sf2-synth-audio-worklet

Getting Started

This code sets up a simple SoundFont2 player in React using the library.

import { useState } from 'react'
import {
  createSoundFont2SynthNode,
  type SoundFont2SynthNode,
} from 'sf2-synth-audio-worklet'

function App() {
  const [node, setNode] = useState<SoundFont2SynthNode>()

  const setup = async () => {
    const audioContext = new AudioContext()
    const sf2Url = 'path/to/soundfont2' // Replace with the SoundFont2 file path
    const node = await createSoundFont2SynthNode(audioContext, sf2Url)
    node.connect(audioContext.destination)
    setNode(node)
  }

  const noteOn = () => node?.noteOn(0, 60, 100, 0)
  const noteOff = () => node?.noteOff(0, 60, 0)

  return (
    <div>
      <button onClick={setup} disabled={!!node}>
        Setup
      </button>
      <button onMouseDown={noteOn} onMouseUp={noteOff} disabled={!node}>
        Sound
      </button>
    </div>
  )
}

License

MIT

Dependencies (0)

    Dev Dependencies (21)

    Package Sidebar

    Install

    npm i sf2-synth-audio-worklet

    Weekly Downloads

    2

    Version

    0.0.12

    License

    MIT

    Unpacked Size

    297 kB

    Total Files

    9

    Last publish

    Collaborators

    • neoki