@@ -29,17 +29,17 @@ onmessage = function(e) {
2929 release ( e . data . ctrl . options ) ;
3030 break ;
3131 default :
32- console . error ( "Unknown control message:" , e . data ) ;
32+ console . error ( "WaveEncoderWorker - Unknown control message:" , e . data ) ;
3333 break ;
3434 }
3535 }
3636 //custom interface
3737 if ( e . data . gate != undefined ) {
38- console . error ( "Message" , e . data ) ; //DEBUG
38+ if ( doDebug ) console . error ( "WaveEncoderWorker - DEBUG - Message" , e . data ) ; //DEBUG
3939 gateControl ( e . data . gate && e . data . gate == "open" , e . data . gateOptions ) ;
4040 }
4141 if ( e . data . request ) {
42- console . error ( "Message" , e . data ) ; //DEBUG
42+ if ( doDebug ) console . error ( "WaveEncoderWorker - DEBUG - Message" , e . data ) ; //DEBUG
4343 if ( e . data . request . get ) {
4444 switch ( e . data . request . get ) {
4545 case "buffer" :
@@ -49,7 +49,7 @@ onmessage = function(e) {
4949 getWave ( e . data . request . start , e . data . request . end ) ;
5050 break ;
5151 default :
52- console . log ( "Unknown request message:" , e . data ) ;
52+ console . log ( "WaveEncoderWorker - Unknown request message:" , e . data ) ;
5353 break ;
5454 }
5555 } else if ( e . data . request . clear ) {
@@ -58,17 +58,21 @@ onmessage = function(e) {
5858 //TODO: clear buffer and release lookback lock
5959 break ;
6060 default :
61- console . log ( "Unknown request message:" , e . data ) ;
61+ console . log ( "WaveEncoderWorker - Unknown request message:" , e . data ) ;
6262 break ;
6363 }
6464 } else {
65- console . log ( "Unknown request message:" , e . data ) ;
65+ console . log ( "WaveEncoderWorker - Unknown request message:" , e . data ) ;
6666 }
6767 } else if ( e . data . encode && e . data . encode . data ) {
6868 encodeInterface ( e . data . encode ) ;
6969 }
7070} ;
7171
72+ let workerId = "wave-encoder-worker-" + Math . round ( Math . random ( ) * 1000000 ) + "-" + Date . now ( ) ;
73+ let doDebug = false ;
74+ let wasConstructorCalled = false ;
75+
7276let inputSampleRate ;
7377let inputSampleSize ;
7478let channelCount ;
@@ -186,6 +190,13 @@ function gateControl(open, gateOptions){
186190//Interface
187191
188192function constructWorker ( options ) {
193+ if ( wasConstructorCalled ) {
194+ console . error ( "WaveEncoderWorker - Constructor was called twice! 2nd call was ignored but this should be fixed!" , "-" , workerId ) ; //DEBUG
195+ return ;
196+ } else {
197+ wasConstructorCalled = true ;
198+ }
199+ doDebug = options . setup . doDebug || false ;
189200 inputSampleRate = options . setup . inputSampleRate || options . setup . ctxInfo . targetSampleRate || options . setup . ctxInfo . sampleRate ;
190201 inputSampleSize = options . setup . inputSampleSize || 512 ;
191202 channelCount = 1 ; //options.setup.channelCount || 1; //TODO: only MONO atm
@@ -210,6 +221,7 @@ function constructWorker(options){
210221 postMessage ( {
211222 moduleState : 1 ,
212223 moduleInfo : {
224+ moduleId : workerId ,
213225 inputSampleRate : inputSampleRate ,
214226 inputSampleSize : inputSampleSize ,
215227 inputIsFloat32 : isFloat32Input ,
@@ -303,7 +315,7 @@ function buildBuffer(start, end){
303315 var isFloat32 ;
304316 if ( recordedBuffers [ 0 ] ) {
305317 isFloat32 = ( recordedBuffers [ 0 ] && recordedBuffers [ 0 ] . constructor . name . indexOf ( "Float32" ) >= 0 ) ;
306- console . error ( "isFloat32" , isFloat32 , recordedBuffers [ 0 ] . constructor . name ) ;
318+ if ( doDebug ) console . error ( "WaveEncoderWorker - DEBUG - isFloat32" , isFloat32 , recordedBuffers [ 0 ] . constructor . name ) ;
307319 }
308320 var lookbackSamples ;
309321 if ( _lookbackRingBuffer && _lookbackRingBuffer . framesAvailable ) {
@@ -326,7 +338,7 @@ function buildBuffer(start, end){
326338 n ++ ;
327339 }
328340 }
329- console . error ( "buffer mismatch" , n , dataLength ) ; //TODO: why does this always match?
341+ if ( doDebug ) console . error ( "WaveEncoderWorker - DEBUG - buffer mismatch" , n , dataLength ) ; //TODO: why does this always match?
330342 //TODO: we clear lookback buffer here ... so we should clear everything
331343 lookbackBufferNeedsReset = false ;
332344
@@ -338,7 +350,7 @@ function buildBuffer(start, end){
338350
339351function encodeWAV ( samples , sampleRate , numChannels , convertFromFloat32 ) {
340352 if ( ! samples || ! sampleRate || ! numChannels ) {
341- console . error ( "Wave Encoder Worker - encodeWAV - Missing parameters" ) ;
353+ console . error ( "WaveEncoderWorker - encodeWAV - Missing parameters" ) ;
342354 return ;
343355 }
344356 //Format description: http://soundfile.sapp.org/doc/WaveFormat/
0 commit comments