danigb / soundfont-player

Quick soundfont loader and player for browser
MIT License
455 stars 59 forks source link

How to use with Tuna.js #77

Open 798714773 opened 4 years ago

798714773 commented 4 years ago

How to use with Tuna.js I need a demo

rhelsing commented 3 years ago

@danigb I would like to know how this would be possible too?

I've tried the following but it does not work:

var AudioContext = window.AudioContext || window.webkitAudioContext || false;
var ac = new AudioContext || new webkitAudioContext;

var ef = new tuna.Bitcrusher({
    bits: 4,          //1 to 16
    normfreq: 0.1,    //0 to 1
    bufferSize: 4096  //256 to 16384
});

var input = ac.createGain();
var output = ac.createGain();
input.connect(ef);
ef.connect(output);

Soundfont.instrument(ac, '......').then(function (instrument) {
....
})
rhelsing commented 3 years ago

I'm a little further along but it seems to be playing the effected audio as well as the uneffected audio:

var AudioContext = window.AudioContext || window.webkitAudioContext || false;
var ac = new AudioContext || new webkitAudioContext;

var ef = new tuna.Bitcrusher({
    bits: 4,          //1 to 16
    normfreq: 0.1,    //0 to 1
    bufferSize: 4096  //256 to 16384
});

Soundfont.instrument(ac, '......').then(function (instrument) {
  instrument.connect(ef)
  ef.connect(ac.destination)
})