Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add sf2 soundfonts to sound registry #182

Open
Tracked by #671
felixroos opened this issue Aug 13, 2022 · 4 comments
Open
Tracked by #671

add sf2 soundfonts to sound registry #182

felixroos opened this issue Aug 13, 2022 · 4 comments
Labels
enhancement improves an existing feature

Comments

@felixroos
Copy link
Collaborator

felixroos commented Aug 13, 2022

instead of (or in addition to) .soundfont, soundfont presets should be usable via .s
When loadSoundfont is called, all presets in the loaded soundfont are added to the available sounds of s.
Some type of sound registry has to be implemented to be able to add sounds from outside (webaudio package should not depend on soundfont package). Also remove the old non sf2 file based soundfonts

@felixroos felixroos added the enhancement improves an existing feature label Aug 14, 2022
@felixroos
Copy link
Collaborator Author

felixroos commented Mar 3, 2023

idea: add a new function that takes in a callback for creating the source web audio node:

note("c a f e").sourceNode((hap, deadline, duration, cps) => {
  /* webaudio code that uses above params to create a webaudio node * /
  return node;
}).lpf(1000)

the function is similar to onTrigger, but instead of being just a general purpose callback, the function is expected to return a web audio node, which is used by the webaudio output to apply the standard chain. Advantages:

  • allows to add custom sound sources from the outside. the existing oscillators, the sampler and soundfonts could all just implement a source.
  • the standard chain is preserved, meaning a custom source will still work with all the effects (like lpf in the example)
  • it can also be used in the user code to create custom instruments with webaudio code

the same approach could potentially also work for custom effects, e.g. effectNode

@felixroos
Copy link
Collaborator Author

felixroos commented Mar 6, 2023

this works really well! it opens up some interesting possibilities:

const lfo = (freq, type = 'sine', range = 1) => {
  const ctx = getAudioContext();
  const osc = ctx.createOscillator();
  osc.type = type;
  osc.frequency.value = freq;
  osc.start();
  const g = new GainNode(ctx, { gain: range/2 });
  osc.connect(g); // -range, range
  return g;
}
const pitchLFO = lfo(.1, 'sine', 20);

note("c eb a*4 c4".add("12,12.05")).legato(.5 )
  .source((t, value, duration) => {
    const { release = 0.01 } = value;
    const ctx = getAudioContext();
    const o = ctx.createOscillator();
    o.type = 'sawtooth';
    const freq = getFrequency({value});
    o.frequency.value = Number(freq/2);
    o.start(t);
    o.stop(t + duration + release)
    pitchLFO.connect(o.frequency)
    return o;
  })
  .room(.5).lpf(800)
  .gain(.5)

this cries for a thin web audio abstraction layer..

@felixroos felixroos mentioned this issue Mar 6, 2023
4 tasks
@felixroos
Copy link
Collaborator Author

PR for sound registry #516

@felixroos
Copy link
Collaborator Author

note to avoid confusion: #516 now has integrated gm soundfonts based on webaudiofontdata, but the soundfonts loaded from sf2 files are still not part of the registry, so I'll leave this open

@felixroos felixroos changed the title add sound registry to integrate soundfonts with .s add sf2 soundfonts to sound registry Mar 23, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement improves an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant