beatd-js 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2026 Yusuke Nakada
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,149 @@
1
- # Temporary Holding Version
1
+ # beatd
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/nuskey8/beatd/actions/workflows/ci.yml/badge.svg)](https://github.com/nuskey8/beatd/avctions/workflows/ci.yml)
4
+ [![Release](https://img.shields.io/github/v/release/nuskey8/beatd)](https://github.com/nuskey8/beatd/releases/latest)
5
+ [![crates.io](https://img.shields.io/crates/v/beatd)](https://crates.io/crates/beatd)
6
+ [![npm](https://img.shields.io/npm/v/beatd-js)](https://www.npmjs.com/package/beatd-js)
7
+ [![NuGet](https://img.shields.io/nuget/v/Beatd)](https://www.nuget.org/packages/Beatd)
8
+ [![Unity](https://img.shields.io/badge/Unity-6000.0%2B-black?logo=unity)](https://github.com/nuskey8/beatd/tree/main/beatd-dotnet/Beatd.Unity/Packages/com.nuskey8.beatd.unity)
9
+
10
+ English | [日本語](https://github.com/nuskey8/beatd/blob/main/README.ja.md)
11
+
12
+ GUI application and library for streaming audio analysis and OSC conversion.
13
+
14
+ ![hero](https://raw.githubusercontent.com/nuskey8/beatd/main/assets/hero.png)
15
+
16
+ ## Overview
17
+
18
+ beatd is a cross-platform application and library for streaming audio analysis.
19
+
20
+ 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.
21
+
22
+ 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).
23
+
24
+ ## Screenshot
25
+
26
+ ![img](https://raw.githubusercontent.com/nuskey8/beatd/main/assets/img1.png)
27
+
28
+ ## Installation
29
+
30
+ Select the latest release from GitHub [Releases](https://github.com/nuskey8/beatd/releases/latest) and download the executable file for your operating system.
31
+
32
+ ## libbeatd
33
+
34
+ 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.
35
+
36
+ ### Rust
37
+
38
+ Add the crate via cargo.
39
+
40
+ ```sh
41
+ cargo add beatd
42
+ ```
43
+
44
+ ```rust
45
+ use beatd::Analyzer;
46
+
47
+ let mut analyzer = Analyzer::new(48_000);
48
+
49
+ // samples: &[f32] (-1.0 to 1.0)
50
+ analyzer.push(&samples);
51
+
52
+ let level = analyzer.level();
53
+ let bpm = analyzer.bpm();
54
+ let spectrum = analyzer.spectrum();
55
+ let waveform = analyzer.waveform();
56
+ let beats = analyzer.beat_offsets(bpm);
57
+ ```
58
+
59
+ ### C
60
+
61
+ Build the library with the `ffi` feature enabled.
62
+
63
+ ```sh
64
+ cargo build -p beatd --features ffi
65
+ ```
66
+
67
+ Add the generated `libbeatd.so` / `libbeatd.dylib` / `beatd.dll` along with `beatd/beatd.h` to your project, and specify `-lbeatd` during linking.
68
+
69
+ ```c
70
+ #include "beatd.h"
71
+
72
+ beatd_analyzer *analyzer = beatd_new(48000);
73
+ if (analyzer == NULL) {
74
+ return 1;
75
+ }
76
+
77
+ beatd_set_bpm_range_min(analyzer, 75);
78
+ beatd_push(analyzer, samples, count);
79
+
80
+ float level = beatd_level(analyzer);
81
+ float bpm = beatd_bpm(analyzer);
82
+
83
+ float spectrum[1024];
84
+ size_t bins = beatd_spectrum(analyzer, spectrum, 1024);
85
+
86
+ beatd_free(analyzer);
87
+ ```
88
+
89
+ ### JavaScript
90
+
91
+ Add the library via npm.
92
+
93
+ ```sh
94
+ npm i beatd-js
95
+ ```
96
+
97
+ ```js
98
+ import { createAnalyzer } from "beatd-js";
99
+
100
+ using analyzer = createAnalyzer({ sampleRate: 48000 });
101
+
102
+ // samples: Float32Array
103
+ analyzer.push(samples);
104
+
105
+ console.log(analyzer.level(), analyzer.bpm());
106
+ console.log(analyzer.spectrum());
107
+ console.log(analyzer.waveform());
108
+ console.log(analyzer.beatOffsets(analyzer.bpm()));
109
+ ```
110
+
111
+ ### C# / Unity
112
+
113
+ For .NET projects, you can add the package from NuGet.
114
+
115
+ ```sh
116
+ dotnet package add Beatd
117
+ ```
118
+
119
+ For Unity, you can add the package from the Package Manager using the git URL.
120
+
121
+ ```
122
+ https://github.com/nuskey8/beatd.git?path=beatd-dotnet/Beatd.Unity/Packages/com.nuskey8.beatd.unity
123
+ ```
124
+
125
+ ```csharp
126
+ using Beatd;
127
+
128
+ using var analyzer = new BeatdAnalyzer(48_000);
129
+ analyzer.BpmRangeMin = 75;
130
+
131
+ analyzer.Push(samples); // ReadOnlySpan<float>
132
+
133
+ Console.WriteLine($"{analyzer.Level}, {analyzer.Bpm}");
134
+ float[] spectrum = analyzer.GetSpectrum();
135
+ float[] beats = analyzer.GetBeatOffsets(analyzer.Bpm);
136
+ ```
137
+
138
+ Please note that the .NET/Unity version currently supports only the following platforms:
139
+
140
+ | Platform | RID | .NET (NuGet) | Unity |
141
+ | :------------------ | :---------- | :----------: | :---: |
142
+ | Windows x64 | `win-x64` | ✅ | ✅ |
143
+ | Linux x64 | `linux-x64` | ✅ | ✅ |
144
+ | macOS Intel | `osx-x64` | ✅ | ✅ |
145
+ | macOS Apple Silicon | `osx-arm64` | ✅ | ✅ |
146
+
147
+ ## License
148
+
149
+ beatd is released under the [MIT License](https://github.com/nuskey8/beatd/blob/main/LICENSE).
@@ -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,149 @@
1
+ # beatd
2
+
3
+ [![CI](https://github.com/nuskey8/beatd/actions/workflows/ci.yml/badge.svg)](https://github.com/nuskey8/beatd/avctions/workflows/ci.yml)
4
+ [![Release](https://img.shields.io/github/v/release/nuskey8/beatd)](https://github.com/nuskey8/beatd/releases/latest)
5
+ [![crates.io](https://img.shields.io/crates/v/beatd)](https://crates.io/crates/beatd)
6
+ [![npm](https://img.shields.io/npm/v/beatd-js)](https://www.npmjs.com/package/beatd-js)
7
+ [![NuGet](https://img.shields.io/nuget/v/Beatd)](https://www.nuget.org/packages/Beatd)
8
+ [![Unity](https://img.shields.io/badge/Unity-6000.0%2B-black?logo=unity)](https://github.com/nuskey8/beatd/tree/main/beatd-dotnet/Beatd.Unity/Packages/com.nuskey8.beatd.unity)
9
+
10
+ English | [日本語](https://github.com/nuskey8/beatd/blob/main/README.ja.md)
11
+
12
+ GUI application and library for streaming audio analysis and OSC conversion.
13
+
14
+ ![hero](https://raw.githubusercontent.com/nuskey8/beatd/main/assets/hero.png)
15
+
16
+ ## Overview
17
+
18
+ beatd is a cross-platform application and library for streaming audio analysis.
19
+
20
+ 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.
21
+
22
+ 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).
23
+
24
+ ## Screenshot
25
+
26
+ ![img](https://raw.githubusercontent.com/nuskey8/beatd/main/assets/img1.png)
27
+
28
+ ## Installation
29
+
30
+ Select the latest release from GitHub [Releases](https://github.com/nuskey8/beatd/releases/latest) and download the executable file for your operating system.
31
+
32
+ ## libbeatd
33
+
34
+ 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.
35
+
36
+ ### Rust
37
+
38
+ Add the crate via cargo.
39
+
40
+ ```sh
41
+ cargo add beatd
42
+ ```
43
+
44
+ ```rust
45
+ use beatd::Analyzer;
46
+
47
+ let mut analyzer = Analyzer::new(48_000);
48
+
49
+ // samples: &[f32] (-1.0 to 1.0)
50
+ analyzer.push(&samples);
51
+
52
+ let level = analyzer.level();
53
+ let bpm = analyzer.bpm();
54
+ let spectrum = analyzer.spectrum();
55
+ let waveform = analyzer.waveform();
56
+ let beats = analyzer.beat_offsets(bpm);
57
+ ```
58
+
59
+ ### C
60
+
61
+ Build the library with the `ffi` feature enabled.
62
+
63
+ ```sh
64
+ cargo build -p beatd --features ffi
65
+ ```
66
+
67
+ Add the generated `libbeatd.so` / `libbeatd.dylib` / `beatd.dll` along with `beatd/beatd.h` to your project, and specify `-lbeatd` during linking.
68
+
69
+ ```c
70
+ #include "beatd.h"
71
+
72
+ beatd_analyzer *analyzer = beatd_new(48000);
73
+ if (analyzer == NULL) {
74
+ return 1;
75
+ }
76
+
77
+ beatd_set_bpm_range_min(analyzer, 75);
78
+ beatd_push(analyzer, samples, count);
79
+
80
+ float level = beatd_level(analyzer);
81
+ float bpm = beatd_bpm(analyzer);
82
+
83
+ float spectrum[1024];
84
+ size_t bins = beatd_spectrum(analyzer, spectrum, 1024);
85
+
86
+ beatd_free(analyzer);
87
+ ```
88
+
89
+ ### JavaScript
90
+
91
+ Add the library via npm.
92
+
93
+ ```sh
94
+ npm i beatd-js
95
+ ```
96
+
97
+ ```js
98
+ import { createAnalyzer } from "beatd-js";
99
+
100
+ using analyzer = createAnalyzer({ sampleRate: 48000 });
101
+
102
+ // samples: Float32Array
103
+ analyzer.push(samples);
104
+
105
+ console.log(analyzer.level(), analyzer.bpm());
106
+ console.log(analyzer.spectrum());
107
+ console.log(analyzer.waveform());
108
+ console.log(analyzer.beatOffsets(analyzer.bpm()));
109
+ ```
110
+
111
+ ### C# / Unity
112
+
113
+ For .NET projects, you can add the package from NuGet.
114
+
115
+ ```sh
116
+ dotnet package add Beatd
117
+ ```
118
+
119
+ For Unity, you can add the package from the Package Manager using the git URL.
120
+
121
+ ```
122
+ https://github.com/nuskey8/beatd.git?path=beatd-dotnet/Beatd.Unity/Packages/com.nuskey8.beatd.unity
123
+ ```
124
+
125
+ ```csharp
126
+ using Beatd;
127
+
128
+ using var analyzer = new BeatdAnalyzer(48_000);
129
+ analyzer.BpmRangeMin = 75;
130
+
131
+ analyzer.Push(samples); // ReadOnlySpan<float>
132
+
133
+ Console.WriteLine($"{analyzer.Level}, {analyzer.Bpm}");
134
+ float[] spectrum = analyzer.GetSpectrum();
135
+ float[] beats = analyzer.GetBeatOffsets(analyzer.Bpm);
136
+ ```
137
+
138
+ Please note that the .NET/Unity version currently supports only the following platforms:
139
+
140
+ | Platform | RID | .NET (NuGet) | Unity |
141
+ | :------------------ | :---------- | :----------: | :---: |
142
+ | Windows x64 | `win-x64` | ✅ | ✅ |
143
+ | Linux x64 | `linux-x64` | ✅ | ✅ |
144
+ | macOS Intel | `osx-x64` | ✅ | ✅ |
145
+ | macOS Apple Silicon | `osx-arm64` | ✅ | ✅ |
146
+
147
+ ## License
148
+
149
+ 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.1.0",
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.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
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
+ }