wavesurfer.js 6.0.3 → 6.0.4
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/CHANGES.md +8 -0
- package/dist/plugin/wavesurfer.cursor.js +1 -1
- package/dist/plugin/wavesurfer.cursor.min.js +1 -1
- package/dist/plugin/wavesurfer.elan.js +1 -1
- package/dist/plugin/wavesurfer.elan.min.js +1 -1
- package/dist/plugin/wavesurfer.markers.js +1 -1
- package/dist/plugin/wavesurfer.markers.min.js +1 -1
- package/dist/plugin/wavesurfer.mediasession.js +1 -1
- package/dist/plugin/wavesurfer.mediasession.min.js +1 -1
- package/dist/plugin/wavesurfer.microphone.js +1 -1
- package/dist/plugin/wavesurfer.microphone.min.js +1 -1
- package/dist/plugin/wavesurfer.minimap.js +1 -1
- package/dist/plugin/wavesurfer.minimap.min.js +1 -1
- package/dist/plugin/wavesurfer.playhead.js +1 -1
- package/dist/plugin/wavesurfer.playhead.min.js +1 -1
- package/dist/plugin/wavesurfer.regions.js +1 -1
- package/dist/plugin/wavesurfer.regions.min.js +1 -1
- package/dist/plugin/wavesurfer.spectrogram.js +28 -9
- package/dist/plugin/wavesurfer.spectrogram.js.map +1 -1
- package/dist/plugin/wavesurfer.spectrogram.min.js +2 -2
- package/dist/plugin/wavesurfer.spectrogram.min.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.js +5 -3
- package/dist/plugin/wavesurfer.timeline.js.map +1 -1
- package/dist/plugin/wavesurfer.timeline.min.js +2 -2
- package/dist/plugin/wavesurfer.timeline.min.js.map +1 -1
- package/dist/wavesurfer-html-init.js +1 -1
- package/dist/wavesurfer-html-init.min.js +1 -1
- package/dist/wavesurfer.js +2 -2
- package/dist/wavesurfer.min.js +2 -2
- package/package.json +3 -3
- package/src/plugin/spectrogram/index.js +23 -10
- package/src/plugin/timeline/index.js +7 -1
|
@@ -21,6 +21,9 @@ import FFT from './fft';
|
|
|
21
21
|
* @property {number} pixelRatio=wavesurfer.params.pixelRatio to control the
|
|
22
22
|
* size of the spectrogram in relation with its canvas. 1 = Draw on the whole
|
|
23
23
|
* canvas. 2 = Draw on a quarter (1/2 the length and 1/2 the width)
|
|
24
|
+
* @property {number} frequencyMin=0 Min frequency to scale spectrogram.
|
|
25
|
+
* @property {number} frequencyMax=12000 Max frequency to scale spectrogram.
|
|
26
|
+
* Set this to samplerate/2 to draw whole range of spectrogram.
|
|
24
27
|
* @property {?boolean} deferInit Set to true to manually call
|
|
25
28
|
* `initPlugin('spectrogram')`
|
|
26
29
|
* @property {?number[][]} colorMap A 256 long array of 4-element arrays.
|
|
@@ -132,6 +135,11 @@ export default class SpectrogramPlugin {
|
|
|
132
135
|
this.splitChannels = params.splitChannels;
|
|
133
136
|
this.channels = this.splitChannels ? ws.backend.buffer.numberOfChannels : 1;
|
|
134
137
|
|
|
138
|
+
// Getting file's original samplerate is difficult(#1248).
|
|
139
|
+
// So set 12kHz default to render like wavesurfer.js 5.x.
|
|
140
|
+
this.frequencyMin = params.frequencyMin || 0;
|
|
141
|
+
this.frequencyMax = params.frequencyMax || 12000;
|
|
142
|
+
|
|
135
143
|
this.createWrapper();
|
|
136
144
|
this.createCanvas();
|
|
137
145
|
this.render();
|
|
@@ -261,6 +269,9 @@ export default class SpectrogramPlugin {
|
|
|
261
269
|
const spectrCc = my.spectrCc;
|
|
262
270
|
const height = my.height;
|
|
263
271
|
const width = my.width;
|
|
272
|
+
const freqFrom = my.buffer.sampleRate / 2;
|
|
273
|
+
const freqMin = my.frequencyMin;
|
|
274
|
+
const freqMax = my.frequencyMax;
|
|
264
275
|
|
|
265
276
|
if (!spectrCc) {
|
|
266
277
|
return;
|
|
@@ -268,7 +279,7 @@ export default class SpectrogramPlugin {
|
|
|
268
279
|
|
|
269
280
|
for (let c = 0; c < frequenciesData.length; c++) { // for each channel
|
|
270
281
|
const pixels = my.resample(frequenciesData[c]);
|
|
271
|
-
const imageData =
|
|
282
|
+
const imageData = new ImageData(width, height);
|
|
272
283
|
|
|
273
284
|
for (let i = 0; i < pixels.length; i++) {
|
|
274
285
|
for (let j = 0; j < pixels[i].length; j++) {
|
|
@@ -281,8 +292,15 @@ export default class SpectrogramPlugin {
|
|
|
281
292
|
}
|
|
282
293
|
}
|
|
283
294
|
|
|
284
|
-
// stack spectrograms
|
|
285
|
-
|
|
295
|
+
// scale and stack spectrograms
|
|
296
|
+
createImageBitmap(imageData).then(renderer =>
|
|
297
|
+
spectrCc.drawImage(renderer,
|
|
298
|
+
0, height * (1 - freqMax / freqFrom), // source x, y
|
|
299
|
+
width, height * (freqMax - freqMin) / freqFrom, // source width, height
|
|
300
|
+
0, height * c, // destination x, y
|
|
301
|
+
width, height // destination width, height
|
|
302
|
+
)
|
|
303
|
+
);
|
|
286
304
|
}
|
|
287
305
|
}
|
|
288
306
|
|
|
@@ -381,10 +399,8 @@ export default class SpectrogramPlugin {
|
|
|
381
399
|
const bgWidth = 55;
|
|
382
400
|
const getMaxY = frequenciesHeight || 512;
|
|
383
401
|
const labelIndex = 5 * (getMaxY / 256);
|
|
384
|
-
const freqStart =
|
|
385
|
-
const step =
|
|
386
|
-
(this.wavesurfer.backend.ac.sampleRate / 2 - freqStart) /
|
|
387
|
-
labelIndex;
|
|
402
|
+
const freqStart = this.frequencyMin;
|
|
403
|
+
const step = (this.frequencyMax - freqStart) / labelIndex;
|
|
388
404
|
|
|
389
405
|
// prepare canvas element for labels
|
|
390
406
|
const ctx = this.labelsEl.getContext('2d');
|
|
@@ -408,9 +424,6 @@ export default class SpectrogramPlugin {
|
|
|
408
424
|
ctx.textBaseline = 'middle';
|
|
409
425
|
|
|
410
426
|
const freq = freqStart + step * i;
|
|
411
|
-
const index = Math.round(
|
|
412
|
-
(freq / (this.sampleRate / 2)) * this.fftSamples
|
|
413
|
-
);
|
|
414
427
|
const label = this.freqType(freq);
|
|
415
428
|
const units = this.unitType(freq);
|
|
416
429
|
const yLabelOffset = 2;
|
|
@@ -371,7 +371,13 @@ export default class TimelinePlugin {
|
|
|
371
371
|
// build an array of position data with index, second and pixel data,
|
|
372
372
|
// this is then used multiple times below
|
|
373
373
|
const positioning = [];
|
|
374
|
-
|
|
374
|
+
|
|
375
|
+
// render until end in case we have a negative offset
|
|
376
|
+
const renderSeconds = (this.params.offset < 0)
|
|
377
|
+
? totalSeconds - this.params.offset
|
|
378
|
+
: totalSeconds;
|
|
379
|
+
|
|
380
|
+
for (i = 0; i < renderSeconds / timeInterval; i++) {
|
|
375
381
|
positioning.push([i, curSeconds, curPixel]);
|
|
376
382
|
curSeconds += timeInterval;
|
|
377
383
|
curPixel += pixelsPerSecond * timeInterval;
|