audio-decode 2.1.4 → 2.1.5
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/audio-decode.js +12 -5
- package/package.json +1 -1
package/audio-decode.js
CHANGED
|
@@ -6,9 +6,16 @@
|
|
|
6
6
|
import getType from 'audio-type';
|
|
7
7
|
import AudioBufferShim from 'audio-buffer';
|
|
8
8
|
|
|
9
|
-
const AudioBuffer = globalThis.AudioBuffer || AudioBufferShim
|
|
9
|
+
const AudioBuffer = globalThis.AudioBuffer || AudioBufferShim;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Decode an audio buffer.
|
|
13
|
+
*
|
|
14
|
+
* @param {ArrayBuffer | Uint8Array} buf - The audio data to decode.
|
|
15
|
+
* @returns {Promise<AudioBuffer>} A promise that resolves to the decoded audio buffer.
|
|
16
|
+
* @throws {Error} Throws an error if the decode target is invalid or if the audio format is not supported.
|
|
17
|
+
*/
|
|
18
|
+
export default async function audioDecode(buf) {
|
|
12
19
|
if (!buf && !(buf.length || buf.buffer)) throw Error('Bad decode target')
|
|
13
20
|
buf = new Uint8Array(buf.buffer || buf)
|
|
14
21
|
|
|
@@ -49,15 +56,15 @@ export const decoders = {
|
|
|
49
56
|
async wav(buf) {
|
|
50
57
|
let module = await import('node-wav')
|
|
51
58
|
let { decode } = module.default
|
|
52
|
-
return (decoders.wav = buf => buf && createBuffer(decode(buf))
|
|
59
|
+
return (decoders.wav = buf => buf && createBuffer(decode(buf)))(buf)
|
|
53
60
|
},
|
|
54
61
|
async qoa(buf) {
|
|
55
62
|
let { decode } = await import('qoa-format')
|
|
56
|
-
return (decoders.qoa = buf => buf && createBuffer(decode(buf))
|
|
63
|
+
return (decoders.qoa = buf => buf && createBuffer(decode(buf)))(buf)
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
function createBuffer({channelData, sampleRate}) {
|
|
67
|
+
function createBuffer({ channelData, sampleRate }) {
|
|
61
68
|
let audioBuffer = new AudioBuffer({
|
|
62
69
|
sampleRate,
|
|
63
70
|
length: channelData[0].length,
|