@remotion/media-utils 3.0.0-lambda.355 → 3.0.0-lambda.359
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/dist/create-smooth-svg-path.d.ts +5 -0
- package/dist/create-smooth-svg-path.d.ts.map +1 -0
- package/dist/create-smooth-svg-path.js +30 -0
- package/dist/create-smooth-svg-path.js.map +1 -0
- package/dist/smooth-path.d.ts +5 -0
- package/dist/smooth-path.d.ts.map +1 -0
- package/dist/smooth-path.js +30 -0
- package/dist/smooth-path.js.map +1 -0
- package/dist/visualize-audio-waveform.d.ts +2 -4
- package/dist/visualize-audio-waveform.d.ts.map +1 -1
- package/dist/visualize-audio-waveform.js +11 -16
- package/dist/visualize-audio-waveform.js.map +1 -1
- package/package.json +3 -3
- package/dist/audio-buffer-to-wav.d.ts +0 -15
- package/dist/audio-buffer-to-wav.d.ts.map +0 -1
- package/dist/audio-buffer-to-wav.js +0 -91
- package/dist/audio-buffer-to-wav.js.map +0 -1
- package/dist/audio-url-helpers.d.ts +0 -2
- package/dist/audio-url-helpers.d.ts.map +0 -1
- package/dist/audio-url-helpers.js +0 -17
- package/dist/audio-url-helpers.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-smooth-svg-path.d.ts","sourceRoot":"","sources":["../src/create-smooth-svg-path.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,WAAY;IAAC,MAAM;IAAE,MAAM;CAAC,EAAE,kBA6B7D,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSmoothSvgPath = void 0;
|
|
4
|
+
const createSmoothSvgPath = (points) => {
|
|
5
|
+
return points.reduce((acc, point, i, a) => {
|
|
6
|
+
if (i === 0) {
|
|
7
|
+
return `M ${point[0]},${point[1]}`;
|
|
8
|
+
}
|
|
9
|
+
const p0 = a[i - 2] || a[i - 1];
|
|
10
|
+
const x0 = p0[0];
|
|
11
|
+
const y0 = p0[1];
|
|
12
|
+
const p1 = a[i - 1];
|
|
13
|
+
const x1 = p1[0];
|
|
14
|
+
const y1 = p1[1];
|
|
15
|
+
const x = point[0];
|
|
16
|
+
const y = point[1];
|
|
17
|
+
const cp1x = (2 * x0 + x1) / 3;
|
|
18
|
+
const cp1y = (2 * y0 + y1) / 3;
|
|
19
|
+
const cp2x = (x0 + 2 * x1) / 3;
|
|
20
|
+
const cp2y = (y0 + 2 * y1) / 3;
|
|
21
|
+
const cp3x = (x0 + 4 * x1 + x) / 6;
|
|
22
|
+
const cp3y = (y0 + 4 * y1 + y) / 6;
|
|
23
|
+
if (i === a.length - 1) {
|
|
24
|
+
return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${cp3x},${cp3y} C${x},${y} ${x},${y} ${x},${y}`;
|
|
25
|
+
}
|
|
26
|
+
return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${cp3x},${cp3y}`;
|
|
27
|
+
}, '');
|
|
28
|
+
};
|
|
29
|
+
exports.createSmoothSvgPath = createSmoothSvgPath;
|
|
30
|
+
//# sourceMappingURL=create-smooth-svg-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-smooth-svg-path.js","sourceRoot":"","sources":["../src/create-smooth-svg-path.ts"],"names":[],"mappings":";;;AAAO,MAAM,mBAAmB,GAAG,CAAC,MAA0B,EAAE,EAAE;IACjE,OAAO,MAAM,CAAC,MAAM,CACnB,CAAC,GAAkB,EAAE,KAAuB,EAAE,CAAS,EAAE,CAAC,EAAE,EAAE;QAC7D,IAAI,CAAC,KAAK,CAAC,EAAE;YACZ,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;SACnC;QAED,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAA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,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;IACnE,CAAC,EACD,EAAE,CACF,CAAC;AACH,CAAC,CAAC;AA7BW,QAAA,mBAAmB,uBA6B9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smooth-path.d.ts","sourceRoot":"","sources":["../src/smooth-path.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,WAAY;IAAC,MAAM;IAAE,MAAM;CAAC,EAAE,kBA6B7D,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSmoothSvgPath = void 0;
|
|
4
|
+
const createSmoothSvgPath = (points) => {
|
|
5
|
+
return points.reduce((acc, point, i, a) => {
|
|
6
|
+
if (i === 0) {
|
|
7
|
+
return `M ${point[0]},${point[1]}`;
|
|
8
|
+
}
|
|
9
|
+
const p0 = a[i - 2] || a[i - 1];
|
|
10
|
+
const x0 = p0[0];
|
|
11
|
+
const y0 = p0[1];
|
|
12
|
+
const p1 = a[i - 1];
|
|
13
|
+
const x1 = p1[0];
|
|
14
|
+
const y1 = p1[1];
|
|
15
|
+
const x = point[0];
|
|
16
|
+
const y = point[1];
|
|
17
|
+
const cp1x = (2 * x0 + x1) / 3;
|
|
18
|
+
const cp1y = (2 * y0 + y1) / 3;
|
|
19
|
+
const cp2x = (x0 + 2 * x1) / 3;
|
|
20
|
+
const cp2y = (y0 + 2 * y1) / 3;
|
|
21
|
+
const cp3x = (x0 + 4 * x1 + x) / 6;
|
|
22
|
+
const cp3y = (y0 + 4 * y1 + y) / 6;
|
|
23
|
+
if (i === a.length - 1) {
|
|
24
|
+
return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${cp3x},${cp3y} C${x},${y} ${x},${y} ${x},${y}`;
|
|
25
|
+
}
|
|
26
|
+
return `${acc} C ${cp1x},${cp1y} ${cp2x},${cp2y} ${cp3x},${cp3y}`;
|
|
27
|
+
}, '');
|
|
28
|
+
};
|
|
29
|
+
exports.createSmoothSvgPath = createSmoothSvgPath;
|
|
30
|
+
//# sourceMappingURL=smooth-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smooth-path.js","sourceRoot":"","sources":["../src/smooth-path.ts"],"names":[],"mappings":";;;AAAO,MAAM,mBAAmB,GAAG,CAAC,MAA0B,EAAE,EAAE;IACjE,OAAO,MAAM,CAAC,MAAM,CACnB,CAAC,GAAkB,EAAE,KAAuB,EAAE,CAAS,EAAE,CAAC,EAAE,EAAE;QAC7D,IAAI,CAAC,KAAK,CAAC,EAAE;YACZ,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;SACnC;QAED,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAChC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACjB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACjB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACpB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACjB,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QACjB,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,IAAI,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACnC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvB,OAAO,GAAG,GAAG,MAAM,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;SACjG;QAED,OAAO,GAAG,GAAG,MAAM,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;IACnE,CAAC,EACD,EAAE,CACF,CAAC;AACH,CAAC,CAAC;AA7BW,QAAA,mBAAmB,uBA6B9B"}
|
|
@@ -3,11 +3,9 @@ declare type FnParameters = {
|
|
|
3
3
|
audioData: AudioData;
|
|
4
4
|
frame: number;
|
|
5
5
|
fps: number;
|
|
6
|
-
|
|
6
|
+
windowInSeconds: number;
|
|
7
7
|
numberOfSamples: number;
|
|
8
8
|
};
|
|
9
|
-
export declare const visualizeAudioWaveform: ({
|
|
10
|
-
smoothing?: boolean | undefined;
|
|
11
|
-
}) => number[];
|
|
9
|
+
export declare const visualizeAudioWaveform: ({ ...parameters }: FnParameters) => number[];
|
|
12
10
|
export {};
|
|
13
11
|
//# sourceMappingURL=visualize-audio-waveform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visualize-audio-waveform.d.ts","sourceRoot":"","sources":["../src/visualize-audio-waveform.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAIlC,aAAK,YAAY,GAAG;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,
|
|
1
|
+
{"version":3,"file":"visualize-audio-waveform.d.ts","sourceRoot":"","sources":["../src/visualize-audio-waveform.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAIlC,aAAK,YAAY,GAAG;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACxB,CAAC;AA2CF,eAAO,MAAM,sBAAsB,sBAAqB,YAAY,aAGnE,CAAC"}
|
|
@@ -3,35 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.visualizeAudioWaveform = void 0;
|
|
4
4
|
const get_waveform_portion_1 = require("./get-waveform-portion");
|
|
5
5
|
const cache = {};
|
|
6
|
-
const visualizeAudioWaveformFrame = ({ audioData, frame, fps, numberOfSamples,
|
|
7
|
-
if (
|
|
8
|
-
throw new TypeError(
|
|
6
|
+
const visualizeAudioWaveformFrame = ({ audioData, frame, fps, numberOfSamples, windowInSeconds, }) => {
|
|
7
|
+
if (windowInSeconds * audioData.sampleRate < numberOfSamples) {
|
|
8
|
+
throw new TypeError(windowInSeconds +
|
|
9
9
|
's audiodata does not have ' +
|
|
10
10
|
numberOfSamples +
|
|
11
|
-
' bars. Increase
|
|
11
|
+
' bars. Increase windowInSeconds or decrease numberOfSamples');
|
|
12
12
|
}
|
|
13
13
|
const cacheKey = audioData.resultId + frame + fps + numberOfSamples + 'waveform';
|
|
14
14
|
if (cache[cacheKey]) {
|
|
15
15
|
return cache[cacheKey];
|
|
16
16
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
: frame / fps - waveformDuration / 2;
|
|
17
|
+
const time = frame / fps;
|
|
18
|
+
const max = audioData.durationInSeconds - windowInSeconds / 2;
|
|
19
|
+
const min = windowInSeconds / 2;
|
|
20
|
+
const startTimeInSeconds = Math.min(max, Math.max(min, time - windowInSeconds / 2));
|
|
22
21
|
return (0, get_waveform_portion_1.getWaveformPortion)({
|
|
23
22
|
audioData,
|
|
24
23
|
startTimeInSeconds,
|
|
25
|
-
durationInSeconds:
|
|
24
|
+
durationInSeconds: windowInSeconds,
|
|
26
25
|
numberOfSamples,
|
|
27
|
-
normalize:
|
|
26
|
+
normalize: true,
|
|
28
27
|
});
|
|
29
28
|
};
|
|
30
|
-
const visualizeAudioWaveform = ({
|
|
31
|
-
if (smoothing) {
|
|
32
|
-
// TODO: Add bezier manipulation?
|
|
33
|
-
console.log('nice');
|
|
34
|
-
}
|
|
29
|
+
const visualizeAudioWaveform = ({ ...parameters }) => {
|
|
35
30
|
const data = visualizeAudioWaveformFrame(parameters);
|
|
36
31
|
return data.map((value) => value.amplitude);
|
|
37
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visualize-audio-waveform.js","sourceRoot":"","sources":["../src/visualize-audio-waveform.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;AAG/D,MAAM,KAAK,GAA2B,EAAE,CAAC;AAUzC,MAAM,2BAA2B,GAAG,CAAC,EACpC,SAAS,EACT,KAAK,EACL,GAAG,EACH,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"visualize-audio-waveform.js","sourceRoot":"","sources":["../src/visualize-audio-waveform.ts"],"names":[],"mappings":";;;AAAA,iEAA+D;AAG/D,MAAM,KAAK,GAA2B,EAAE,CAAC;AAUzC,MAAM,2BAA2B,GAAG,CAAC,EACpC,SAAS,EACT,KAAK,EACL,GAAG,EACH,eAAe,EAC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|
3
|
+
"version": "3.0.0-lambda.359+59cc0e49b",
|
|
4
4
|
"description": "Utility functions for audio and video",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"url": "https://github.com/remotion-dev/remotion"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"remotion": "3.0.0-lambda.
|
|
18
|
+
"remotion": "3.0.0-lambda.359+59cc0e49b"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": "^17.0.1",
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "59cc0e49b376f8ab8d310d0522160c67195f44b2"
|
|
36
36
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare function audioBufferToWav(buffer: AudioBuffer, opt: {
|
|
2
|
-
float32: boolean;
|
|
3
|
-
}): ArrayBuffer;
|
|
4
|
-
declare function encodeWAV({ samples, format, sampleRate, numChannels, bitDepth, }: {
|
|
5
|
-
samples: Float32Array;
|
|
6
|
-
format: 3 | 1;
|
|
7
|
-
sampleRate: number;
|
|
8
|
-
numChannels: number;
|
|
9
|
-
bitDepth: 32 | 16;
|
|
10
|
-
}): ArrayBuffer;
|
|
11
|
-
declare function interleave(inputL: Float32Array, inputR: Float32Array): Float32Array;
|
|
12
|
-
declare function writeFloat32(output: DataView, offset: number, input: Float32Array): void;
|
|
13
|
-
declare function floatTo16BitPCM(output: DataView, offset: number, input: Float32Array): void;
|
|
14
|
-
declare function writeString(view: DataView, offset: number, string: string): void;
|
|
15
|
-
//# sourceMappingURL=audio-buffer-to-wav.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audio-buffer-to-wav.d.ts","sourceRoot":"","sources":["../src/audio-buffer-to-wav.ts"],"names":[],"mappings":"AAEA,iBAAS,gBAAgB,CACxB,MAAM,EAAE,WAAW,EACnB,GAAG,EAAE;IACJ,OAAO,EAAE,OAAO,CAAC;CACjB,eAqBD;AAED,iBAAS,SAAS,CAAC,EAClB,OAAO,EACP,MAAM,EACN,UAAU,EACV,WAAW,EACX,QAAQ,GACR,EAAE;IACF,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC;CAClB,eAyCA;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,gBAc7D;AAED,iBAAS,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,QAI1E;AAED,iBAAS,eAAe,CACvB,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY,QAMnB;AAED,iBAAS,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAIlE"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = audioBufferToWav;
|
|
3
|
-
function audioBufferToWav(buffer, opt) {
|
|
4
|
-
const numChannels = buffer.numberOfChannels;
|
|
5
|
-
const { sampleRate } = buffer;
|
|
6
|
-
const format = opt.float32 ? 3 : 1;
|
|
7
|
-
const bitDepth = format === 3 ? 32 : 16;
|
|
8
|
-
let result;
|
|
9
|
-
if (numChannels === 2) {
|
|
10
|
-
result = interleave(buffer.getChannelData(0), buffer.getChannelData(1));
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
result = buffer.getChannelData(0);
|
|
14
|
-
}
|
|
15
|
-
return encodeWAV({
|
|
16
|
-
samples: result,
|
|
17
|
-
format,
|
|
18
|
-
sampleRate,
|
|
19
|
-
numChannels,
|
|
20
|
-
bitDepth,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function encodeWAV({ samples, format, sampleRate, numChannels, bitDepth, }) {
|
|
24
|
-
const bytesPerSample = bitDepth / 8;
|
|
25
|
-
const blockAlign = numChannels * bytesPerSample;
|
|
26
|
-
const buffer = new ArrayBuffer(44 + samples.length * bytesPerSample);
|
|
27
|
-
const view = new DataView(buffer);
|
|
28
|
-
/* RIFF identifier */
|
|
29
|
-
writeString(view, 0, 'RIFF');
|
|
30
|
-
/* RIFF chunk length */
|
|
31
|
-
view.setUint32(4, 36 + samples.length * bytesPerSample, true);
|
|
32
|
-
/* RIFF type */
|
|
33
|
-
writeString(view, 8, 'WAVE');
|
|
34
|
-
/* format chunk identifier */
|
|
35
|
-
writeString(view, 12, 'fmt ');
|
|
36
|
-
/* format chunk length */
|
|
37
|
-
view.setUint32(16, 16, true);
|
|
38
|
-
/* sample format (raw) */
|
|
39
|
-
view.setUint16(20, format, true);
|
|
40
|
-
/* channel count */
|
|
41
|
-
view.setUint16(22, numChannels, true);
|
|
42
|
-
/* sample rate */
|
|
43
|
-
view.setUint32(24, sampleRate, true);
|
|
44
|
-
/* byte rate (sample rate * block align) */
|
|
45
|
-
view.setUint32(28, sampleRate * blockAlign, true);
|
|
46
|
-
/* block align (channel count * bytes per sample) */
|
|
47
|
-
view.setUint16(32, blockAlign, true);
|
|
48
|
-
/* bits per sample */
|
|
49
|
-
view.setUint16(34, bitDepth, true);
|
|
50
|
-
/* data chunk identifier */
|
|
51
|
-
writeString(view, 36, 'data');
|
|
52
|
-
/* data chunk length */
|
|
53
|
-
view.setUint32(40, samples.length * bytesPerSample, true);
|
|
54
|
-
if (format === 1) {
|
|
55
|
-
// Raw PCM
|
|
56
|
-
floatTo16BitPCM(view, 44, samples);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
writeFloat32(view, 44, samples);
|
|
60
|
-
}
|
|
61
|
-
return buffer;
|
|
62
|
-
}
|
|
63
|
-
function interleave(inputL, inputR) {
|
|
64
|
-
const length = inputL.length + inputR.length;
|
|
65
|
-
const result = new Float32Array(length);
|
|
66
|
-
let index = 0;
|
|
67
|
-
let inputIndex = 0;
|
|
68
|
-
while (index < length) {
|
|
69
|
-
result[index++] = inputL[inputIndex];
|
|
70
|
-
result[index++] = inputR[inputIndex];
|
|
71
|
-
inputIndex++;
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
function writeFloat32(output, offset, input) {
|
|
76
|
-
for (let i = 0; i < input.length; i++, offset += 4) {
|
|
77
|
-
output.setFloat32(offset, input[i], true);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function floatTo16BitPCM(output, offset, input) {
|
|
81
|
-
for (let i = 0; i < input.length; i++, offset += 2) {
|
|
82
|
-
const s = Math.max(-1, Math.min(1, input[i]));
|
|
83
|
-
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7fff, true);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function writeString(view, offset, string) {
|
|
87
|
-
for (let i = 0; i < string.length; i++) {
|
|
88
|
-
view.setUint8(offset + i, string.charCodeAt(i));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=audio-buffer-to-wav.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audio-buffer-to-wav.js","sourceRoot":"","sources":["../src/audio-buffer-to-wav.ts"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG,gBAAgB,CAAC;AAElC,SAAS,gBAAgB,CACxB,MAAmB,EACnB,GAEC;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAC5C,MAAM,EAAC,UAAU,EAAC,GAAG,MAAM,CAAC;IAC5B,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CA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AU,CAAC,CAAC,CAAC,CAAC,CAAC;KAChD;AACF,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audio-url-helpers.d.ts","sourceRoot":"","sources":["../src/audio-url-helpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,WAAY,WAAW,WAYhD,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uint8ToBase64 = void 0;
|
|
4
|
-
const uint8ToBase64 = (buffer) => {
|
|
5
|
-
const wavAsArrayBuffer = audioBufferToWav(buffer, {
|
|
6
|
-
float32: false,
|
|
7
|
-
});
|
|
8
|
-
let binary = '';
|
|
9
|
-
const bytes = new Uint8Array(wavAsArrayBuffer);
|
|
10
|
-
const len = bytes.byteLength;
|
|
11
|
-
for (let i = 0; i < len; i++) {
|
|
12
|
-
binary += String.fromCharCode(bytes[i]);
|
|
13
|
-
}
|
|
14
|
-
return window.btoa(binary);
|
|
15
|
-
};
|
|
16
|
-
exports.uint8ToBase64 = uint8ToBase64;
|
|
17
|
-
//# sourceMappingURL=audio-url-helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"audio-url-helpers.js","sourceRoot":"","sources":["../src/audio-url-helpers.ts"],"names":[],"mappings":";;;AAAO,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAE,EAAE;IACpD,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,EAAE;QACjD,OAAO,EAAE,KAAK;KACd,CAAC,CAAC;IACH,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC;IAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QAC7B,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;KACxC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC,CAAC;AAZW,QAAA,aAAa,iBAYxB"}
|