@@ -36,20 +36,33 @@ onmessage = function(e) {
3636 //custom interface
3737 if ( e . data . gate != undefined ) {
3838 console . error ( "Message" , e . data ) ; //DEBUG
39- gateControl ( e . data . gate && e . data . gate == "open" ) ;
39+ gateControl ( e . data . gate && e . data . gate == "open" , e . data . gateOptions ) ;
4040 }
4141 if ( e . data . request ) {
4242 console . error ( "Message" , e . data ) ; //DEBUG
43- switch ( e . data . request . get ) {
44- case "buffer" :
45- getBuffer ( e . data . request . start , e . data . request . end ) ;
46- break ;
47- case "wave" :
48- getWave ( e . data . request . start , e . data . request . end ) ;
49- break ;
50- default :
51- console . log ( "Unknown request message:" , e . data ) ;
52- break ;
43+ if ( e . data . request . get ) {
44+ switch ( e . data . request . get ) {
45+ case "buffer" :
46+ getBuffer ( e . data . request . start , e . data . request . end ) ;
47+ break ;
48+ case "wave" :
49+ getWave ( e . data . request . start , e . data . request . end ) ;
50+ break ;
51+ default :
52+ console . log ( "Unknown request message:" , e . data ) ;
53+ break ;
54+ }
55+ } else if ( e . data . request . clear ) {
56+ switch ( e . data . request . clear ) {
57+ case "buffer" :
58+ //TODO: clear buffer and release lookback lock
59+ break ;
60+ default :
61+ console . log ( "Unknown request message:" , e . data ) ;
62+ break ;
63+ }
64+ } else {
65+ console . log ( "Unknown request message:" , e . data ) ;
5366 }
5467 } else if ( e . data . encode && e . data . encode . data ) {
5568 encodeInterface ( e . data . encode ) ;
@@ -145,7 +158,8 @@ function encodeInterface(e){
145158 }
146159}
147160
148- function gateControl ( open ) {
161+ function gateControl ( open , gateOptions ) {
162+ if ( ! gateOptions ) gateOptions = { } ; //TODO: use e.g. for (lookbackBufferNeedsReset = false)
149163 var msg = {
150164 moduleEvent : true , //use 'moduleEvent' to distinguish from normal processing result
151165 gate : { }
@@ -197,6 +211,7 @@ function constructWorker(options){
197211 moduleInfo : {
198212 inputSampleRate : inputSampleRate ,
199213 inputSampleSize : inputSampleSize ,
214+ inputIsFloat32 : isFloat32Input ,
200215 channelCount : channelCount ,
201216 lookbackBufferSizeKb : Math . ceil ( ( _lookbackBufferSize * 2 ) / 1024 ) , //1 sample = 2 bytes
202217 lookbackLimitMs : lookbackBufferMs ,
@@ -210,21 +225,21 @@ function process(data){
210225 //TODO: check process values against constructor values (sampleSize etc.)
211226 if ( data && data . samples ) {
212227 if ( _isFirstValidProcess ) {
228+ //console.error("data info", data); //DEBUG
213229 _isFirstValidProcess = false ;
214- console . error ( "data info" , data ) ; //DEBUG
215230 //check: inputSampleRate, inputSampleSize, channelCount, float32
216231 if ( data . sampleRate != inputSampleRate ) {
217232 var msg = "Sample-rate mismatch! Should be '" + inputSampleRate + "' is '" + data . sampleRate + "'" ;
218233 console . error ( "Audio Worker sample-rate exception - Msg.: " + msg ) ;
219- throw new SampleRateException ( msg ) ; //TODO : this probably needs to be a string to show up in worker.onerror properly :-/
234+ throw JSON . stringify ( new SampleRateException ( msg ) ) ; //NOTE : this needs to be a string to show up in worker.onerror properly :-/
220235 return ;
221236 }
222- var inputArrayType = data . samples [ 0 ] . constructor . name ;
237+ var inputArrayType = data . type || data . samples [ 0 ] . constructor . name ;
223238 var isFloat32 = ( inputArrayType . indexOf ( "Float32" ) >= 0 ) ;
224239 if ( isFloat32 != isFloat32Input ) {
225240 var msg = "Array type mismatch! Input samples are of type '" + inputArrayType + "' but expected: " + ( isFloat32Input ? "Float32" : "Int16" ) ;
226241 console . error ( "Audio Worker type exception - Msg.: " + msg ) ;
227- throw new ArrayTypeException ( msg ) ; //TODO : this probably needs to be a string to show up in worker.onerror properly :-/
242+ throw JSON . stringify ( new ArrayTypeException ( msg ) ) ; //NOTE : this needs to be a string to show up in worker.onerror properly :-/
228243 return ;
229244 }
230245 //TODO: should we re-init. instead of fail?
@@ -295,6 +310,7 @@ function buildBuffer(start, end){
295310 _lookbackRingBuffer . pull ( lookbackSamples ) ;
296311 }
297312 var dataLength = recordedBuffers . length * inputSampleSize + ( lookbackSamples ? lookbackSamples [ 0 ] . length : 0 ) ;
313+ //TODO: any chance to allocate 'collectBuffer' in advance and keep it? (max. rec + lookback maybe?)
298314 var collectBuffer = isFloat32 ? new Float32Array ( dataLength ) : new Int16Array ( dataLength ) ; //TODO: this is usually too big because the last buffer is not full ...
299315 var n = 0 ;
300316 if ( lookbackSamples ) {
@@ -316,6 +332,7 @@ function buildBuffer(start, end){
316332 isFloat32 : isFloat32
317333 }
318334 //TODO: we clear lookback buffer here ... so we should clear everything
335+ lookbackBufferNeedsReset = false ;
319336}
320337
321338function encodeWAV ( samples , sampleRate , numChannels , convertFromFloat32 ) {
0 commit comments