wavesurfer.js 7.0.0-beta.2 → 7.0.0-beta.3

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/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2012-2023, katspaugh and contributors
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,46 +1,65 @@
1
- # <img src="https://user-images.githubusercontent.com/381895/226091100-f5567a28-7736-4d37-8f84-e08f297b7e1a.png" alt="logo" height="60" valign="middle" /> wavesurfer.ts
1
+ # <img src="https://user-images.githubusercontent.com/381895/226091100-f5567a28-7736-4d37-8f84-e08f297b7e1a.png" alt="logo" height="60" valign="middle" /> wavesurfer.js
2
2
 
3
3
  ![npm](https://img.shields.io/npm/v/wavesurfer.js/beta)
4
4
 
5
- A rewrite of [wavesufer.js](https://github.com/wavesurfer-js/wavesurfer.js) in TypeScript with better performance.
5
+ ## New TypeScript version
6
6
 
7
- <img alt="screenshot" src="https://user-images.githubusercontent.com/381895/225539680-fc724acd-8657-458e-a558-ff1c6758ba30.png" width="800" />
7
+ wavesurfer.js v7 beta is a TypeScript rewrite of wavesurfer.js that brings several improvements:
8
+
9
+ * Typed API for better development experience
10
+ * Enhanced decoding and rendering performance
11
+ * New and improved plugins
12
+
13
+ <img width="674" alt="Screenshot" src="https://github.com/katspaugh/wavesurfer.ts/assets/381895/cde5fe51-be8a-46ff-934e-1d76a827b8bc">
14
+
15
+ ---
16
+
17
+ ℹ️ Looking for the old stable version? V6 is here: https://github.com/katspaugh/wavesurfer.js/tree/master
18
+
19
+ ---
8
20
 
9
21
  Try it out:
10
- ```
22
+
23
+ ```bash
11
24
  npm install --save wavesurfer.js@beta
12
25
  ```
26
+ ```js
27
+ import WaveSurfer from 'wavesurfer.js'
28
+ ```
13
29
 
14
- Alternatively, import from a CDN or a local file as an ES6 module:
30
+ Alternatively, import it from a CDN as a ES6 module directly in the browser:
15
31
 
16
- ```
17
- import WaveSurfer from 'https://unpkg.com/wavesurfer.js@beta'
18
- ```
32
+ ```html
33
+ <script type="module">
34
+ import WaveSurfer from 'https://unpkg.com/wavesurfer.js@beta'
19
35
 
20
- Or, as a UMD script tag which exposes `WaveSurfer` as a global variable:
36
+ const wavesurfer = WaveSurfer.create({ ... })
37
+ </script>
21
38
  ```
39
+
40
+ Or, as a UMD script tag which exports the library as a global `WaveSurfer` variable:
41
+ ```html
22
42
  <script src="https://unpkg.com/wavesurfer.js@beta/dist/wavesurfer.min.js"></script>
23
43
  ```
24
44
 
25
45
  To import a plugin, e.g. the Timeline plugin:
26
- ```
46
+ ```js
27
47
  import Timeline from 'https://unpkg.com/wavesurfer.js@beta/dist/plugins/timeline.js'
28
48
  ```
29
49
 
30
50
  TypeScript types are included in the package, so there's no need to install `@types/wavesurfer.js`.
31
51
 
32
- ## Why upgrade to wavesurfer.ts?
52
+ See more [examples](https://wavesurfer.pages.dev/examples/).
33
53
 
34
- wavesurfer.js v7 (aka wavesurfer.ts) brings several improvements:
54
+ ## Documentation
35
55
 
36
- * Typed API for better development experience
37
- * Enhanced decoding and rendering performance
38
- * New and improved plugins
56
+ See the documentation on wavesurfer.js [methods](https://wavesurfer-ts.pages.dev/docs/classes/wavesurfer.WaveSurfer), [options](https://wavesurfer-ts.pages.dev/docs/types/wavesurfer.WaveSurferOptions) and [events](https://wavesurfer-ts.pages.dev/docs/types/wavesurfer.WaveSurferEvents) on our website.
39
57
 
40
58
  ## Plugins
59
+
41
60
  The "official" plugins have been completely rewritten and enhanced:
42
61
 
43
- * [Regions](https://wavesurfer.pages.dev/examples/#regions.js) – now also replaces the old Markers plugin
62
+ * [Regions](https://wavesurfer.pages.dev/examples/#regions.js) – visual overlays and markers for regions of audio
44
63
  * [Timeline](https://wavesurfer.pages.dev/examples/#timeline.js) – displays notches and time labels below the waveform
45
64
  * [Minimap](https://wavesurfer.pages.dev/examples/#minimap.js) – a small waveform that serves as a scrollbar for the main waveform
46
65
  * [Envelope](https://wavesurfer.pages.dev/examples/#envelope.js) – a graphical interface to add fade-in and -out effects and control volume
@@ -68,10 +87,7 @@ You can see which elements you can style in the DOM inspector – they will have
68
87
 
69
88
  See [this example](https://wavesurfer.pages.dev/examples/#styling.js) for play around with styling.
70
89
 
71
- ## Documentation
72
- See the documentation on wavesurfer.js [methods](https://wavesurfer-ts.pages.dev/docs/classes/wavesurfer.WaveSurfer), [options](https://wavesurfer-ts.pages.dev/docs/types/wavesurfer.WaveSurferOptions) and [events](https://wavesurfer-ts.pages.dev/docs/types/wavesurfer.WaveSurferEvents) on our website.
73
-
74
- ## Migrating from v6 and lower
90
+ ## Migrating from v6
75
91
 
76
92
  Most options, events, and methods are similar to those in previous versions.
77
93
 
@@ -93,6 +109,10 @@ Most options, events, and methods are similar to those in previous versions.
93
109
 
94
110
  See the complete [documentation of the new API](https://wavesurfer-ts.pages.dev/docs/modules/wavesurfer).
95
111
 
112
+ ## Questions
113
+
114
+ Have a question about integrating wavesurfer.js on your website? Feel free to ask in our forum: https://github.com/wavesurfer-js/wavesurfer.js/discussions/categories/q-a
115
+
96
116
  ## Development
97
117
 
98
118
  To get started with development, follow these steps:
@@ -109,11 +129,20 @@ yarn
109
129
  yarn start
110
130
  ```
111
131
 
112
- This command will open http://localhost:9090/tutorial in your browser with live reload, allowing you to see the changes as you develop.
132
+ This command will open http://localhost:9090 in your browser with live reload, allowing you to see the changes as you develop.
133
+
134
+ ## Tests
135
+
136
+ The tests are written in the Cypress framework. They are a mix of e2e and visual regression tests.
137
+ To run the test suite locally:
138
+
139
+ ```
140
+ yarn cypress
141
+ ```
113
142
 
114
143
  ## Feedback
115
144
 
116
- We appreciate your feedback and contributions! Join the conversation and share your thoughts here: https://github.com/wavesurfer-js/wavesurfer.js/discussions/2684
145
+ We appreciate your feedback and contributions! Join the conversation and share your thoughts here: https://github.com/wavesurfer-js/wavesurfer.js/discussions/2789
117
146
 
118
147
  If you encounter any issues or have suggestions for improvements, please don't hesitate to open an issue or submit a pull request on the GitHub repository.
119
148
 
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Calculate FFT - Based on https://github.com/corbanbrook/dsp.js
3
+ *
4
+ * @param {Number} bufferSize Buffer size
5
+ * @param {Number} sampleRate Sample rate
6
+ * @param {Function} windowFunc Window function
7
+ * @param {Number} alpha Alpha channel
8
+ */
9
+ export default function FFT(bufferSize: any, sampleRate: any, windowFunc: any, alpha: any): void;
@@ -0,0 +1,150 @@
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
+ }
@@ -19,7 +19,7 @@
19
19
  */
20
20
  // @ts-nocheck
21
21
  import BasePlugin from '../base-plugin.js';
22
- import FFT from './spectrogram-fft.mjs';
22
+ import FFT from './spectrogram-fft.js';
23
23
  export default class SpectrogramPlugin extends BasePlugin {
24
24
  static create(options) {
25
25
  return new SpectrogramPlugin(options || {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wavesurfer.js",
3
- "version": "7.0.0-beta.2",
3
+ "version": "7.0.0-beta.3",
4
4
  "license": "BSD-3-Clause",
5
5
  "author": "katspaugh",
6
6
  "homepage": "https://wavesurfer-js.org",
@@ -17,7 +17,7 @@
17
17
  "main": "dist/wavesurfer.js",
18
18
  "module": "dist/wavesurfer.js",
19
19
  "types": "dist/wavesurfer.d.ts",
20
- "browser": "dist/wavesurfer.min.js",
20
+ "browser": "dist/wavesurfer.js",
21
21
  "exports": {
22
22
  ".": {
23
23
  "import": "dist/wavesurfer.js",