spessasynth_lib 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -179,6 +179,10 @@ type SequencerReturnMessage = (SequencerEvent & {
179
179
  type: "midiError";
180
180
  data: Error;
181
181
  id: number;
182
+ } | {
183
+ type: "sync";
184
+ data: number;
185
+ id: number;
182
186
  };
183
187
  /**
184
188
  * Sequencer.js
@@ -235,6 +239,7 @@ declare abstract class BasicSynthesizerCore {
235
239
  readonly synthesizer: SpessaSynthProcessor;
236
240
  readonly sequencers: SpessaSynthSequencer[];
237
241
  protected readonly post: PostMessageSynthCore;
242
+ protected lastSequencerSync: number;
238
243
  /**
239
244
  * Indicates if the processor is alive.
240
245
  * @protected
@@ -276,7 +281,7 @@ declare class WorkerSynthesizerCore extends BasicSynthesizerCore {
276
281
  protected stopAudioLoop(): void;
277
282
  protected startAudioLoop(): void;
278
283
  protected destroy(): void;
279
- protected renderAndSendChunk(): void;
284
+ protected process(): void;
280
285
  }
281
286
 
282
287
  interface WorkerRenderAudioOptions {
package/dist/index.js CHANGED
@@ -1996,10 +1996,12 @@ var songChangeType = {
1996
1996
  };
1997
1997
 
1998
1998
  // src/synthesizer/basic/basic_synthesizer_core.ts
1999
+ var SEQUENCER_SYNC_INTERVAL = 1;
1999
2000
  var BasicSynthesizerCore = class {
2000
2001
  synthesizer;
2001
2002
  sequencers = new Array();
2002
2003
  post;
2004
+ lastSequencerSync = 0;
2003
2005
  /**
2004
2006
  * Indicates if the processor is alive.
2005
2007
  * @protected
@@ -2504,7 +2506,7 @@ var WorkerSynthesizerCore = class extends BasicSynthesizerCore {
2504
2506
  mainThreadCallback
2505
2507
  );
2506
2508
  this.workletMessagePort = workletMessagePort;
2507
- this.workletMessagePort.onmessage = this.renderAndSendChunk.bind(this);
2509
+ this.workletMessagePort.onmessage = this.process.bind(this);
2508
2510
  this.compressionFunction = compressionFunction;
2509
2511
  void this.synthesizer.processorInitialized.then(() => {
2510
2512
  this.postReady("sf3Decoder", null);
@@ -2608,14 +2610,14 @@ var WorkerSynthesizerCore = class extends BasicSynthesizerCore {
2608
2610
  }
2609
2611
  startAudioLoop() {
2610
2612
  this.alive = true;
2611
- this.renderAndSendChunk();
2613
+ this.process();
2612
2614
  }
2613
2615
  destroy() {
2614
2616
  this.workletMessagePort.postMessage(null);
2615
2617
  this.stopAudioLoop();
2616
2618
  super.destroy();
2617
2619
  }
2618
- renderAndSendChunk() {
2620
+ process() {
2619
2621
  if (!this.alive) {
2620
2622
  return;
2621
2623
  }
@@ -2644,6 +2646,21 @@ var WorkerSynthesizerCore = class extends BasicSynthesizerCore {
2644
2646
  }
2645
2647
  this.synthesizer.renderAudioSplit(rev, chr, dry);
2646
2648
  this.workletMessagePort.postMessage(data, [data.buffer]);
2649
+ const t = this.synthesizer.currentSynthTime;
2650
+ if (t - this.lastSequencerSync > SEQUENCER_SYNC_INTERVAL) {
2651
+ for (let id = 0; id < this.sequencers.length; id++) {
2652
+ this.post({
2653
+ type: "sequencerReturn",
2654
+ data: {
2655
+ type: "sync",
2656
+ data: this.sequencers[id].currentTime,
2657
+ id
2658
+ },
2659
+ currentTime: t
2660
+ });
2661
+ }
2662
+ this.lastSequencerSync = t;
2663
+ }
2647
2664
  }
2648
2665
  };
2649
2666
 
@@ -3011,6 +3028,11 @@ var Sequencer = class {
3011
3028
  this.callEventInternal("songChange", songChangeData);
3012
3029
  break;
3013
3030
  }
3031
+ case "sync": {
3032
+ if (Math.abs(m.data - this.currentTime) > 0.05)
3033
+ this.recalculateStartTime(m.data);
3034
+ break;
3035
+ }
3014
3036
  case "timeChange": {
3015
3037
  const time = m.data.newTime;
3016
3038
  this.recalculateStartTime(time);