g200kg / webaudio-tinysynth

Light-weight GM mapped WebAudio-JavaScript Synthesizer Engine / MIDI Player
Apache License 2.0
229 stars 22 forks source link

{osx, iOS} safari: Can't find variable AudioContext. #1

Closed sug1no closed 7 years ago

sug1no commented 7 years ago

On load https://g200kg.github.io/webaudio-tinysynth/jstest.html by {osx, iOS} safari the following error occurred:

Can't find variable AudioContext.

the following is a fake workaround (need panner support...) to avoid error:

diff --git a/webaudio-tinysynth.js b/webaudio-tinysynth.js
index 0c313fa..05fc57b 100644
--- a/webaudio-tinysynth.js
+++ b/webaudio-tinysynth.js
@@ -551,8 +551,10 @@ function WebAudioTinySynth(){
         this.canvas.addEventListener("click",this.click.bind(this),false);
       }
       console.log("internalcontext:"+this.internalcontext)
-      if(this.internalcontext)
-        this.setAudioContext(new AudioContext());
+      if(this.internalcontext) {
+        var tAudioContext = window.AudioContext || window.webkitAudioContext;
+        this.setAudioContext(new tAudioContext());
+      }
       this.isReady=1;
     },
     setMasterVol:function(v){
@@ -887,7 +889,7 @@ function WebAudioTinySynth(){
       this.bend[ch]=0; this.vol[ch]=100/127*100/127; this.ex[ch]=1.0;
       this.brange[ch]=2<<7; this.rpnidx[ch]=0x3fff; this.sustain[ch]=0;
       this.chvol[ch].gain.value=this.vol[ch]*this.ex[ch];
-      this.chmod[ch].gain.value=0; this.chpan[ch].pan.value=0;
+      //this.chmod[ch].gain.value=0; this.chpan[ch].pan.value=0;
       this.pg[ch]=0;
     },
     send:function(msg,t,tsmode){    /* send midi message */
@@ -920,7 +922,7 @@ function WebAudioTinySynth(){
           this.chvol[ch].gain.setValueAtTime(this.vol[ch]*this.ex[ch],t);
           break;
         case 10: /* pan */
-          this.chpan[ch].pan.setValueAtTime((msg[2]-64)/64,t);
+          //this.chpan[ch].pan.setValueAtTime((msg[2]-64)/64,t);
           break;
         case 11: /* expression */
           this.ex[ch]=msg[2]*msg[2]/(127*127);
@@ -1049,7 +1051,7 @@ function WebAudioTinySynth(){
       this.lfo.start();
       for(i=0;i<16;++i){
         this.chvol[i]=this.actx.createGain();
-        this.chpan[i]=this.actx.createStereoPanner();
+        this.chpan[i]=this.actx.createStereoPanner ? this.actx.createStereoPanner() : this.actx.createPanner();
         this.chvol[i].connect(this.chpan[i]);
         this.chpan[i].connect(this.out);
         this.chmod[i]=this.actx.createGain();

Thank you for the great product. Are there any plans to support Safari?

g200kg commented 7 years ago

Thank you!!

Until now I did not think about mobile devices. Though it may become intense CPU consumption, I will think about that when I can have the time.

g200kg commented 7 years ago

Now, iOS Safari has supported.

sug1no commented 7 years ago

5e5ebe91a33805d12ca2667764068b41b6e8433b works on my iPad pro safari and osx safari!. great! thx!