wavesurfer.js 7.0.0-beta.8 → 7.0.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.
Files changed (69) hide show
  1. package/README.md +65 -33
  2. package/dist/base-plugin.d.ts +5 -2
  3. package/dist/base-plugin.js +1 -0
  4. package/dist/decoder.js +17 -6
  5. package/dist/draggable.js +15 -10
  6. package/dist/fetcher.d.ts +2 -2
  7. package/dist/fetcher.js +14 -3
  8. package/dist/player.d.ts +3 -3
  9. package/dist/player.js +12 -10
  10. package/dist/plugins/base-plugin.d.ts +16 -0
  11. package/dist/plugins/decoder.d.ts +9 -0
  12. package/dist/plugins/draggable.d.ts +1 -0
  13. package/dist/plugins/envelope.cjs +1 -0
  14. package/dist/plugins/envelope.d.ts +12 -4
  15. package/dist/plugins/envelope.esm.js +1 -0
  16. package/dist/plugins/envelope.js +29 -9
  17. package/dist/plugins/envelope.min.js +1 -1
  18. package/dist/plugins/event-emitter.d.ts +19 -0
  19. package/dist/plugins/fetcher.d.ts +5 -0
  20. package/dist/plugins/hover.cjs +1 -0
  21. package/dist/plugins/hover.d.ts +35 -0
  22. package/dist/plugins/hover.esm.js +1 -0
  23. package/dist/plugins/hover.js +101 -0
  24. package/dist/plugins/hover.min.js +1 -0
  25. package/dist/plugins/minimap.cjs +1 -0
  26. package/dist/plugins/minimap.d.ts +2 -2
  27. package/dist/plugins/minimap.esm.js +1 -0
  28. package/dist/plugins/minimap.js +8 -13
  29. package/dist/plugins/minimap.min.js +1 -1
  30. package/dist/plugins/player.d.ts +45 -0
  31. package/dist/plugins/plugins/envelope.d.ts +79 -0
  32. package/dist/plugins/plugins/hover.d.ts +35 -0
  33. package/dist/plugins/plugins/minimap.d.ts +39 -0
  34. package/dist/plugins/plugins/record.d.ts +31 -0
  35. package/dist/plugins/plugins/regions.d.ts +115 -0
  36. package/dist/plugins/plugins/spectrogram.d.ts +76 -0
  37. package/dist/plugins/plugins/timeline.d.ts +47 -0
  38. package/dist/plugins/record.cjs +1 -0
  39. package/dist/plugins/record.d.ts +9 -4
  40. package/dist/plugins/record.esm.js +1 -0
  41. package/dist/plugins/record.js +77 -65
  42. package/dist/plugins/record.min.js +1 -1
  43. package/dist/plugins/regions.cjs +1 -0
  44. package/dist/plugins/regions.d.ts +25 -4
  45. package/dist/plugins/regions.esm.js +1 -0
  46. package/dist/plugins/regions.js +60 -60
  47. package/dist/plugins/regions.min.js +1 -1
  48. package/dist/plugins/renderer.d.ts +44 -0
  49. package/dist/plugins/spectrogram.cjs +1 -0
  50. package/dist/plugins/spectrogram.d.ts +10 -3
  51. package/dist/plugins/spectrogram.esm.js +1 -0
  52. package/dist/plugins/spectrogram.js +166 -20
  53. package/dist/plugins/spectrogram.min.js +1 -1
  54. package/dist/plugins/timeline.cjs +1 -0
  55. package/dist/plugins/timeline.d.ts +5 -3
  56. package/dist/plugins/timeline.esm.js +1 -0
  57. package/dist/plugins/timeline.js +27 -21
  58. package/dist/plugins/timeline.min.js +1 -1
  59. package/dist/plugins/timer.d.ts +11 -0
  60. package/dist/plugins/wavesurfer.d.ts +156 -0
  61. package/dist/renderer.js +25 -11
  62. package/dist/wavesurfer.cjs +1 -0
  63. package/dist/wavesurfer.d.ts +7 -4
  64. package/dist/wavesurfer.esm.js +1 -0
  65. package/dist/wavesurfer.js +74 -42
  66. package/dist/wavesurfer.min.js +1 -1
  67. package/package.json +21 -22
  68. package/dist/plugins/spectrogram-fft.d.ts +0 -9
  69. package/dist/plugins/spectrogram-fft.js +0 -150
@@ -1,150 +0,0 @@
1
- // @ts-nocheck
2
- /**
3
- * Calculate FFT - Based on https://github.com/corbanbrook/dsp.js
4
- *
5
- * @param {Number} bufferSize Buffer size
6
- * @param {Number} sampleRate Sample rate
7
- * @param {Function} windowFunc Window function
8
- * @param {Number} alpha Alpha channel
9
- */
10
- export default function FFT(bufferSize, sampleRate, windowFunc, alpha) {
11
- this.bufferSize = bufferSize;
12
- this.sampleRate = sampleRate;
13
- this.bandwidth = (2 / bufferSize) * (sampleRate / 2);
14
- this.sinTable = new Float32Array(bufferSize);
15
- this.cosTable = new Float32Array(bufferSize);
16
- this.windowValues = new Float32Array(bufferSize);
17
- this.reverseTable = new Uint32Array(bufferSize);
18
- this.peakBand = 0;
19
- this.peak = 0;
20
- var i;
21
- switch (windowFunc) {
22
- case 'bartlett':
23
- for (i = 0; i < bufferSize; i++) {
24
- this.windowValues[i] = (2 / (bufferSize - 1)) * ((bufferSize - 1) / 2 - Math.abs(i - (bufferSize - 1) / 2));
25
- }
26
- break;
27
- case 'bartlettHann':
28
- for (i = 0; i < bufferSize; i++) {
29
- this.windowValues[i] =
30
- 0.62 - 0.48 * Math.abs(i / (bufferSize - 1) - 0.5) - 0.38 * Math.cos((Math.PI * 2 * i) / (bufferSize - 1));
31
- }
32
- break;
33
- case 'blackman':
34
- alpha = alpha || 0.16;
35
- for (i = 0; i < bufferSize; i++) {
36
- this.windowValues[i] =
37
- (1 - alpha) / 2 -
38
- 0.5 * Math.cos((Math.PI * 2 * i) / (bufferSize - 1)) +
39
- (alpha / 2) * Math.cos((4 * Math.PI * i) / (bufferSize - 1));
40
- }
41
- break;
42
- case 'cosine':
43
- for (i = 0; i < bufferSize; i++) {
44
- this.windowValues[i] = Math.cos((Math.PI * i) / (bufferSize - 1) - Math.PI / 2);
45
- }
46
- break;
47
- case 'gauss':
48
- alpha = alpha || 0.25;
49
- for (i = 0; i < bufferSize; i++) {
50
- this.windowValues[i] = Math.pow(Math.E, -0.5 * Math.pow((i - (bufferSize - 1) / 2) / ((alpha * (bufferSize - 1)) / 2), 2));
51
- }
52
- break;
53
- case 'hamming':
54
- for (i = 0; i < bufferSize; i++) {
55
- this.windowValues[i] = 0.54 - 0.46 * Math.cos((Math.PI * 2 * i) / (bufferSize - 1));
56
- }
57
- break;
58
- case 'hann':
59
- case undefined:
60
- for (i = 0; i < bufferSize; i++) {
61
- this.windowValues[i] = 0.5 * (1 - Math.cos((Math.PI * 2 * i) / (bufferSize - 1)));
62
- }
63
- break;
64
- case 'lanczoz':
65
- for (i = 0; i < bufferSize; i++) {
66
- this.windowValues[i] =
67
- Math.sin(Math.PI * ((2 * i) / (bufferSize - 1) - 1)) / (Math.PI * ((2 * i) / (bufferSize - 1) - 1));
68
- }
69
- break;
70
- case 'rectangular':
71
- for (i = 0; i < bufferSize; i++) {
72
- this.windowValues[i] = 1;
73
- }
74
- break;
75
- case 'triangular':
76
- for (i = 0; i < bufferSize; i++) {
77
- this.windowValues[i] = (2 / bufferSize) * (bufferSize / 2 - Math.abs(i - (bufferSize - 1) / 2));
78
- }
79
- break;
80
- default:
81
- throw Error("No such window function '" + windowFunc + "'");
82
- }
83
- var limit = 1;
84
- var bit = bufferSize >> 1;
85
- var i;
86
- while (limit < bufferSize) {
87
- for (i = 0; i < limit; i++) {
88
- this.reverseTable[i + limit] = this.reverseTable[i] + bit;
89
- }
90
- limit = limit << 1;
91
- bit = bit >> 1;
92
- }
93
- for (i = 0; i < bufferSize; i++) {
94
- this.sinTable[i] = Math.sin(-Math.PI / i);
95
- this.cosTable[i] = Math.cos(-Math.PI / i);
96
- }
97
- this.calculateSpectrum = function (buffer) {
98
- // Locally scope variables for speed up
99
- var bufferSize = this.bufferSize, cosTable = this.cosTable, sinTable = this.sinTable, reverseTable = this.reverseTable, real = new Float32Array(bufferSize), imag = new Float32Array(bufferSize), bSi = 2 / this.bufferSize, sqrt = Math.sqrt, rval, ival, mag, spectrum = new Float32Array(bufferSize / 2);
100
- var k = Math.floor(Math.log(bufferSize) / Math.LN2);
101
- if (Math.pow(2, k) !== bufferSize) {
102
- throw 'Invalid buffer size, must be a power of 2.';
103
- }
104
- if (bufferSize !== buffer.length) {
105
- throw ('Supplied buffer is not the same size as defined FFT. FFT Size: ' +
106
- bufferSize +
107
- ' Buffer Size: ' +
108
- buffer.length);
109
- }
110
- var halfSize = 1, phaseShiftStepReal, phaseShiftStepImag, currentPhaseShiftReal, currentPhaseShiftImag, off, tr, ti, tmpReal;
111
- for (var i = 0; i < bufferSize; i++) {
112
- real[i] = buffer[reverseTable[i]] * this.windowValues[reverseTable[i]];
113
- imag[i] = 0;
114
- }
115
- while (halfSize < bufferSize) {
116
- phaseShiftStepReal = cosTable[halfSize];
117
- phaseShiftStepImag = sinTable[halfSize];
118
- currentPhaseShiftReal = 1;
119
- currentPhaseShiftImag = 0;
120
- for (var fftStep = 0; fftStep < halfSize; fftStep++) {
121
- var i = fftStep;
122
- while (i < bufferSize) {
123
- off = i + halfSize;
124
- tr = currentPhaseShiftReal * real[off] - currentPhaseShiftImag * imag[off];
125
- ti = currentPhaseShiftReal * imag[off] + currentPhaseShiftImag * real[off];
126
- real[off] = real[i] - tr;
127
- imag[off] = imag[i] - ti;
128
- real[i] += tr;
129
- imag[i] += ti;
130
- i += halfSize << 1;
131
- }
132
- tmpReal = currentPhaseShiftReal;
133
- currentPhaseShiftReal = tmpReal * phaseShiftStepReal - currentPhaseShiftImag * phaseShiftStepImag;
134
- currentPhaseShiftImag = tmpReal * phaseShiftStepImag + currentPhaseShiftImag * phaseShiftStepReal;
135
- }
136
- halfSize = halfSize << 1;
137
- }
138
- for (var i = 0, N = bufferSize / 2; i < N; i++) {
139
- rval = real[i];
140
- ival = imag[i];
141
- mag = bSi * sqrt(rval * rval + ival * ival);
142
- if (mag > this.peak) {
143
- this.peakBand = i;
144
- this.peak = mag;
145
- }
146
- spectrum[i] = mag;
147
- }
148
- return spectrum;
149
- };
150
- }