@@ -2896,6 +2896,7 @@ pulse = function () {
28962896 */
28972897 p5 . Pulse = function ( freq , w ) {
28982898 p5 . Oscillator . call ( this , freq , 'sawtooth' ) ;
2899+ this . output . disconnect ( ) ;
28992900 // width of PWM, should be betw 0 to 1.0
29002901 this . w = w || 0 ;
29012902 // create a second oscillator with inverse frequency
@@ -2908,8 +2909,9 @@ pulse = function () {
29082909 this . dcOffset . connect ( this . dcGain ) ;
29092910 this . dcGain . connect ( this . output ) ;
29102911 // set delay time based on PWM width
2911- var mW = this . w / this . oscillator . frequency . value ;
2912- this . dNode . delayTime . setValueAtTime ( mW , p5sound . audiocontext . currentTime ) ;
2912+ this . f = freq || 440 ;
2913+ var mW = map ( this . w , 0 , 1 , 0 , 1 / this . f ) ;
2914+ this . dNode . delayTime . value = mW ;
29132915 this . dcGain . gain . value = 1.7 * ( 0.5 - this . w ) ;
29142916 this . oscillator . disconnect ( ) ;
29152917 this . newGain = p5sound . audiocontext . createGain ( ) ;
@@ -2920,9 +2922,9 @@ pulse = function () {
29202922 this . osc2 . disconnect ( ) ;
29212923 this . osc2 . output . gain . minValue = - 10 ;
29222924 this . osc2 . output . gain . maxValue = 10 ;
2923- this . osc2 . output . gain . value = - 1 ;
2925+ this . osc2 . amp ( - 1 ) ;
29242926 // inverted amplitude
2925- this . osc2 . panner . connect ( this . dNode ) ;
2927+ this . osc2 . output . connect ( this . dNode ) ;
29262928 this . dNode . connect ( this . output ) ;
29272929 this . output . connect ( this . panner ) ;
29282930 } ;
@@ -2939,8 +2941,10 @@ pulse = function () {
29392941 if ( w <= 1 && w >= 0 ) {
29402942 this . w = w ;
29412943 // set delay time based on PWM width
2942- var mW = this . w / this . oscillator . frequency . value ;
2943- this . dNode . delayTime . setValueAtTime ( mW , p5sound . audiocontext . currentTime ) ;
2944+ // var mW = map(this.w, 0, 1.0, 0, 1/this.f);
2945+ var mW = this . w / this . f ;
2946+ console . log ( mW ) ;
2947+ this . dNode . delayTime . value = mW ;
29442948 }
29452949 this . dcGain . gain . value = 1.7 * ( 0.5 - this . w ) ;
29462950 } ;
@@ -2967,6 +2971,8 @@ pulse = function () {
29672971 this . osc2 . oscillator . frequency
29682972 ] ;
29692973 // start dcOffset, too
2974+ this . dcOffset = createDCOffset ( ) ;
2975+ this . dcOffset . connect ( this . dcGain ) ;
29702976 this . dcOffset . start ( t + now ) ;
29712977 // if LFO connections depend on these oscillators
29722978 if ( this . mods !== undefined && this . mods . frequency !== undefined ) {
0 commit comments