@dawcore/spectrogram 0.0.9-next.5 → 0.0.9-next.6

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.mts CHANGED
@@ -143,7 +143,13 @@ interface SpectrogramWorkerFFTParams {
143
143
  start: number;
144
144
  end: number;
145
145
  };
146
- /** If set, compute only this channel index (used by worker pool). */
146
+ /**
147
+ * If set, compute only the channel at this index of the arrays the worker
148
+ * has for the clip. A worker with one array computes that array whatever
149
+ * this says. The pool gives each worker its one channel at index 0, or
150
+ * (worker 0, registered audio) every channel, and its multi-channel fan-out
151
+ * asks for index 0 (a mono request sends no filter) (#925).
152
+ */
147
153
  channelFilter?: number;
148
154
  }
149
155
  interface SpectrogramWorkerRenderChunksParams {
package/dist/index.d.ts CHANGED
@@ -143,7 +143,13 @@ interface SpectrogramWorkerFFTParams {
143
143
  start: number;
144
144
  end: number;
145
145
  };
146
- /** If set, compute only this channel index (used by worker pool). */
146
+ /**
147
+ * If set, compute only the channel at this index of the arrays the worker
148
+ * has for the clip. A worker with one array computes that array whatever
149
+ * this says. The pool gives each worker its one channel at index 0, or
150
+ * (worker 0, registered audio) every channel, and its multi-channel fan-out
151
+ * asks for index 0 (a mono request sends no filter) (#925).
152
+ */
147
153
  channelFilter?: number;
148
154
  }
149
155
  interface SpectrogramWorkerRenderChunksParams {
package/dist/index.js CHANGED
@@ -3651,6 +3651,13 @@ function parseChannelFromCanvasId(canvasId) {
3651
3651
  function defaultPoolSize() {
3652
3652
  return 2;
3653
3653
  }
3654
+ function channelsForWorker(channelDataArrays, workerIndex) {
3655
+ if (workerIndex === 0 || channelDataArrays.length === 0) return channelDataArrays;
3656
+ return [channelDataArrays[workerIndex]];
3657
+ }
3658
+ function payloadForChannel(channelDataArrays, channelIndex) {
3659
+ return channelDataArrays.length === 0 ? [] : [channelDataArrays[channelIndex]];
3660
+ }
3654
3661
  var MAX_POOL_CHANNELS = 32;
3655
3662
  function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize()) {
3656
3663
  if (poolSize > MAX_POOL_CHANNELS) {
@@ -3700,7 +3707,11 @@ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize())
3700
3707
  const workerIndex = workers.length;
3701
3708
  for (const [clipId, entry] of registeredAudio) {
3702
3709
  if (entry.channelDataArrays.length > workerIndex) {
3703
- w.registerAudioData(clipId, entry.channelDataArrays, entry.sampleRate);
3710
+ w.registerAudioData(
3711
+ clipId,
3712
+ channelsForWorker(entry.channelDataArrays, workerIndex),
3713
+ entry.sampleRate
3714
+ );
3704
3715
  }
3705
3716
  }
3706
3717
  workers.push(w);
@@ -3728,7 +3739,14 @@ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize())
3728
3739
  }
3729
3740
  const promises = Array.from(
3730
3741
  { length: channelCount },
3731
- (_, i) => ensureWorkerForChannel(i).computeFFT({ ...params, channelFilter: i }, generation)
3742
+ (_, i) => ensureWorkerForChannel(i).computeFFT(
3743
+ {
3744
+ ...params,
3745
+ channelDataArrays: payloadForChannel(params.channelDataArrays, i),
3746
+ channelFilter: 0
3747
+ },
3748
+ generation
3749
+ )
3732
3750
  );
3733
3751
  const settled = await Promise.allSettled(promises);
3734
3752
  const failures = settled.filter((s) => s.status === "rejected");
@@ -3772,10 +3790,14 @@ function createSpectrogramWorkerPool(createWorker, poolSize = defaultPoolSize())
3772
3790
  },
3773
3791
  registerAudioData(clipId, channelDataArrays, sampleRate) {
3774
3792
  if (terminated) return;
3793
+ const previousCount = registeredAudio.get(clipId)?.channelDataArrays.length ?? 0;
3794
+ for (let i = channelDataArrays.length; i < Math.min(previousCount, workers.length); i++) {
3795
+ workers[i].unregisterAudioData(clipId);
3796
+ }
3775
3797
  registeredAudio.set(clipId, { channelDataArrays, sampleRate });
3776
3798
  const relevantWorkers = Math.min(channelDataArrays.length, workers.length);
3777
3799
  for (let i = 0; i < relevantWorkers; i++) {
3778
- workers[i].registerAudioData(clipId, channelDataArrays, sampleRate);
3800
+ workers[i].registerAudioData(clipId, channelsForWorker(channelDataArrays, i), sampleRate);
3779
3801
  }
3780
3802
  },
3781
3803
  unregisterAudioData(clipId) {