beatd-js 0.0.0-stage → 0.0.1
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.d.ts +24 -0
- package/dist/index.js +34 -0
- package/dist/wasm/README.md +142 -0
- package/dist/wasm/beatd.d.ts +71 -0
- package/dist/wasm/beatd.js +321 -0
- package/dist/wasm/beatd_bg.wasm +0 -0
- package/dist/wasm/beatd_bg.wasm.d.ts +24 -0
- package/dist/wasm/package.json +29 -0
- package/package.json +48 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface AnalyzerOptions {
|
|
2
|
+
sampleRate: number;
|
|
3
|
+
}
|
|
4
|
+
export declare class Analyzer {
|
|
5
|
+
private readonly inner;
|
|
6
|
+
constructor(options: AnalyzerOptions);
|
|
7
|
+
push(samples: Float32Array): boolean;
|
|
8
|
+
sampleRate(): number;
|
|
9
|
+
level(): number;
|
|
10
|
+
bpm(): number;
|
|
11
|
+
spectrum(): Float32Array;
|
|
12
|
+
waveform(): Float32Array;
|
|
13
|
+
beatOffsets(bpm: number): Float32Array;
|
|
14
|
+
bandLevel(low: number, high: number): number;
|
|
15
|
+
bpmRangeMin(): number;
|
|
16
|
+
setBpmRangeMin(min: number): void;
|
|
17
|
+
setBpmEnabled(enabled: boolean): void;
|
|
18
|
+
setSpectrumGain(gain: number): void;
|
|
19
|
+
setSpectrumCompression(compression: number): void;
|
|
20
|
+
reset(): void;
|
|
21
|
+
dispose(): void;
|
|
22
|
+
[Symbol.dispose](): void;
|
|
23
|
+
}
|
|
24
|
+
export declare function createAnalyzer(options: AnalyzerOptions): Analyzer;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import init, { Analyzer as WasmAnalyzer } from '../dist/wasm/beatd.js';
|
|
2
|
+
const wasmUrl = new URL('./wasm/beatd_bg.wasm', import.meta.url);
|
|
3
|
+
if (wasmUrl.protocol === 'file:') {
|
|
4
|
+
const { readFile } = await import('node:fs/promises');
|
|
5
|
+
await init({ module_or_path: await readFile(wasmUrl) });
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
await init({ module_or_path: wasmUrl });
|
|
9
|
+
}
|
|
10
|
+
export class Analyzer {
|
|
11
|
+
inner;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.inner = new WasmAnalyzer(options.sampleRate);
|
|
14
|
+
}
|
|
15
|
+
push(samples) { return this.inner.push(samples); }
|
|
16
|
+
sampleRate() { return this.inner.sample_rate(); }
|
|
17
|
+
level() { return this.inner.level(); }
|
|
18
|
+
bpm() { return this.inner.bpm(); }
|
|
19
|
+
spectrum() { return this.inner.spectrum(); }
|
|
20
|
+
waveform() { return this.inner.waveform(); }
|
|
21
|
+
beatOffsets(bpm) { return this.inner.beat_offsets(bpm); }
|
|
22
|
+
bandLevel(low, high) { return this.inner.band_level(low, high); }
|
|
23
|
+
bpmRangeMin() { return this.inner.bpm_range_min(); }
|
|
24
|
+
setBpmRangeMin(min) { this.inner.set_bpm_range_min(min); }
|
|
25
|
+
setBpmEnabled(enabled) { this.inner.set_bpm_enabled(enabled); }
|
|
26
|
+
setSpectrumGain(gain) { this.inner.set_spectrum_gain(gain); }
|
|
27
|
+
setSpectrumCompression(compression) { this.inner.set_spectrum_compression(compression); }
|
|
28
|
+
reset() { this.inner.reset(); }
|
|
29
|
+
dispose() { this.inner.free(); }
|
|
30
|
+
[Symbol.dispose]() { this.dispose(); }
|
|
31
|
+
}
|
|
32
|
+
export function createAnalyzer(options) {
|
|
33
|
+
return new Analyzer(options);
|
|
34
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# beatd
|
|
2
|
+
|
|
3
|
+
English | [日本語](https://github.com/nuskey8/beatd/blob/main/README.ja.md)
|
|
4
|
+
|
|
5
|
+
GUI application and library for streaming audio analysis and OSC conversion.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
beatd is a cross-platform application and library for streaming audio analysis.
|
|
12
|
+
|
|
13
|
+
It started with the concept of being a modern reimplementation of [Sound2Light](https://github.com/ETCLabs/Sound2Light), utilizing a Rust implementation to create an easy-to-use, cross-platform GUI. It can send audio analysis results via OSC to integrate with external VJ software and similar tools.
|
|
14
|
+
|
|
15
|
+
Additionally, the core analysis engine is provided as an independent library so that it can be embedded into applications for Rust, C, C# (.NET/Unity), and JavaScript (WebAssembly).
|
|
16
|
+
|
|
17
|
+
## Screenshot
|
|
18
|
+
|
|
19
|
+

|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Select the latest release from GitHub [Releases](https://github.com/nuskey8/beatd/releases/latest) and download the executable file for your operating system.
|
|
24
|
+
|
|
25
|
+
## libbeatd
|
|
26
|
+
|
|
27
|
+
The streaming audio analysis in beatd is implemented in Rust as an independent crate. By embedding this, you can use features such as BPM analysis within your applications.
|
|
28
|
+
|
|
29
|
+
### Rust
|
|
30
|
+
|
|
31
|
+
Add the crate via cargo.
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
cargo add beatd
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```rust
|
|
38
|
+
use beatd::Analyzer;
|
|
39
|
+
|
|
40
|
+
let mut analyzer = Analyzer::new(48_000);
|
|
41
|
+
|
|
42
|
+
// samples: &[f32] (-1.0 to 1.0)
|
|
43
|
+
analyzer.push(&samples);
|
|
44
|
+
|
|
45
|
+
let level = analyzer.level();
|
|
46
|
+
let bpm = analyzer.bpm();
|
|
47
|
+
let spectrum = analyzer.spectrum();
|
|
48
|
+
let waveform = analyzer.waveform();
|
|
49
|
+
let beats = analyzer.beat_offsets(bpm);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### C
|
|
53
|
+
|
|
54
|
+
Build the library with the `ffi` feature enabled.
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
cargo build -p beatd --features ffi
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Add the generated `libbeatd.so` / `libbeatd.dylib` / `beatd.dll` along with `beatd/beatd.h` to your project, and specify `-lbeatd` during linking.
|
|
61
|
+
|
|
62
|
+
```c
|
|
63
|
+
#include "beatd.h"
|
|
64
|
+
|
|
65
|
+
beatd_analyzer *analyzer = beatd_new(48000);
|
|
66
|
+
if (analyzer == NULL) {
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
beatd_set_bpm_range_min(analyzer, 75);
|
|
71
|
+
beatd_push(analyzer, samples, count);
|
|
72
|
+
|
|
73
|
+
float level = beatd_level(analyzer);
|
|
74
|
+
float bpm = beatd_bpm(analyzer);
|
|
75
|
+
|
|
76
|
+
float spectrum[1024];
|
|
77
|
+
size_t bins = beatd_spectrum(analyzer, spectrum, 1024);
|
|
78
|
+
|
|
79
|
+
beatd_free(analyzer);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### JavaScript
|
|
83
|
+
|
|
84
|
+
Add the library via npm.
|
|
85
|
+
|
|
86
|
+
```sh
|
|
87
|
+
npm i beatd-js
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
import { createAnalyzer } from "beatd-js";
|
|
92
|
+
|
|
93
|
+
using analyzer = createAnalyzer({ sampleRate: 48000 });
|
|
94
|
+
|
|
95
|
+
// samples: Float32Array
|
|
96
|
+
analyzer.push(samples);
|
|
97
|
+
|
|
98
|
+
console.log(analyzer.level(), analyzer.bpm());
|
|
99
|
+
console.log(analyzer.spectrum());
|
|
100
|
+
console.log(analyzer.waveform());
|
|
101
|
+
console.log(analyzer.beatOffsets(analyzer.bpm()));
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### C# / Unity
|
|
105
|
+
|
|
106
|
+
For .NET projects, you can add the package from NuGet.
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
dotnet package add Beatd
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
For Unity, you can add the package from the Package Manager using the git URL.
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
https://github.com/nuskey8/beatd.git?path=beatd-dotnet/Beatd.Unity/Packages/com.nuskey8.beatd.unity
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```csharp
|
|
119
|
+
using Beatd;
|
|
120
|
+
|
|
121
|
+
using var analyzer = new BeatdAnalyzer(48_000);
|
|
122
|
+
analyzer.BpmRangeMin = 75;
|
|
123
|
+
|
|
124
|
+
analyzer.Push(samples); // ReadOnlySpan<float>
|
|
125
|
+
|
|
126
|
+
Console.WriteLine($"{analyzer.Level}, {analyzer.Bpm}");
|
|
127
|
+
float[] spectrum = analyzer.GetSpectrum();
|
|
128
|
+
float[] beats = analyzer.GetBeatOffsets(analyzer.Bpm);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Please note that the .NET/Unity version currently supports only the following platforms:
|
|
132
|
+
|
|
133
|
+
| Platform | RID | .NET (NuGet) | Unity |
|
|
134
|
+
| :------------------ | :---------- | :----------: | :---: |
|
|
135
|
+
| Windows x64 | `win-x64` | ✅ | ✅ |
|
|
136
|
+
| Linux x64 | `linux-x64` | ✅ | ✅ |
|
|
137
|
+
| macOS Intel | `osx-x64` | ✅ | ✅ |
|
|
138
|
+
| macOS Apple Silicon | `osx-arm64` | ✅ | ✅ |
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
beatd is released under the [MIT License](https://github.com/nuskey8/beatd/blob/main/LICENSE).
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class Analyzer {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
band_level(low: number, high: number): number;
|
|
8
|
+
beat_offsets(bpm: number): Float32Array;
|
|
9
|
+
bpm(): number;
|
|
10
|
+
bpm_range_min(): number;
|
|
11
|
+
level(): number;
|
|
12
|
+
constructor(sample_rate: number);
|
|
13
|
+
push(samples: Float32Array | number[]): boolean;
|
|
14
|
+
reset(): void;
|
|
15
|
+
sample_rate(): number;
|
|
16
|
+
set_bpm_enabled(enabled: boolean): void;
|
|
17
|
+
set_bpm_range_min(min: number): void;
|
|
18
|
+
set_spectrum_compression(compression: number): void;
|
|
19
|
+
set_spectrum_gain(gain: number): void;
|
|
20
|
+
spectrum(): Float32Array;
|
|
21
|
+
waveform(): Float32Array;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
25
|
+
|
|
26
|
+
export interface InitOutput {
|
|
27
|
+
readonly memory: WebAssembly.Memory;
|
|
28
|
+
readonly __wbg_analyzer_free: (a: number, b: number) => void;
|
|
29
|
+
readonly analyzer_band_level: (a: number, b: number, c: number) => number;
|
|
30
|
+
readonly analyzer_beat_offsets: (a: number, b: number) => [number, number];
|
|
31
|
+
readonly analyzer_bpm: (a: number) => number;
|
|
32
|
+
readonly analyzer_bpm_range_min: (a: number) => number;
|
|
33
|
+
readonly analyzer_level: (a: number) => number;
|
|
34
|
+
readonly analyzer_new: (a: number) => [number, number, number];
|
|
35
|
+
readonly analyzer_push: (a: number, b: number, c: number) => number;
|
|
36
|
+
readonly analyzer_reset: (a: number) => void;
|
|
37
|
+
readonly analyzer_sample_rate: (a: number) => number;
|
|
38
|
+
readonly analyzer_set_bpm_enabled: (a: number, b: number) => void;
|
|
39
|
+
readonly analyzer_set_bpm_range_min: (a: number, b: number) => [number, number];
|
|
40
|
+
readonly analyzer_set_spectrum_compression: (a: number, b: number) => void;
|
|
41
|
+
readonly analyzer_set_spectrum_gain: (a: number, b: number) => void;
|
|
42
|
+
readonly analyzer_spectrum: (a: number) => [number, number];
|
|
43
|
+
readonly analyzer_waveform: (a: number) => [number, number];
|
|
44
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
45
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
46
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
47
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
48
|
+
readonly __wbindgen_start: () => void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
55
|
+
* a precompiled `WebAssembly.Module`.
|
|
56
|
+
*
|
|
57
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
58
|
+
*
|
|
59
|
+
* @returns {InitOutput}
|
|
60
|
+
*/
|
|
61
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
65
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
66
|
+
*
|
|
67
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
68
|
+
*
|
|
69
|
+
* @returns {Promise<InitOutput>}
|
|
70
|
+
*/
|
|
71
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/* @ts-self-types="./beatd.d.ts" */
|
|
2
|
+
|
|
3
|
+
export class Analyzer {
|
|
4
|
+
__destroy_into_raw() {
|
|
5
|
+
const ptr = this.__wbg_ptr;
|
|
6
|
+
this.__wbg_ptr = 0;
|
|
7
|
+
AnalyzerFinalization.unregister(this);
|
|
8
|
+
return ptr;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
const ptr = this.__destroy_into_raw();
|
|
12
|
+
wasm.__wbg_analyzer_free(ptr, 0);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @param {number} low
|
|
16
|
+
* @param {number} high
|
|
17
|
+
* @returns {number}
|
|
18
|
+
*/
|
|
19
|
+
band_level(low, high) {
|
|
20
|
+
const ret = wasm.analyzer_band_level(this.__wbg_ptr, low, high);
|
|
21
|
+
return ret;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @param {number} bpm
|
|
25
|
+
* @returns {Float32Array}
|
|
26
|
+
*/
|
|
27
|
+
beat_offsets(bpm) {
|
|
28
|
+
const ret = wasm.analyzer_beat_offsets(this.__wbg_ptr, bpm);
|
|
29
|
+
var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
30
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
31
|
+
return v1;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @returns {number}
|
|
35
|
+
*/
|
|
36
|
+
bpm() {
|
|
37
|
+
const ret = wasm.analyzer_bpm(this.__wbg_ptr);
|
|
38
|
+
return ret;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @returns {number}
|
|
42
|
+
*/
|
|
43
|
+
bpm_range_min() {
|
|
44
|
+
const ret = wasm.analyzer_bpm_range_min(this.__wbg_ptr);
|
|
45
|
+
return ret;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @returns {number}
|
|
49
|
+
*/
|
|
50
|
+
level() {
|
|
51
|
+
const ret = wasm.analyzer_level(this.__wbg_ptr);
|
|
52
|
+
return ret;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @param {number} sample_rate
|
|
56
|
+
*/
|
|
57
|
+
constructor(sample_rate) {
|
|
58
|
+
const ret = wasm.analyzer_new(sample_rate);
|
|
59
|
+
if (ret[2]) {
|
|
60
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
61
|
+
}
|
|
62
|
+
this.__wbg_ptr = ret[0];
|
|
63
|
+
AnalyzerFinalization.register(this, this.__wbg_ptr, this);
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @param {Float32Array | number[]} samples
|
|
68
|
+
* @returns {boolean}
|
|
69
|
+
*/
|
|
70
|
+
push(samples) {
|
|
71
|
+
const ptr0 = passArrayF32ToWasm0(samples, wasm.__wbindgen_malloc);
|
|
72
|
+
const len0 = WASM_VECTOR_LEN;
|
|
73
|
+
const ret = wasm.analyzer_push(this.__wbg_ptr, ptr0, len0);
|
|
74
|
+
return ret !== 0;
|
|
75
|
+
}
|
|
76
|
+
reset() {
|
|
77
|
+
wasm.analyzer_reset(this.__wbg_ptr);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @returns {number}
|
|
81
|
+
*/
|
|
82
|
+
sample_rate() {
|
|
83
|
+
const ret = wasm.analyzer_sample_rate(this.__wbg_ptr);
|
|
84
|
+
return ret >>> 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @param {boolean} enabled
|
|
88
|
+
*/
|
|
89
|
+
set_bpm_enabled(enabled) {
|
|
90
|
+
wasm.analyzer_set_bpm_enabled(this.__wbg_ptr, enabled);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @param {number} min
|
|
94
|
+
*/
|
|
95
|
+
set_bpm_range_min(min) {
|
|
96
|
+
const ret = wasm.analyzer_set_bpm_range_min(this.__wbg_ptr, min);
|
|
97
|
+
if (ret[1]) {
|
|
98
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @param {number} compression
|
|
103
|
+
*/
|
|
104
|
+
set_spectrum_compression(compression) {
|
|
105
|
+
wasm.analyzer_set_spectrum_compression(this.__wbg_ptr, compression);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @param {number} gain
|
|
109
|
+
*/
|
|
110
|
+
set_spectrum_gain(gain) {
|
|
111
|
+
wasm.analyzer_set_spectrum_gain(this.__wbg_ptr, gain);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @returns {Float32Array}
|
|
115
|
+
*/
|
|
116
|
+
spectrum() {
|
|
117
|
+
const ret = wasm.analyzer_spectrum(this.__wbg_ptr);
|
|
118
|
+
var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
119
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
120
|
+
return v1;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @returns {Float32Array}
|
|
124
|
+
*/
|
|
125
|
+
waveform() {
|
|
126
|
+
const ret = wasm.analyzer_waveform(this.__wbg_ptr);
|
|
127
|
+
var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
128
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
129
|
+
return v1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (Symbol.dispose) Analyzer.prototype[Symbol.dispose] = Analyzer.prototype.free;
|
|
133
|
+
function __wbg_get_imports() {
|
|
134
|
+
const import0 = {
|
|
135
|
+
__proto__: null,
|
|
136
|
+
__wbg_Error_208446807d0d1e30: function(arg0, arg1) {
|
|
137
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
138
|
+
return ret;
|
|
139
|
+
},
|
|
140
|
+
__wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
|
|
141
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
142
|
+
},
|
|
143
|
+
__wbindgen_init_externref_table: function() {
|
|
144
|
+
const table = wasm.__wbindgen_externrefs;
|
|
145
|
+
table.set(0, undefined);
|
|
146
|
+
table.set(1024, undefined);
|
|
147
|
+
table.set(1025, null);
|
|
148
|
+
table.set(1026, true);
|
|
149
|
+
table.set(1027, false);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
__proto__: null,
|
|
154
|
+
"./beatd_bg.js": import0,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const AnalyzerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
159
|
+
? { register: () => {}, unregister: () => {} }
|
|
160
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_analyzer_free(ptr, 1));
|
|
161
|
+
|
|
162
|
+
function getArrayF32FromWasm0(ptr, len) {
|
|
163
|
+
ptr = ptr >>> 0;
|
|
164
|
+
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let cachedFloat32ArrayMemory0 = null;
|
|
168
|
+
function getFloat32ArrayMemory0() {
|
|
169
|
+
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
|
170
|
+
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
|
171
|
+
}
|
|
172
|
+
return cachedFloat32ArrayMemory0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function getStringFromWasm0(ptr, len) {
|
|
176
|
+
ptr = ptr >>> 0;
|
|
177
|
+
return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let cachedUint8ArrayMemory0 = null;
|
|
181
|
+
function getUint8ArrayMemory0() {
|
|
182
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
183
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
184
|
+
}
|
|
185
|
+
return cachedUint8ArrayMemory0;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function passArrayF32ToWasm0(arg, malloc) {
|
|
189
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
190
|
+
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
|
191
|
+
WASM_VECTOR_LEN = arg.length;
|
|
192
|
+
return ptr;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function takeFromExternrefTable0(idx) {
|
|
196
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
197
|
+
wasm.__externref_table_dealloc(idx);
|
|
198
|
+
return value;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
202
|
+
cachedTextDecoder.decode();
|
|
203
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
204
|
+
let numBytesDecoded = 0;
|
|
205
|
+
function decodeText(bytes) {
|
|
206
|
+
numBytesDecoded += bytes.length;
|
|
207
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
208
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
209
|
+
cachedTextDecoder.decode();
|
|
210
|
+
numBytesDecoded = bytes.length;
|
|
211
|
+
}
|
|
212
|
+
return cachedTextDecoder.decode(bytes);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
let WASM_VECTOR_LEN = 0;
|
|
216
|
+
|
|
217
|
+
let wasmModule, wasmInstance, wasm;
|
|
218
|
+
function __wbg_finalize_init(instance, module) {
|
|
219
|
+
wasmInstance = instance;
|
|
220
|
+
wasm = instance.exports;
|
|
221
|
+
wasmModule = module;
|
|
222
|
+
cachedFloat32ArrayMemory0 = null;
|
|
223
|
+
cachedUint8ArrayMemory0 = null;
|
|
224
|
+
wasm.__wbindgen_start();
|
|
225
|
+
return wasm;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function __wbg_load(module, imports) {
|
|
229
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
230
|
+
if (!module.ok) {
|
|
231
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
235
|
+
try {
|
|
236
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
const validResponse = expectedResponseType(module.type);
|
|
239
|
+
|
|
240
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
241
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
242
|
+
|
|
243
|
+
} else { throw e; }
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const bytes = await module.arrayBuffer();
|
|
248
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
249
|
+
} else {
|
|
250
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
251
|
+
|
|
252
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
253
|
+
return { instance, module };
|
|
254
|
+
} else {
|
|
255
|
+
return instance;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function expectedResponseType(type) {
|
|
260
|
+
switch (type) {
|
|
261
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
262
|
+
}
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function initSync(module) {
|
|
268
|
+
if (wasm !== undefined) return wasm;
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
if (module !== undefined) {
|
|
272
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
273
|
+
({module} = module)
|
|
274
|
+
} else {
|
|
275
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const imports = __wbg_get_imports();
|
|
280
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
281
|
+
module = new WebAssembly.Module(module);
|
|
282
|
+
}
|
|
283
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
284
|
+
return __wbg_finalize_init(instance, module);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
let __wbg_init_promise;
|
|
288
|
+
async function __wbg_init(module_or_path) {
|
|
289
|
+
if (wasm !== undefined) return wasm;
|
|
290
|
+
if (__wbg_init_promise === undefined) {
|
|
291
|
+
__wbg_init_promise = __wbg_init_once(module_or_path);
|
|
292
|
+
__wbg_init_promise.catch(() => { __wbg_init_promise = undefined; });
|
|
293
|
+
}
|
|
294
|
+
return __wbg_init_promise;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async function __wbg_init_once(module_or_path) {
|
|
298
|
+
|
|
299
|
+
if (module_or_path !== undefined) {
|
|
300
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
301
|
+
({module_or_path} = module_or_path)
|
|
302
|
+
} else {
|
|
303
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (module_or_path === undefined) {
|
|
308
|
+
module_or_path = new URL('beatd_bg.wasm', import.meta.url);
|
|
309
|
+
}
|
|
310
|
+
const imports = __wbg_get_imports();
|
|
311
|
+
|
|
312
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
313
|
+
module_or_path = fetch(module_or_path);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
317
|
+
|
|
318
|
+
return __wbg_finalize_init(instance, module);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_analyzer_free: (a: number, b: number) => void;
|
|
5
|
+
export const analyzer_band_level: (a: number, b: number, c: number) => number;
|
|
6
|
+
export const analyzer_beat_offsets: (a: number, b: number) => [number, number];
|
|
7
|
+
export const analyzer_bpm: (a: number) => number;
|
|
8
|
+
export const analyzer_bpm_range_min: (a: number) => number;
|
|
9
|
+
export const analyzer_level: (a: number) => number;
|
|
10
|
+
export const analyzer_new: (a: number) => [number, number, number];
|
|
11
|
+
export const analyzer_push: (a: number, b: number, c: number) => number;
|
|
12
|
+
export const analyzer_reset: (a: number) => void;
|
|
13
|
+
export const analyzer_sample_rate: (a: number) => number;
|
|
14
|
+
export const analyzer_set_bpm_enabled: (a: number, b: number) => void;
|
|
15
|
+
export const analyzer_set_bpm_range_min: (a: number, b: number) => [number, number];
|
|
16
|
+
export const analyzer_set_spectrum_compression: (a: number, b: number) => void;
|
|
17
|
+
export const analyzer_set_spectrum_gain: (a: number, b: number) => void;
|
|
18
|
+
export const analyzer_spectrum: (a: number) => [number, number];
|
|
19
|
+
export const analyzer_waveform: (a: number) => [number, number];
|
|
20
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
21
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
22
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
23
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
24
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "beatd",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "A cross-platform library for Streaming audio analysis.",
|
|
5
|
+
"version": "0.0.1",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/nuskey8/beatd"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"beatd_bg.wasm",
|
|
13
|
+
"beatd.js",
|
|
14
|
+
"beatd.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "beatd.js",
|
|
17
|
+
"homepage": "https://github.com/nuskey8/beatd",
|
|
18
|
+
"types": "beatd.d.ts",
|
|
19
|
+
"sideEffects": [
|
|
20
|
+
"./snippets/*"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"audio",
|
|
24
|
+
"bpm",
|
|
25
|
+
"beat-detection",
|
|
26
|
+
"fft",
|
|
27
|
+
"wasm"
|
|
28
|
+
]
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beatd-js",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "beatd bindings for JavaScript",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "nuskey",
|
|
7
|
+
"homepage": "https://github.com/nuskey8/beatd#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/nuskey8/beatd.git",
|
|
11
|
+
"directory": "beatd-js"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/nuskey8/beatd/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"audio",
|
|
18
|
+
"bpm",
|
|
19
|
+
"beat",
|
|
20
|
+
"analysis",
|
|
21
|
+
"webassembly",
|
|
22
|
+
"wasm"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "wasm-pack build ../beatd --target web --out-dir ../beatd-js/dist/wasm -- --features wasm && rm -f dist/wasm/.gitignore && tsc",
|
|
40
|
+
"test": "bun test",
|
|
41
|
+
"prepack": "bun run build"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"typescript": "^5.8.3",
|
|
48
|
+
"@types/node": "^22.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/README.md
DELETED