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.
Files changed (2) hide show
  1. package/audio-decode.js +12 -5
  2. 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
- export default async function audioDecode (buf) {
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)) )(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)) )(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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "audio-decode",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
4
4
  "description": "Decode audio data in node or browser",
5
5
  "main": "audio-decode.js",
6
6
  "module": "audio-decode.js",