@@ -811,11 +811,10 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
811811 super ( ) ;
812812 this . port . onmessage = ( event ) => {
813813 let { codeText } = event . data ;
814- const { startTimeSeconds, frequency } = event . data ;
815- if ( startTimeSeconds != null ) {
816- const t = startTimeSeconds * sampleRate ;
817- this . t = t ;
818- this . t = ( t / ( sampleRate / 256 ) ) * frequency ;
814+ const { byteBeatStartTime } = event . data ;
815+ if ( byteBeatStartTime != null ) {
816+ this . t = 0
817+ this . initialOffset = Math . floor ( byteBeatStartTime )
819818 }
820819
821820 //Optimization pulled from dollchan.net: https://github.com/Chasyxx/EnBeat_NEW, it seemed important
@@ -829,6 +828,7 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
829828
830829 this . func = getByteBeatFunc ( codeText ) ;
831830 } ;
831+ this . initialOffset = null ;
832832 this . t = null ;
833833 this . func = null ;
834834 }
@@ -878,13 +878,14 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
878878 for ( let i = 0 ; i < output [ 0 ] . length ; i ++ ) {
879879 const detune = getParamValue ( i , params . detune ) ;
880880 const freq = applySemitoneDetuneToFrequency ( getParamValue ( i , params . frequency ) , detune / 100 ) ;
881- let t = ( this . t / ( sampleRate / 256 ) ) * freq ;
882- const funcValue = this . func ( t ) ;
881+ let local_t = ( ( this . t / ( sampleRate / 256 ) ) * freq ) + this . initialOffset
882+ const funcValue = this . func ( local_t ) ;
883883 let signal = ( funcValue & 255 ) / 127.5 - 1 ;
884884 const out = signal * 0.2 ;
885885
886886 for ( let c = 0 ; c < output . length ; c ++ ) {
887- output [ c ] [ i ] = clamp ( out , - 0.2 , 0.2 ) ;
887+ //prevent speaker blowout via clipping if threshold exceeds
888+ output [ c ] [ i ] = clamp ( out , - 0.4 , 0.4 ) ;
888889 }
889890 this . t = this . t + 1 ;
890891 }
0 commit comments