@mimium/mimium-webaudio 1.0.3 → 1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimium/mimium-webaudio",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "webaudio audioworklet module to run mimium code on web browser.",
6
6
  "main": "dist/mimium-webaudio.js",
@@ -15,6 +15,12 @@
15
15
  "keywords": [
16
16
  "mimium"
17
17
  ],
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "exports": {
22
+ ".": "./dist/mimium-webaudio.js"
23
+ },
18
24
  "author": "Tomoya Matsuura",
19
25
  "license": "MPL-2.0",
20
26
  "bugs": {
@@ -33,4 +39,4 @@
33
39
  "vite": "^6.0.3",
34
40
  "vite-plugin-dts": "^4.4.0"
35
41
  }
36
- }
42
+ }
@@ -1,60 +0,0 @@
1
- import "./textencoder.js";
2
-
3
- import init, { Context, Config } from "mimium-web";
4
-
5
- export class MimiumProcessor extends AudioWorkletProcessor {
6
- context: Context | null;
7
-
8
- constructor() {
9
- super();
10
- this.context = null;
11
- this.port.onmessage = (event) => {
12
- this.onmessage(event.data);
13
- };
14
- }
15
- onmessage(event: MessageEvent<any>) {
16
- switch (event.type) {
17
- case "send-wasm-module": {
18
- this.port.postMessage("start_loading");
19
- const wasmBinary = event.data; //this is invalid conversion for workaround.
20
- const wasm = WebAssembly.compile(wasmBinary);
21
- init(wasm)
22
- .then(() => {
23
- console.log("wasm module loaded");
24
- this.port.postMessage({ type: "wasm-module-loaded" });
25
- })
26
- .catch((e) => {
27
- this.port.postMessage({ type: "error_wasm_load", data: e });
28
- });
29
- }
30
- case "compile":
31
- this.compile(
32
- event.data.samplerate,
33
- event.data.buffersize,
34
- event.data.src
35
- );
36
- break;
37
- }
38
- }
39
- public compile(samplerate: number, buffersize: number, src: string) {
40
- let config = new Config();
41
- config.sample_rate = samplerate;
42
- config.output_channels = 1;
43
- config.buffer_size = buffersize;
44
- this.context = new Context(config);
45
- this.context.compile(src);
46
- }
47
- public process(
48
- inputs: Float32Array[][],
49
- outputs: Float32Array[][],
50
- parameter: Record<string, Float32Array>
51
- ) {
52
- const input = inputs[0][0];
53
- if (this.context) {
54
- this.context.process(input, outputs[0][0]);
55
- }
56
- return true;
57
- }
58
- }
59
-
60
- registerProcessor("MimiumProcessor", MimiumProcessor);
package/src/index.ts DELETED
@@ -1,42 +0,0 @@
1
- import MimiumProcessor from "./audioprocessor.js?worker&url";
2
- import { MimiumProcessorNode, CompileData } from "./workletnode";
3
- import wasmurl from "mimium-web/mimium_web_bg.wasm?url";
4
-
5
- export { MimiumProcessorNode, MimiumProcessor };
6
-
7
- export default async function setupAudioWorklet(src: string) {
8
- const userMedia = await navigator.mediaDevices.getUserMedia({
9
- audio: true,
10
- video: false,
11
- });
12
- let audioNode;
13
- const audioContext = new AudioContext({ latencyHint: "interactive" });
14
- try {
15
- const response = await window.fetch(wasmurl);
16
- const wasmBytes = await response.arrayBuffer();
17
- try {
18
- await audioContext.audioWorklet.addModule(MimiumProcessor);
19
- } catch (e) {
20
- let err = e as unknown as Error;
21
- throw new Error(
22
- `Failed to load audio analyzer worklet at url: ${MimiumProcessor}. Further info: ${err.message}`
23
- );
24
- }
25
- audioNode = new MimiumProcessorNode(audioContext, "MimiumProcessor");
26
- audioNode.init(wasmBytes, {
27
- src: src,
28
- samplerate: audioContext.sampleRate,
29
- buffersize: 128, //AudioWorklet Always uses 128 for now
30
- } as CompileData);
31
- audioContext.resume();
32
- const microphone = await audioContext.createMediaStreamSource(userMedia);
33
-
34
- microphone.connect(audioNode).connect(audioContext.destination);
35
- return { node: audioNode, context: audioContext };
36
- } catch (e) {
37
- let err = e as unknown as Error;
38
- throw new Error(
39
- `Failed to load audio analyzer WASM module. Further info: ${err.message}`
40
- );
41
- }
42
- }
@@ -1,100 +0,0 @@
1
- // TextEncoder/TextDecoder polyfills for utf-8 - an implementation of TextEncoder/TextDecoder APIs
2
- // Written in 2013 by Viktor Mukhachev <vic99999@yandex.ru>
3
- // To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
4
- // You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
5
-
6
- // Some important notes about the polyfill below:
7
- // Native TextEncoder/TextDecoder implementation is overwritten
8
- // String.prototype.codePointAt polyfill not included, as well as String.fromCodePoint
9
- // TextEncoder.prototype.encode returns a regular array instead of Uint8Array
10
- // No options (fatal of the TextDecoder constructor and stream of the TextDecoder.prototype.decode method) are supported.
11
- // TextDecoder.prototype.decode does not valid byte sequences
12
- // This is a demonstrative implementation not intended to have the best performance
13
-
14
- // http://encoding.spec.whatwg.org/#textencoder
15
- (function (window) {
16
- "use strict";
17
- function TextEncoder() {}
18
- TextEncoder.prototype.encode = function (string) {
19
- var octets = [];
20
- var length = string.length;
21
- var i = 0;
22
- while (i < length) {
23
- var codePoint = string.codePointAt(i);
24
- var c = 0;
25
- var bits = 0;
26
- if (codePoint <= 0x0000007f) {
27
- c = 0;
28
- bits = 0x00;
29
- } else if (codePoint <= 0x000007ff) {
30
- c = 6;
31
- bits = 0xc0;
32
- } else if (codePoint <= 0x0000ffff) {
33
- c = 12;
34
- bits = 0xe0;
35
- } else if (codePoint <= 0x001fffff) {
36
- c = 18;
37
- bits = 0xf0;
38
- }
39
- octets.push(bits | (codePoint >> c));
40
- c -= 6;
41
- while (c >= 0) {
42
- octets.push(0x80 | ((codePoint >> c) & 0x3f));
43
- c -= 6;
44
- }
45
- i += codePoint >= 0x10000 ? 2 : 1;
46
- }
47
- return octets;
48
- };
49
- globalThis.TextEncoder = TextEncoder;
50
- if (!window["TextEncoder"]) window["TextEncoder"] = TextEncoder;
51
-
52
- function TextDecoder() {}
53
- TextDecoder.prototype.decode = function (octets) {
54
- if (!octets) return "";
55
- var string = "";
56
- var i = 0;
57
- while (i < octets.length) {
58
- var octet = octets[i];
59
- var bytesNeeded = 0;
60
- var codePoint = 0;
61
- if (octet <= 0x7f) {
62
- bytesNeeded = 0;
63
- codePoint = octet & 0xff;
64
- } else if (octet <= 0xdf) {
65
- bytesNeeded = 1;
66
- codePoint = octet & 0x1f;
67
- } else if (octet <= 0xef) {
68
- bytesNeeded = 2;
69
- codePoint = octet & 0x0f;
70
- } else if (octet <= 0xf4) {
71
- bytesNeeded = 3;
72
- codePoint = octet & 0x07;
73
- }
74
- if (octets.length - i - bytesNeeded > 0) {
75
- var k = 0;
76
- while (k < bytesNeeded) {
77
- octet = octets[i + k + 1];
78
- codePoint = (codePoint << 6) | (octet & 0x3f);
79
- k += 1;
80
- }
81
- } else {
82
- codePoint = 0xfffd;
83
- bytesNeeded = octets.length - i;
84
- }
85
- string += String.fromCodePoint(codePoint);
86
- i += bytesNeeded + 1;
87
- }
88
- return string;
89
- };
90
- globalThis.TextDecoder = TextDecoder;
91
- if (!window["TextDecoder"]) window["TextDecoder"] = TextDecoder;
92
- })(
93
- typeof globalThis == "" + void 0
94
- ? typeof global == "" + void 0
95
- ? typeof self == "" + void 0
96
- ? this
97
- : self
98
- : global
99
- : globalThis
100
- );
package/src/vite-env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />
@@ -1,39 +0,0 @@
1
- export type CompileData = {
2
- samplerate: number;
3
- buffersize: number;
4
- src: string;
5
- };
6
- export class MimiumProcessorNode extends AudioWorkletNode {
7
- private data: CompileData | null = null;
8
- init(wasmBinary: ArrayBuffer, data: CompileData) {
9
- this.data = data;
10
- console.log(`Compiledata : ${data}`);
11
- this.port.onmessage = (event: MessageEvent) => {
12
- this.onmessage(event.data);
13
- };
14
- this.port.postMessage({
15
- type: "send-wasm-module",
16
- data: wasmBinary,
17
- });
18
- // Handle an uncaught exception thrown in the Processor.
19
- this.onprocessorerror = (err) => {
20
- console.log(
21
- `An error from AudioWorkletProcessor.process() occurred: ${err}`
22
- );
23
- };
24
- }
25
-
26
- onmessage(event: MessageEvent) {
27
- if (event.type === "wasm-module-loaded") {
28
- console.log("wasm module loaded");
29
- this.port.postMessage({
30
- type: "compile",
31
- data: this.data,
32
- });
33
- } else if (event.type === "error_wasm_load") {
34
- console.error(event.data);
35
- }else if (event.type ==="stop"){
36
- this.disconnect()
37
- }
38
- }
39
- }
package/tsconfig.json DELETED
@@ -1,114 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
- "lib": ["es6","dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
-
27
- /* Modules */
28
- "module": "commonjs", /* Specify what module code is generated. */
29
- "rootDir": "src", /* Specify the root folder within your source files. */
30
- // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
31
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
- // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
- "types": [
37
- "@types/audioworklet"
38
- ],
39
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
40
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
41
- // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
42
- // "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
43
- // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
44
- // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
45
- // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
46
- // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
47
- "resolveJsonModule": true, /* Enable importing .json files. */
48
- // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
49
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
50
-
51
- /* JavaScript Support */
52
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
53
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
54
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
55
-
56
- /* Emit */
57
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
58
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
59
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
60
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
61
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
62
- // "noEmit": true, /* Disable emitting files from a compilation. */
63
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
64
- "outDir": "lib", /* Specify an output folder for all emitted files. */
65
- // "removeComments": true, /* Disable emitting comments. */
66
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
67
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
68
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
69
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
70
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
71
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
72
- // "newLine": "crlf", /* Set the newline character for emitting files. */
73
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
74
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
75
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
76
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
77
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
78
-
79
- /* Interop Constraints */
80
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
81
- // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
82
- // "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
83
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
84
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
85
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
86
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
87
-
88
- /* Type Checking */
89
- "strict": true, /* Enable all strict type-checking options. */
90
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
91
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
92
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
93
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
94
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
95
- // "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
96
- // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
97
- // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
98
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
99
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
100
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
101
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
102
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
103
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
104
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
105
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
106
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
107
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
108
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
109
-
110
- /* Completeness */
111
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
112
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
113
- }
114
- }
package/vite.config.js DELETED
@@ -1,19 +0,0 @@
1
- import { defineConfig } from "vite";
2
- import wasm from "vite-plugin-wasm";
3
- import topLevelAwait from "vite-plugin-top-level-await";
4
- import { resolve } from "node:path";
5
- import dts from "vite-plugin-dts";
6
-
7
- export default defineConfig({
8
- plugins: [wasm(), topLevelAwait(), dts()],
9
- build: {
10
- minify: true,
11
- lib: {
12
- entry: resolve(__dirname, "src/index.ts"),
13
- name: "mimium_webaudio",
14
- formats: ["iife"],
15
- fileName: () => "mimium-webaudio.js",
16
- },
17
- sourcemap: true,
18
- },
19
- });