@arraypress/waveform-player 1.14.0 → 1.15.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/index.d.ts CHANGED
@@ -78,7 +78,8 @@ export interface WaveformPlayerOptions {
78
78
  src?: string;
79
79
  /** Waveform height in pixels. @default 60 */
80
80
  height?: number;
81
- /** Number of peak samples to extract when decoding. @default 200 */
81
+ /** Source peak resolution for live decode (ignored when `waveform` peaks are
82
+ * supplied); resampled to fit the visible bars. @default 1800 */
82
83
  samples?: number;
83
84
  /** `<audio>` preload hint. @default 'metadata' */
84
85
  preload?: AudioPreload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arraypress/waveform-player",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "Lightweight, customizable audio player with waveform visualization",
5
5
  "type": "module",
6
6
  "types": "./index.d.ts",
package/src/js/audio.js CHANGED
@@ -10,11 +10,12 @@ import {clamp} from './utils.js';
10
10
  * Extract peaks from a decoded audio buffer for waveform visualization.
11
11
  *
12
12
  * Divides the buffer into `samples` equal-width windows and, within each
13
- * window, finds the largest absolute amplitude. To keep large files fast the
14
- * inner loop strides through every 10th frame (`sampleStep`) rather than
15
- * inspecting every frame. Across multiple channels the per-window peaks are
16
- * merged by taking the loudest channel, then the whole array is normalized so
17
- * the maximum peak becomes 1 (a silent buffer is returned unscaled).
13
+ * window, finds the largest absolute amplitude by inspecting every frame (so
14
+ * transients are never missed and the shape is stable across sample counts —
15
+ * matching WaveformGen's offline output). Across multiple channels the
16
+ * per-window peaks are merged by taking the loudest channel, then the whole
17
+ * array is normalized so the maximum peak becomes 1 (a silent buffer is
18
+ * returned unscaled).
18
19
  *
19
20
  * @param {AudioBuffer} buffer - Decoded audio buffer to analyse.
20
21
  * @param {number} [samples=200] - Number of peak windows (output array length).
@@ -22,7 +23,6 @@ import {clamp} from './utils.js';
22
23
  */
23
24
  export function extractPeaks(buffer, samples = 200) {
24
25
  const sampleSize = buffer.length / samples;
25
- const sampleStep = ~~(sampleSize / 10) || 1;
26
26
  const channels = buffer.numberOfChannels;
27
27
  const peaks = [];
28
28
 
@@ -36,7 +36,12 @@ export function extractPeaks(buffer, samples = 200) {
36
36
  let min = 0;
37
37
  let max = 0;
38
38
 
39
- for (let j = start; j < end; j += sampleStep) {
39
+ // Scan EVERY frame in the window. Previously this stepped by
40
+ // sampleSize/10 (~10 samples/window) for speed, but that misses
41
+ // transients and makes the shape change with the sample count.
42
+ // decodeAudioData dominates the cost, so a full scan is worth it —
43
+ // and it now matches WaveformGen's offline output exactly.
44
+ for (let j = start; j < end; j++) {
40
45
  const value = chan[j];
41
46
  if (value > max) max = value;
42
47
  if (value < min) min = value;
package/src/js/themes.js CHANGED
@@ -152,10 +152,12 @@ export const DEFAULT_OPTIONS = {
152
152
  // Core settings
153
153
  url: '',
154
154
  height: 64,
155
- // Source peak resolution. The drawer resamples these to fit
156
- // canvasWidth / (barWidth + barSpacing) bars, so this is fidelity headroom,
157
- // not the visible bar count.
158
- samples: 256,
155
+ // Source peak resolution for LIVE decode (ignored when peaks are supplied).
156
+ // The drawer resamples these to fit canvasWidth / (barWidth + barSpacing)
157
+ // bars, so this is fidelity headroom, not the visible bar count. 1800 (the
158
+ // SoundCloud/WaveformGen figure) keeps wide / high-DPI waveforms crisp; the
159
+ // every-frame scan means a higher value costs no extra extraction time.
160
+ samples: 1800,
159
161
  preload: 'metadata',
160
162
 
161
163
  // Audio mode — 'self' = player owns the <audio> element (default, current