@waveform-playlist/core 13.0.0-next.7 → 13.0.0-next.9

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.mjs CHANGED
@@ -667,9 +667,6 @@ function appendToAudioBuffer(audioContext, existingBuffer, newSamples, sampleRat
667
667
  const combined = concatenateAudioData([existingData, newSamples]);
668
668
  return createAudioBuffer(audioContext, [combined], sampleRate);
669
669
  }
670
- function calculateDuration(sampleCount, sampleRate) {
671
- return sampleCount / sampleRate;
672
- }
673
670
 
674
671
  // src/utils/latency.ts
675
672
  function audibleLatencySamples(outputLatency, lookAhead, sampleRate) {
@@ -1309,9 +1306,9 @@ function applyAnnotationBounds(current, changes) {
1309
1306
 
1310
1307
  // src/panStage.ts
1311
1308
  var PREFIX = "[waveform-playlist] ";
1312
- function panMatrix(pan, sourceChannelCount) {
1309
+ function panMatrix(pan, panLaw) {
1313
1310
  const p = Number.isFinite(pan) ? Math.max(-1, Math.min(1, pan)) : 0;
1314
- if (sourceChannelCount < 2) {
1311
+ if (panLaw === "mono") {
1315
1312
  const theta = (p + 1) * Math.PI / 4;
1316
1313
  return { ll: Math.cos(theta), lr: 0, rl: 0, rr: Math.sin(theta) };
1317
1314
  }
@@ -1322,7 +1319,8 @@ function panMatrix(pan, sourceChannelCount) {
1322
1319
  const x = p * Math.PI / 2;
1323
1320
  return { ll: Math.cos(x), lr: Math.sin(x), rl: 0, rr: 1 };
1324
1321
  }
1325
- function createPanStage(context, pan, sourceChannelCount) {
1322
+ var PAN_LAW_RAMP_SECONDS = 0.01;
1323
+ function createPanStage(context, pan, panLaw) {
1326
1324
  const upmix = context.createGain();
1327
1325
  upmix.channelCount = 2;
1328
1326
  upmix.channelCountMode = "explicit";
@@ -1334,13 +1332,32 @@ function createPanStage(context, pan, sourceChannelCount) {
1334
1332
  const rl = context.createGain();
1335
1333
  const rr = context.createGain();
1336
1334
  let currentPan = pan;
1337
- let currentChannelCount = sourceChannelCount;
1335
+ let currentLaw = panLaw;
1336
+ let rampScheduled = false;
1337
+ const targets = () => {
1338
+ const matrix = panMatrix(currentPan, currentLaw);
1339
+ return [
1340
+ [ll, matrix.ll],
1341
+ [lr, matrix.lr],
1342
+ [rl, matrix.rl],
1343
+ [rr, matrix.rr]
1344
+ ];
1345
+ };
1338
1346
  const apply = () => {
1339
- const matrix = panMatrix(currentPan, currentChannelCount);
1340
- ll.gain.value = matrix.ll;
1341
- lr.gain.value = matrix.lr;
1342
- rl.gain.value = matrix.rl;
1343
- rr.gain.value = matrix.rr;
1347
+ for (const [node, value] of targets()) {
1348
+ if (rampScheduled) node.gain.cancelScheduledValues(context.currentTime);
1349
+ node.gain.value = value;
1350
+ }
1351
+ rampScheduled = false;
1352
+ };
1353
+ const ramp = () => {
1354
+ const now = context.currentTime;
1355
+ for (const [node, value] of targets()) {
1356
+ node.gain.cancelScheduledValues(now);
1357
+ node.gain.setValueAtTime(node.gain.value, now);
1358
+ node.gain.linearRampToValueAtTime(value, now + PAN_LAW_RAMP_SECONDS);
1359
+ }
1360
+ rampScheduled = true;
1344
1361
  };
1345
1362
  apply();
1346
1363
  upmix.connect(split);
@@ -1359,9 +1376,10 @@ function createPanStage(context, pan, sourceChannelCount) {
1359
1376
  currentPan = value;
1360
1377
  apply();
1361
1378
  },
1362
- setSourceChannelCount: (value) => {
1363
- currentChannelCount = value;
1364
- apply();
1379
+ setPanLaw: (value) => {
1380
+ if (value === currentLaw) return;
1381
+ currentLaw = value;
1382
+ ramp();
1365
1383
  },
1366
1384
  dispose: () => {
1367
1385
  for (const node of [upmix, split, ll, lr, rl, rr, merge]) {
@@ -1375,6 +1393,26 @@ function createPanStage(context, pan, sourceChannelCount) {
1375
1393
  };
1376
1394
  }
1377
1395
 
1396
+ // src/panLaw.ts
1397
+ var DEFAULT_PAN_LAW = "auto";
1398
+ function isDecidedPanLaw(value) {
1399
+ return value === "mono" || value === "stereo";
1400
+ }
1401
+ function audioPanLaw(track) {
1402
+ let law = null;
1403
+ for (const clip of track.clips) {
1404
+ const channels = clip.audioBuffer?.numberOfChannels;
1405
+ if (channels === void 0) continue;
1406
+ if (channels >= 2) return "stereo";
1407
+ law = "mono";
1408
+ }
1409
+ return law;
1410
+ }
1411
+ function trackPanLaw(track) {
1412
+ if (isDecidedPanLaw(track.panLaw)) return track.panLaw;
1413
+ return audioPanLaw(track) ?? "mono";
1414
+ }
1415
+
1378
1416
  // src/valueSource.ts
1379
1417
  function silentMeterLevels(channelCount) {
1380
1418
  const count = Math.max(0, Math.floor(channelCount));
@@ -1610,7 +1648,8 @@ function audioTrack(options) {
1610
1648
  ...base,
1611
1649
  id: options.id || base.id,
1612
1650
  clips: [clip],
1613
- renderMode: options.renderMode
1651
+ renderMode: options.renderMode,
1652
+ ...options.panLaw !== void 0 && { panLaw: options.panLaw }
1614
1653
  };
1615
1654
  return track;
1616
1655
  }
@@ -1780,6 +1819,7 @@ function createEffectInstance(type, audioContext, params = {}) {
1780
1819
  export {
1781
1820
  ANNOTATION_LINK_THRESHOLD_TICKS,
1782
1821
  DEFAULT_ANNOTATION_SHORTCUTS,
1822
+ DEFAULT_PAN_LAW,
1783
1823
  DEFAULT_SPECTROGRAM_COLOR_MAP,
1784
1824
  InteractionState,
1785
1825
  LINK_THRESHOLD,
@@ -1787,6 +1827,7 @@ export {
1787
1827
  METER_PEAK_DECAY,
1788
1828
  MIN_ANNOTATION_DURATION,
1789
1829
  MIN_PIXELS_PER_UNIT,
1830
+ PAN_LAW_RAMP_SECONDS,
1790
1831
  PPQN,
1791
1832
  SPECTROGRAM_DEFAULTS,
1792
1833
  TRACK_VIEW_FIELDS,
@@ -1798,9 +1839,9 @@ export {
1798
1839
  applyFadeOut,
1799
1840
  assertTrackKind,
1800
1841
  audibleLatencySamples,
1842
+ audioPanLaw,
1801
1843
  audioTrack,
1802
1844
  buildSpectrogramCanvasId,
1803
- calculateDuration,
1804
1845
  carveClipRange,
1805
1846
  clipDurationTime,
1806
1847
  clipEndTime,
@@ -1837,6 +1878,7 @@ export {
1837
1878
  getClipsInRange,
1838
1879
  getEffectDefinitions,
1839
1880
  handleKeyboardEvent,
1881
+ isDecidedPanLaw,
1840
1882
  isLoadingClip,
1841
1883
  keyBelongsToFocusedControl,
1842
1884
  linearCurve,
@@ -1872,6 +1914,7 @@ export {
1872
1914
  ticksToSamples,
1873
1915
  trackChannelCount,
1874
1916
  trackKind,
1917
+ trackPanLaw,
1875
1918
  unregisterEffect,
1876
1919
  updateAnnotationBoundaries,
1877
1920
  watchMicrophoneDevices