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

how to play tremolo effect? #90

Closed viewerw closed 1 year ago

surikov commented 1 year ago

Launch example https://playcode.io/1035150

Code

function playTremolo(){
  var selectedPreset=_tone_0010_SoundBlasterOld_sf2;
    var AudioContextFunc = window.AudioContext || window.webkitAudioContext;
    var audioContext = new AudioContextFunc();
    var player=new WebAudioFontPlayer();
  var pitch=12*4+7;
  var volume=0.75;
  var duration=1;
  var when=audioContext.currentTime + 0;
  var slides=[
    { delta: 0.5, when: 0.05 }
    ,{ delta: -0.5, when: 0.1 }
      ,{ delta: 0.5, when: 0.15 }
      ,{ delta: -0.5, when: 0.2 }
      ,{ delta: 0.5, when: 0.25 }
      ,{ delta: -0.5, when: 0.3 }
      ,{ delta: 0.5, when: 0.35 }
      ,{ delta: -0.5, when: 0.4 }
      ,{ delta: 0.5, when: 0.45 }
      ,{ delta: -0.5, when: 0.5 }
      ,{ delta: 0.5, when: 0.55 }
      ,{ delta: -0.5, when: 0.6 }
      ,{ delta: 0.5, when: 0.65 }
      ,{ delta: -0.5, when: 0.7 }
      ,{ delta: 0.5, when: 0.75 }
      ,{ delta: -0.5, when: 0.8 }
      ,{ delta: 0.5, when: 0.85 }
      ,{ delta: -0.5, when: 0.9 }
      ,{ delta: 0.5, when: 0.95 }
    ];
  var audioBufferSourceNode = player.queueWaveTable(audioContext
    , audioContext.destination
    , selectedPreset
    , when
    , pitch
    , duration
    , volume
    , slides
    );
}