You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
907 B
29 lines
907 B
// src/components/audioWorker.js
|
|
/* eslint-disable no-restricted-globals */
|
|
|
|
// This worker receives a base64-encoded string, decodes it into an ArrayBuffer,
|
|
// and sends it back to the main thread.
|
|
|
|
onmessage = (e) => {
|
|
const { type, base64data } = e.data;
|
|
|
|
if (type === 'DECODE_BASE64') {
|
|
try {
|
|
// Decode base64 to a binary string
|
|
const binaryString = atob(base64data);
|
|
// Convert binary string to a typed array
|
|
const len = binaryString.length;
|
|
const bytes = new Uint8Array(len);
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
bytes[i] = binaryString.charCodeAt(i);
|
|
}
|
|
|
|
// Post the ArrayBuffer back to the main thread
|
|
postMessage({ success: true, buffer: bytes.buffer }, [bytes.buffer]);
|
|
} catch (err) {
|
|
console.error('Worker: Error decoding base64 data', err);
|
|
postMessage({ success: false, error: 'Decoding error' });
|
|
}
|
|
}
|
|
};
|
|
|