surikov / webaudiofont

Use full GM set of musical instruments to play MIDI and single sounds or effects. Support for reverberation and equaliser. No plugins, no Flash. Pure HTML5 implementation compatible with desktop and mobile browser. See live examples.
https://surikov.github.io/webaudiofont/
GNU General Public License v3.0
891 stars 92 forks source link

No Example for ES6 Imports #69

Closed frastlin closed 3 years ago

frastlin commented 3 years ago

Hello, There is no example that I can find that uses ES6 imports. The nearest thing I can find is the "Minimal NPM code (if you need this)", but that uses Node syntax. I'm having problems finding the presets. Here is what I have:

import WebAudioFont from 'webaudiofont'

const AudioContextFunc = window.AudioContext || window.webkitAudioContext
const audioContext = new AudioContextFunc()
const player = new WebAudioFont()
player.loader.decodeAfterLoading(audioContext, '_tone_0250_SoundBlasterOld_sf2')
function play(){
    player.queueWaveTable(audioContext, audioContext.destination,
        window._tone_0250_SoundBlasterOld_sf2, 0, 12*4+7, 2)
}

I also tried importing the preset by doing:

import WebAudioFont, { _tone_0250_SoundBlasterOld_sf2} from 'webaudiofont'

I looked at player:

player._tone_0250_SoundBlasterOld_sf2

and what is returned by:

const _tone_0250_SoundBlasterOld_sf2 = player.loader.decodeAfterLoading(audioContext, '_tone_0250_SoundBlasterOld_sf2')

I'm not sure what else to try.

surikov commented 3 years ago

see https://github.com/surikov/webaudiofont#dynamic-loading

MrThanlon commented 3 months ago

Hi, check this out https://www.npmjs.com/package/@mrthanlon/webaudiofont