@waveform-playlist/browser 11.1.0 → 11.2.0

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
@@ -186,6 +186,10 @@ interface WaveformPlaylistProviderProps {
186
186
  /** Disable automatic stop when the cursor reaches the end of the longest
187
187
  * track. Useful for DAW-style recording beyond existing audio. */
188
188
  indefinitePlayback?: boolean;
189
+ /** Desired AudioContext sample rate. Creates a cross-browser AudioContext at
190
+ * this rate via standardized-audio-context. Pre-computed peaks (.dat files)
191
+ * render instantly when they match. On mismatch, falls back to worker. */
192
+ sampleRate?: number;
189
193
  children: ReactNode;
190
194
  }
191
195
  declare const WaveformPlaylistProvider: React__default.FC<WaveformPlaylistProviderProps>;
package/dist/index.d.ts CHANGED
@@ -186,6 +186,10 @@ interface WaveformPlaylistProviderProps {
186
186
  /** Disable automatic stop when the cursor reaches the end of the longest
187
187
  * track. Useful for DAW-style recording beyond existing audio. */
188
188
  indefinitePlayback?: boolean;
189
+ /** Desired AudioContext sample rate. Creates a cross-browser AudioContext at
190
+ * this rate via standardized-audio-context. Pre-computed peaks (.dat files)
191
+ * render instantly when they match. On mismatch, falls back to worker. */
192
+ sampleRate?: number;
189
193
  children: ReactNode;
190
194
  }
191
195
  declare const WaveformPlaylistProvider: React__default.FC<WaveformPlaylistProviderProps>;
package/dist/index.js CHANGED
@@ -172,11 +172,13 @@ var import_tone4 = require("tone");
172
172
  var import_waveform_data = __toESM(require("waveform-data"));
173
173
  function loadWaveformData(src) {
174
174
  return __async(this, null, function* () {
175
+ var _a, _b;
175
176
  const response = yield fetch(src);
176
177
  if (!response.ok) {
177
178
  throw new Error(`Failed to fetch waveform data: ${response.statusText}`);
178
179
  }
179
- const isBinary = src.endsWith(".dat");
180
+ const { pathname } = new URL(src, (_b = (_a = globalThis.location) == null ? void 0 : _a.href) != null ? _b : "http://localhost");
181
+ const isBinary = pathname.toLowerCase().endsWith(".dat");
180
182
  if (isBinary) {
181
183
  const arrayBuffer = yield response.arrayBuffer();
182
184
  return import_waveform_data.default.create(arrayBuffer);
@@ -3764,6 +3766,7 @@ var WaveformPlaylistProvider = ({
3764
3766
  soundFontCache,
3765
3767
  deferEngineRebuild = false,
3766
3768
  indefinitePlayback = false,
3769
+ sampleRate: sampleRateProp,
3767
3770
  children
3768
3771
  }) => {
3769
3772
  var _a, _b, _c, _d;
@@ -3827,9 +3830,21 @@ var WaveformPlaylistProvider = ({
3827
3830
  const isDraggingRef = (0, import_react24.useRef)(false);
3828
3831
  const prevTracksRef = (0, import_react24.useRef)([]);
3829
3832
  const samplesPerPixelRef = (0, import_react24.useRef)(initialSamplesPerPixel);
3830
- const sampleRateRef = (0, import_react24.useRef)(
3831
- typeof AudioContext !== "undefined" ? (0, import_playout5.getGlobalAudioContext)().sampleRate : 48e3
3832
- );
3833
+ const [initialSampleRate] = (0, import_react24.useState)(() => {
3834
+ if (typeof AudioContext === "undefined") return sampleRateProp != null ? sampleRateProp : 48e3;
3835
+ try {
3836
+ if (sampleRateProp !== void 0) {
3837
+ return (0, import_playout5.configureGlobalContext)({ sampleRate: sampleRateProp });
3838
+ }
3839
+ return (0, import_playout5.getGlobalAudioContext)().sampleRate;
3840
+ } catch (err) {
3841
+ console.warn(
3842
+ "[waveform-playlist] Failed to configure AudioContext: " + String(err) + " \u2014 falling back to " + (sampleRateProp != null ? sampleRateProp : 48e3) + " Hz"
3843
+ );
3844
+ return sampleRateProp != null ? sampleRateProp : 48e3;
3845
+ }
3846
+ });
3847
+ const sampleRateRef = (0, import_react24.useRef)(initialSampleRate);
3833
3848
  const { timeFormat, setTimeFormat, formatTime: formatTime2 } = useTimeFormat();
3834
3849
  const zoom = useZoomControls({ engineRef, initialSamplesPerPixel });
3835
3850
  const { samplesPerPixel, onEngineState: onZoomEngineState } = zoom;
@@ -4179,15 +4194,28 @@ var WaveformPlaylistProvider = ({
4179
4194
  let peaks;
4180
4195
  if (clip.waveformData) {
4181
4196
  try {
4197
+ const wdRate = clip.waveformData.sample_rate;
4198
+ const clipRate = clip.sampleRate;
4199
+ let peakOffset = clip.offsetSamples;
4200
+ let peakDuration = clip.durationSamples;
4201
+ let peakSpp = samplesPerPixel;
4202
+ if (wdRate !== clipRate && clipRate > 0 && wdRate > 0) {
4203
+ const ratio = wdRate / clipRate;
4204
+ peakOffset = Math.round(clip.offsetSamples * ratio);
4205
+ peakDuration = Math.round(clip.durationSamples * ratio);
4206
+ peakSpp = Math.max(1, Math.round(samplesPerPixel * ratio));
4207
+ }
4182
4208
  peaks = extractPeaksFromWaveformDataFull(
4183
4209
  clip.waveformData,
4184
- samplesPerPixel,
4210
+ peakSpp,
4185
4211
  mono,
4186
- clip.offsetSamples,
4187
- clip.durationSamples
4212
+ peakOffset,
4213
+ peakDuration
4188
4214
  );
4189
4215
  } catch (err) {
4190
- console.warn("[waveform-playlist] Failed to extract peaks from waveformData:", err);
4216
+ console.warn(
4217
+ "[waveform-playlist] Failed to extract peaks from waveformData: " + String(err)
4218
+ );
4191
4219
  }
4192
4220
  }
4193
4221
  if (!peaks) {
@@ -4202,7 +4230,9 @@ var WaveformPlaylistProvider = ({
4202
4230
  clip.durationSamples
4203
4231
  );
4204
4232
  } catch (err) {
4205
- console.warn("[waveform-playlist] Failed to extract peaks from cache:", err);
4233
+ console.warn(
4234
+ "[waveform-playlist] Failed to extract peaks from cache: " + String(err)
4235
+ );
4206
4236
  }
4207
4237
  }
4208
4238
  }