med-scribe-alliance-ts-sdk 2.0.7 → 2.0.8
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/index.d.ts +18 -4
- package/dist/index.mjs +124 -98
- package/dist/worker.bundle.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -361,6 +361,8 @@ export interface PollOptions {
|
|
|
361
361
|
maxAttempts?: number;
|
|
362
362
|
intervalMs?: number;
|
|
363
363
|
onProgress?: (status: GetSessionStatusResponse) => void;
|
|
364
|
+
/** AbortSignal to cancel polling early. */
|
|
365
|
+
signal?: AbortSignal;
|
|
364
366
|
}
|
|
365
367
|
export interface PatchSessionRequest {
|
|
366
368
|
user_status?: string;
|
|
@@ -894,6 +896,10 @@ export declare class SessionManager {
|
|
|
894
896
|
*/
|
|
895
897
|
private isTerminalStatus;
|
|
896
898
|
private sleep;
|
|
899
|
+
/**
|
|
900
|
+
* Sleep that can be interrupted by an AbortSignal.
|
|
901
|
+
*/
|
|
902
|
+
private sleepWithAbort;
|
|
897
903
|
}
|
|
898
904
|
export interface WorkerManagerConfig {
|
|
899
905
|
/** Path to the compiled shared-worker.js bundle. Required for SharedWorker mode. */
|
|
@@ -965,10 +971,11 @@ export declare class RecordingManager {
|
|
|
965
971
|
*/
|
|
966
972
|
stop(): Promise<StopRecordingResult>;
|
|
967
973
|
/**
|
|
968
|
-
*
|
|
969
|
-
* Used by cancelSession — we don't want the server to start processing
|
|
974
|
+
* Immediately stop the recorder without calling endSession or waiting for uploads.
|
|
975
|
+
* Used by cancelSession — we don't want the server to start processing
|
|
976
|
+
* and don't want to block on pending uploads.
|
|
970
977
|
*/
|
|
971
|
-
forceStop():
|
|
978
|
+
forceStop(): void;
|
|
972
979
|
/**
|
|
973
980
|
* Update the auth token for the active recording.
|
|
974
981
|
* Forwards to the active recorder (which updates WorkerManager/transport).
|
|
@@ -1011,8 +1018,9 @@ export declare class RecordingManager {
|
|
|
1011
1018
|
*/
|
|
1012
1019
|
private dispatchStartError;
|
|
1013
1020
|
/**
|
|
1014
|
-
* Extract failed chunks with their
|
|
1021
|
+
* Extract failed chunks with their blobs from the recorder
|
|
1015
1022
|
* before cleanup destroys the recorder state.
|
|
1023
|
+
* Supports both ChunkedRecorder and SingleRecorder.
|
|
1016
1024
|
*/
|
|
1017
1025
|
private preserveRetryContext;
|
|
1018
1026
|
/**
|
|
@@ -1052,6 +1060,12 @@ export declare class HttpTransport implements ITransport {
|
|
|
1052
1060
|
*/
|
|
1053
1061
|
private handleErrorResponse;
|
|
1054
1062
|
private extractHeaders;
|
|
1063
|
+
/**
|
|
1064
|
+
* Cancel in-flight fetch requests by aborting (best-effort).
|
|
1065
|
+
* HttpTransport has no pending-request map, so this is a no-op.
|
|
1066
|
+
* Included for ITransport interface parity with IpcTransport.
|
|
1067
|
+
*/
|
|
1068
|
+
destroy(): void;
|
|
1055
1069
|
private getRetryOptions;
|
|
1056
1070
|
}
|
|
1057
1071
|
export declare class IpcTransport implements ITransport {
|
package/dist/index.mjs
CHANGED
|
@@ -204,7 +204,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
204
204
|
message: e.string(),
|
|
205
205
|
audio_files_received: e.number().int(),
|
|
206
206
|
audio_files: e.array(e.string())
|
|
207
|
-
}),
|
|
207
|
+
}), re = e.object({
|
|
208
208
|
session_id: e.string().min(1, "session_id is required"),
|
|
209
209
|
status: e.string(),
|
|
210
210
|
created_at: e.string(),
|
|
@@ -236,16 +236,16 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
236
236
|
mobile: e.number().optional()
|
|
237
237
|
}).optional(),
|
|
238
238
|
message: e.string().optional()
|
|
239
|
-
}),
|
|
239
|
+
}), A = e.object({
|
|
240
240
|
session_id: e.string().min(1, "session_id is required"),
|
|
241
241
|
status: e.string(),
|
|
242
242
|
message: e.string()
|
|
243
|
-
}),
|
|
243
|
+
}), j = e.object({
|
|
244
244
|
session_id: e.string().min(1, "session_id is required"),
|
|
245
245
|
template_id: e.string(),
|
|
246
246
|
status: e.string(),
|
|
247
247
|
message: e.string()
|
|
248
|
-
}),
|
|
248
|
+
}), M = e.string().min(1, "Session ID is required"), N = e.object({
|
|
249
249
|
templates: e.array(e.string()).min(1, "templates must contain at least one item").max(2, "templates cannot have more than 2 items"),
|
|
250
250
|
uploadType: e.string().optional(),
|
|
251
251
|
communicationProtocol: e.string().optional(),
|
|
@@ -262,7 +262,7 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
262
262
|
mobile: e.number().optional()
|
|
263
263
|
}).optional(),
|
|
264
264
|
txnId: e.string().optional()
|
|
265
|
-
}),
|
|
265
|
+
}), P = class {
|
|
266
266
|
validateDiscoveryResponse(e) {
|
|
267
267
|
this.parseWithValidationError(D, e, "Invalid discovery response");
|
|
268
268
|
}
|
|
@@ -279,22 +279,22 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
279
279
|
this.parseWithValidationError(ne, e, "Invalid EndSessionResponse");
|
|
280
280
|
}
|
|
281
281
|
validateGetSessionStatusResponse(e) {
|
|
282
|
-
this.parseWithValidationError(
|
|
282
|
+
this.parseWithValidationError(re, e, "Invalid GetSessionStatusResponse");
|
|
283
283
|
}
|
|
284
284
|
validateSessionId(e) {
|
|
285
|
-
this.parseWithValidationError(
|
|
285
|
+
this.parseWithValidationError(M, e, "Invalid session ID");
|
|
286
286
|
}
|
|
287
287
|
validateRecordingOptions(e) {
|
|
288
|
-
this.parseWithValidationError(
|
|
288
|
+
this.parseWithValidationError(N, e, "Invalid RecordingOptions");
|
|
289
289
|
}
|
|
290
290
|
validatePatchSessionRequest(e) {
|
|
291
291
|
this.parseWithValidationError(ee, e, "Invalid PatchSessionRequest");
|
|
292
292
|
}
|
|
293
293
|
validatePatchSessionResponse(e) {
|
|
294
|
-
this.parseWithValidationError(
|
|
294
|
+
this.parseWithValidationError(A, e, "Invalid PatchSessionResponse");
|
|
295
295
|
}
|
|
296
296
|
validateProcessTemplateResponse(e) {
|
|
297
|
-
this.parseWithValidationError(
|
|
297
|
+
this.parseWithValidationError(j, e, "Invalid ProcessTemplateResponse");
|
|
298
298
|
}
|
|
299
299
|
validateAgainstDiscovery(e, t) {
|
|
300
300
|
try {
|
|
@@ -337,26 +337,26 @@ var r = "/.well-known/medscribealliance", i = 3600 * 1e3, a = /* @__PURE__ */ fu
|
|
|
337
337
|
};
|
|
338
338
|
//#endregion
|
|
339
339
|
//#region src/utils/retry.ts
|
|
340
|
-
async function
|
|
340
|
+
async function F(e, t = {}) {
|
|
341
341
|
let { maxRetries: n = 3, delayMs: r = f, onRetry: i } = t, a = null;
|
|
342
342
|
for (let t = 0; t <= n; t++) try {
|
|
343
343
|
return await e();
|
|
344
344
|
} catch (e) {
|
|
345
|
-
if (a = e instanceof Error ? e : Error(String(e)),
|
|
345
|
+
if (a = e instanceof Error ? e : Error(String(e)), I(e?.httpStatus ?? e?.statusCode ?? e?.status)) throw a;
|
|
346
346
|
if (t >= n || i && i(t + 1, a) === !1) break;
|
|
347
|
-
await
|
|
347
|
+
await L(r);
|
|
348
348
|
}
|
|
349
349
|
throw a ?? /* @__PURE__ */ Error("Retry failed: unknown error");
|
|
350
350
|
}
|
|
351
|
-
function
|
|
351
|
+
function I(e) {
|
|
352
352
|
return typeof e == "number" ? e >= 400 && e < 500 && e !== 408 && e !== 429 : !1;
|
|
353
353
|
}
|
|
354
|
-
function
|
|
354
|
+
function L(e) {
|
|
355
355
|
return new Promise((t) => setTimeout(t, e));
|
|
356
356
|
}
|
|
357
357
|
//#endregion
|
|
358
358
|
//#region src/transport/http-transport.ts
|
|
359
|
-
var
|
|
359
|
+
var R = class {
|
|
360
360
|
constructor(e) {
|
|
361
361
|
this.tokenRefreshPromise = null, this.accessToken = e.accessToken, this.debug = e.debug ?? !1, this.onUnauthorized = e.onUnauthorized;
|
|
362
362
|
}
|
|
@@ -365,7 +365,7 @@ var z = class {
|
|
|
365
365
|
}
|
|
366
366
|
async request(e) {
|
|
367
367
|
try {
|
|
368
|
-
return await
|
|
368
|
+
return await F(() => this.executeRequest(e), this.getRetryOptions());
|
|
369
369
|
} catch (t) {
|
|
370
370
|
throw t instanceof p ? t : new x(`Network error: ${t instanceof Error ? t.message : "Unknown error"}`, {
|
|
371
371
|
url: e.url,
|
|
@@ -464,12 +464,13 @@ var z = class {
|
|
|
464
464
|
t[n] = e;
|
|
465
465
|
}), t;
|
|
466
466
|
}
|
|
467
|
+
destroy() {}
|
|
467
468
|
getRetryOptions() {
|
|
468
469
|
return { onRetry: (e, t) => {
|
|
469
470
|
this.debug && console.log(`[ScribeSDK] Retry attempt ${e}:`, t.message);
|
|
470
471
|
} };
|
|
471
472
|
}
|
|
472
|
-
},
|
|
473
|
+
}, z = class {
|
|
473
474
|
constructor(e) {
|
|
474
475
|
this.pendingRequests = /* @__PURE__ */ new Map(), this.correlationCounter = 0, this.tokenRefreshPromise = null, this.bridge = e.bridge, this.accessToken = e.accessToken, this.debug = e.debug ?? !1, this.onUnauthorized = e.onUnauthorized, this.bridge.onResponse((e) => {
|
|
475
476
|
this.handleResponse(e);
|
|
@@ -480,7 +481,7 @@ var z = class {
|
|
|
480
481
|
}
|
|
481
482
|
async request(e) {
|
|
482
483
|
try {
|
|
483
|
-
return await
|
|
484
|
+
return await F(() => this.executeRequest(e), this.getRetryOptions());
|
|
484
485
|
} catch (t) {
|
|
485
486
|
throw t instanceof p ? t : new x(`IPC error: ${t instanceof Error ? t.message : "Unknown error"}`, {
|
|
486
487
|
url: e.url,
|
|
@@ -621,7 +622,7 @@ var z = class {
|
|
|
621
622
|
};
|
|
622
623
|
//#endregion
|
|
623
624
|
//#region src/discovery/resolved-config.ts
|
|
624
|
-
function
|
|
625
|
+
function B(e) {
|
|
625
626
|
try {
|
|
626
627
|
let t = /* @__PURE__ */ new Map(), n = e.models ?? [];
|
|
627
628
|
for (let e of n) e.id && typeof e.max_session_duration_seconds == "number" && t.set(e.id, e.max_session_duration_seconds);
|
|
@@ -645,7 +646,7 @@ function V(e) {
|
|
|
645
646
|
}
|
|
646
647
|
//#endregion
|
|
647
648
|
//#region src/discovery/discovery-manager.ts
|
|
648
|
-
var
|
|
649
|
+
var V = class {
|
|
649
650
|
constructor(e, t, n = !1) {
|
|
650
651
|
this.cachedDocument = null, this.resolvedConfig = null, this.cacheTimestamp = 0, this.cacheTtlMs = i, this.transport = e, this.validator = t, this.debug = n;
|
|
651
652
|
}
|
|
@@ -659,7 +660,7 @@ var H = class {
|
|
|
659
660
|
url: n
|
|
660
661
|
});
|
|
661
662
|
this.validator.validateDiscoveryResponse(i.data);
|
|
662
|
-
let a = i.data, o =
|
|
663
|
+
let a = i.data, o = B(a);
|
|
663
664
|
return this.cachedDocument = a, this.resolvedConfig = o, this.cacheTimestamp = Date.now(), this.debug && console.log("[ScribeSDK] Discovery complete:", a.service?.name ?? a.protocol), o;
|
|
664
665
|
} catch (t) {
|
|
665
666
|
throw t instanceof h ? t : new h(`Failed to fetch discovery document: ${t instanceof Error ? t.message : "Unknown error"}`, { baseUrl: e });
|
|
@@ -709,7 +710,7 @@ var H = class {
|
|
|
709
710
|
isCacheValid() {
|
|
710
711
|
return Date.now() - this.cacheTimestamp < this.cacheTtlMs;
|
|
711
712
|
}
|
|
712
|
-
},
|
|
713
|
+
}, H = class {
|
|
713
714
|
constructor(e, t, n = !1) {
|
|
714
715
|
this.currentSession = null, this.transport = e, this.validator = t, this.debug = n;
|
|
715
716
|
}
|
|
@@ -805,6 +806,7 @@ var H = class {
|
|
|
805
806
|
intervalMs: a
|
|
806
807
|
});
|
|
807
808
|
for (let t = 1; t <= i; t++) {
|
|
809
|
+
if (n?.signal?.aborted) throw new p("Polling was aborted", "polling_aborted", void 0, { session_id: r });
|
|
808
810
|
let o = await this.getSessionStatus(e, r);
|
|
809
811
|
if (n?.onProgress) try {
|
|
810
812
|
n.onProgress(o);
|
|
@@ -812,7 +814,7 @@ var H = class {
|
|
|
812
814
|
console.error("[ScribeSDK] Error in poll onProgress callback:", e);
|
|
813
815
|
}
|
|
814
816
|
if (this.isTerminalStatus(o.status)) return this.debug && console.log("[ScribeSDK] Poll complete:", r, o.status, `(attempt ${t})`), o;
|
|
815
|
-
t < i && await this.
|
|
817
|
+
t < i && await this.sleepWithAbort(a, n?.signal);
|
|
816
818
|
}
|
|
817
819
|
throw new p(`Polling timed out after ${i} attempts for session '${r}'`, "polling_timeout", void 0, {
|
|
818
820
|
session_id: r,
|
|
@@ -834,15 +836,27 @@ var H = class {
|
|
|
834
836
|
sleep(e) {
|
|
835
837
|
return new Promise((t) => setTimeout(t, e));
|
|
836
838
|
}
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
839
|
+
sleepWithAbort(e, t) {
|
|
840
|
+
return t ? new Promise((n, r) => {
|
|
841
|
+
if (t.aborted) {
|
|
842
|
+
r(new p("Polling was aborted", "polling_aborted"));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
let i = setTimeout(n, e);
|
|
846
|
+
t.addEventListener("abort", () => {
|
|
847
|
+
clearTimeout(i), r(new p("Polling was aborted", "polling_aborted"));
|
|
848
|
+
}, { once: !0 });
|
|
849
|
+
}) : this.sleep(e);
|
|
850
|
+
}
|
|
851
|
+
}, U = 1024, W = 16e3;
|
|
852
|
+
U / W, W / U;
|
|
853
|
+
var G = {
|
|
840
854
|
m4a: "audio/m4a",
|
|
841
855
|
wav: "audio/wav",
|
|
842
856
|
mp3: "audio/mpeg"
|
|
843
|
-
},
|
|
857
|
+
}, K = class {
|
|
844
858
|
constructor(e, t) {
|
|
845
|
-
this.vadPast = [], this.lastClipIndex = 0, this.
|
|
859
|
+
this.vadPast = [], this.lastClipIndex = 0, this.silDurationAcc = 0, this.micVad = null, this.micStream = null, this.isLoading = !0, this.isRecording = !1, this.noSpeechStartTime = null, this.lastWarningTime = null;
|
|
846
860
|
let n = e.samplingRate;
|
|
847
861
|
this.samplingRate = n, this.prefLengthSamples = e.prefChunkLength * n, this.despLengthSamples = e.despChunkLength * n, this.maxLengthSamples = e.maxChunkLength * n, this.shortThreshold = (e.shortSilenceThreshold ?? .1) * n, this.longThreshold = (e.longSilenceThreshold ?? .5) * n, this.frameSize = e.frameSize ?? 1024, this.speechPadFrames = e.preSpeechPadFrames ?? 20, this.callbackRegistry = t;
|
|
848
862
|
}
|
|
@@ -907,7 +921,7 @@ var K = {
|
|
|
907
921
|
this.stopMicStream(), this.isRecording = !1;
|
|
908
922
|
}
|
|
909
923
|
reset() {
|
|
910
|
-
this.destroy(), this.vadPast = [], this.lastClipIndex = 0, this.
|
|
924
|
+
this.destroy(), this.vadPast = [], this.lastClipIndex = 0, this.silDurationAcc = 0, this.noSpeechStartTime = null, this.lastWarningTime = null, this.isLoading = !0, this.micVad = null;
|
|
911
925
|
}
|
|
912
926
|
updateChunkLengths(e) {
|
|
913
927
|
let t = e.samplingRate ?? this.samplingRate;
|
|
@@ -940,7 +954,7 @@ var K = {
|
|
|
940
954
|
let t = !1;
|
|
941
955
|
this.vadPast.length > 0 && (e === 0 && (this.silDurationAcc += 1), e === 1 && (this.silDurationAcc = 0));
|
|
942
956
|
let n = (this.vadPast.length - this.lastClipIndex) * this.frameSize, r = this.silDurationAcc * this.frameSize;
|
|
943
|
-
return n > this.prefLengthSamples && r > this.longThreshold && (this.lastClipIndex = this.vadPast.length - Math.min(Math.floor(this.silDurationAcc / 2), 5), this.
|
|
957
|
+
return n > this.prefLengthSamples && r > this.longThreshold || n > this.despLengthSamples && r > this.shortThreshold ? (this.lastClipIndex = this.vadPast.length - Math.min(Math.floor(this.silDurationAcc / 2), 5), this.silDurationAcc = 0, t = !0) : n >= this.maxLengthSamples && (this.lastClipIndex = this.vadPast.length, this.silDurationAcc = 0, t = !0), this.vadPast.push(e), t && (this.vadPast = this.vadPast.slice(this.lastClipIndex), this.lastClipIndex = 0), t;
|
|
944
958
|
}
|
|
945
959
|
checkSilence(e) {
|
|
946
960
|
let t = Date.now();
|
|
@@ -969,7 +983,7 @@ var K = {
|
|
|
969
983
|
} catch {}
|
|
970
984
|
this.micStream = null;
|
|
971
985
|
}
|
|
972
|
-
},
|
|
986
|
+
}, q = class {
|
|
973
987
|
constructor(e, t) {
|
|
974
988
|
this.currentSampleLength = 0, this.currentFrameLength = 0, this.samplingRate = e, this.incrementalAllocationSize = Math.floor(e * t), this.buffer = new Float32Array(this.incrementalAllocationSize);
|
|
975
989
|
}
|
|
@@ -1019,7 +1033,7 @@ var K = {
|
|
|
1019
1033
|
formatTimestamp(e) {
|
|
1020
1034
|
return `${Math.floor(e / 60).toString().padStart(2, "0")}:${(e % 60).toFixed(6).padStart(9, "0")}`;
|
|
1021
1035
|
}
|
|
1022
|
-
},
|
|
1036
|
+
}, J = class {
|
|
1023
1037
|
constructor() {
|
|
1024
1038
|
this.chunks = [], this.successfulUploads = [], this.totalRawSamples = 0, this.totalRawFrames = 0, this.totalInsertedSamples = 0, this.totalInsertedFrames = 0;
|
|
1025
1039
|
}
|
|
@@ -1086,7 +1100,7 @@ var K = {
|
|
|
1086
1100
|
return [...this.successfulUploads];
|
|
1087
1101
|
}
|
|
1088
1102
|
getFailedUploads() {
|
|
1089
|
-
return this.chunks.filter((e) => e.status
|
|
1103
|
+
return this.chunks.filter((e) => e.status === "failure").map((e) => e.fileName);
|
|
1090
1104
|
}
|
|
1091
1105
|
getFailedChunksWithBlobs() {
|
|
1092
1106
|
let e = [];
|
|
@@ -1098,13 +1112,22 @@ var K = {
|
|
|
1098
1112
|
});
|
|
1099
1113
|
}), e;
|
|
1100
1114
|
}
|
|
1115
|
+
markPendingAsFailed() {
|
|
1116
|
+
for (let e = 0; e < this.chunks.length; e++) this.chunks[e].status === "pending" && (this.chunks[e] = {
|
|
1117
|
+
fileName: this.chunks[e].fileName,
|
|
1118
|
+
timestamp: this.chunks[e].timestamp,
|
|
1119
|
+
response: "Upload did not complete (timed out or worker unresponsive)",
|
|
1120
|
+
status: "failure",
|
|
1121
|
+
fileBlob: new Blob()
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1101
1124
|
resetInstance() {
|
|
1102
1125
|
this.chunks = [], this.successfulUploads = [], this.totalRawSamples = 0, this.totalRawFrames = 0, this.totalInsertedSamples = 0, this.totalInsertedFrames = 0;
|
|
1103
1126
|
}
|
|
1104
1127
|
};
|
|
1105
1128
|
//#endregion
|
|
1106
1129
|
//#region src/audio/mp3-encoder.ts
|
|
1107
|
-
function
|
|
1130
|
+
function Y(e, t = W, r = 128) {
|
|
1108
1131
|
try {
|
|
1109
1132
|
let i = new n.Mp3Encoder(1, t, r), a = new Int16Array(e.length);
|
|
1110
1133
|
for (let t = 0; t < e.length; t++) {
|
|
@@ -1114,14 +1137,14 @@ function X(e, t = G, r = 128) {
|
|
|
1114
1137
|
let o = [], s = i.encodeBuffer(a);
|
|
1115
1138
|
s && s.length > 0 && o.push(s);
|
|
1116
1139
|
let c = i.flush();
|
|
1117
|
-
return c && c.length > 0 && o.push(c), o.length === 0 ? null : new Blob(o, { type:
|
|
1140
|
+
return c && c.length > 0 && o.push(c), o.length === 0 ? null : new Blob(o, { type: G.mp3 });
|
|
1118
1141
|
} catch (e) {
|
|
1119
1142
|
return console.error("[ScribeSDK] MP3 encoding failed:", e), null;
|
|
1120
1143
|
}
|
|
1121
1144
|
}
|
|
1122
1145
|
//#endregion
|
|
1123
1146
|
//#region src/worker/worker-manager.ts
|
|
1124
|
-
var
|
|
1147
|
+
var ie = class {
|
|
1125
1148
|
constructor(e, t, n, r) {
|
|
1126
1149
|
if (this.worker = null, this.port = null, this.useWorker = !1, this.uploadUrl = "", this.uploadHeaders = {}, this.pendingUploads = /* @__PURE__ */ new Set(), this.allUploadsResolver = null, this.callbackRegistry = e, this.fileManager = t, this.transport = n, !r?.forceMainThread && typeof SharedWorker < "u" && r?.workerScriptUrl) try {
|
|
1127
1150
|
this.worker = new SharedWorker(r.workerScriptUrl, { name: "scribe-sdk-worker" }), this.port = this.worker.port, this.port.onmessage = (e) => {
|
|
@@ -1139,7 +1162,9 @@ var re = class {
|
|
|
1139
1162
|
}
|
|
1140
1163
|
waitForAllUploads() {
|
|
1141
1164
|
return this.useWorker && this.port ? new Promise((e) => {
|
|
1142
|
-
this.allUploadsResolver = e, this.postToWorker({ type: "wait_for_all_uploads" })
|
|
1165
|
+
this.allUploadsResolver = e, this.postToWorker({ type: "wait_for_all_uploads" }), setTimeout(() => {
|
|
1166
|
+
this.allUploadsResolver &&= (console.warn("[ScribeSDK] waitForAllUploads timed out after 15s"), this.allUploadsResolver(), null);
|
|
1167
|
+
}, 15e3);
|
|
1143
1168
|
}) : Promise.all(this.pendingUploads).then(() => {});
|
|
1144
1169
|
}
|
|
1145
1170
|
updateAuthToken(e) {
|
|
@@ -1215,7 +1240,7 @@ var re = class {
|
|
|
1215
1240
|
async doMainThreadUpload(e, t, n) {
|
|
1216
1241
|
let r = null;
|
|
1217
1242
|
try {
|
|
1218
|
-
if (r =
|
|
1243
|
+
if (r = Y(e), !r) {
|
|
1219
1244
|
this.fileManager.markFailure(n, new Blob(), "MP3 encoding failed"), this.callbackRegistry.dispatch("onUploadEvent", {
|
|
1220
1245
|
type: "failed",
|
|
1221
1246
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -1259,9 +1284,9 @@ var re = class {
|
|
|
1259
1284
|
}
|
|
1260
1285
|
});
|
|
1261
1286
|
}
|
|
1262
|
-
},
|
|
1287
|
+
}, X = class {
|
|
1263
1288
|
constructor(e, t, n, r) {
|
|
1264
|
-
this._isPaused = !1, this.initialized = !1, this.callbackRegistry = e, this.bufferManager = new
|
|
1289
|
+
this._isPaused = !1, this.initialized = !1, this.callbackRegistry = e, this.bufferManager = new q(W, 25), this.fileManager = new J();
|
|
1265
1290
|
let i = {
|
|
1266
1291
|
prefChunkLength: n?.prefChunkLength ?? 10,
|
|
1267
1292
|
despChunkLength: n?.despChunkLength ?? 20,
|
|
@@ -1272,37 +1297,15 @@ var re = class {
|
|
|
1272
1297
|
shortSilenceThreshold: n?.shortSilenceThreshold,
|
|
1273
1298
|
longSilenceThreshold: n?.longSilenceThreshold
|
|
1274
1299
|
};
|
|
1275
|
-
this.vadClient = new
|
|
1300
|
+
this.vadClient = new K(i, e), this.workerManager = new ie(e, this.fileManager, t, r), this.wireVadCallbacks();
|
|
1276
1301
|
}
|
|
1277
1302
|
initialize(e, t) {
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
this.workerManager.setUploadConfig(e.upload_url, t.uploadHeaders), this.initialized = !0;
|
|
1281
|
-
} catch (e) {
|
|
1282
|
-
throw this.callbackRegistry.dispatch("onError", {
|
|
1283
|
-
type: "vad_error",
|
|
1284
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1285
|
-
error: {
|
|
1286
|
-
code: "recorder_init_failed",
|
|
1287
|
-
message: e instanceof Error ? e.message : "Failed to initialize chunked recorder"
|
|
1288
|
-
}
|
|
1289
|
-
}), e;
|
|
1290
|
-
}
|
|
1303
|
+
if (!e.upload_url) throw Error("Upload URL is required for chunked recording");
|
|
1304
|
+
this.workerManager.setUploadConfig(e.upload_url, t.uploadHeaders), this.initialized = !0;
|
|
1291
1305
|
}
|
|
1292
1306
|
async start(e) {
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
this.vadClient.start(), this._isPaused = !1;
|
|
1296
|
-
} catch (e) {
|
|
1297
|
-
throw this.callbackRegistry.dispatch("onError", {
|
|
1298
|
-
type: "vad_error",
|
|
1299
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1300
|
-
error: {
|
|
1301
|
-
code: "vad_start_failed",
|
|
1302
|
-
message: e instanceof Error ? e.message : "Failed to start VAD"
|
|
1303
|
-
}
|
|
1304
|
-
}), e;
|
|
1305
|
-
}
|
|
1307
|
+
if (await this.vadClient.init(e), this.vadClient.isVadLoading() && (await this.vadClient.init(e), this.vadClient.isVadLoading())) throw Error("VAD instance failed to initialize after retry");
|
|
1308
|
+
this.vadClient.start(), this._isPaused = !1;
|
|
1306
1309
|
}
|
|
1307
1310
|
pause() {
|
|
1308
1311
|
this._isPaused ||= (this.vadClient.pause(), !0);
|
|
@@ -1315,12 +1318,12 @@ var re = class {
|
|
|
1315
1318
|
}
|
|
1316
1319
|
async stop() {
|
|
1317
1320
|
try {
|
|
1318
|
-
return this._isPaused = !1, this.vadClient.destroy(), this.flushRemainingAudio(), await this.workerManager.waitForAllUploads(), this.
|
|
1321
|
+
return this._isPaused = !1, this.vadClient.destroy(), this.flushRemainingAudio(), await this.workerManager.waitForAllUploads(), this.fileManager.markPendingAsFailed(), {
|
|
1319
1322
|
failedUploads: this.fileManager.getFailedUploads(),
|
|
1320
1323
|
totalFiles: this.fileManager.getChunkCount()
|
|
1321
1324
|
};
|
|
1322
1325
|
} catch (e) {
|
|
1323
|
-
return console.error("[ScribeSDK] Error stopping chunked recorder:", e), {
|
|
1326
|
+
return console.error("[ScribeSDK] Error stopping chunked recorder:", e), this.fileManager.markPendingAsFailed(), {
|
|
1324
1327
|
failedUploads: this.fileManager.getFailedUploads(),
|
|
1325
1328
|
totalFiles: this.fileManager.getChunkCount()
|
|
1326
1329
|
};
|
|
@@ -1380,13 +1383,13 @@ var re = class {
|
|
|
1380
1383
|
flushRemainingAudio() {
|
|
1381
1384
|
this.bufferManager.getCurrentSampleLength() > 0 && this.handleClipPoint();
|
|
1382
1385
|
}
|
|
1383
|
-
},
|
|
1386
|
+
}, Z = class {
|
|
1384
1387
|
constructor(e, t) {
|
|
1385
|
-
this.mediaRecorder = null, this.audioChunks = [], this.micStream = null, this._isPaused = !1, this.uploadUrl = "", this.
|
|
1388
|
+
this.mediaRecorder = null, this.audioChunks = [], this.micStream = null, this._isPaused = !1, this.uploadUrl = "", this.failedUploadData = null, this.callbackRegistry = e, this.transport = t;
|
|
1386
1389
|
}
|
|
1387
1390
|
initialize(e, t) {
|
|
1388
1391
|
if (!e.upload_url) throw Error("Upload URL is required for single recording");
|
|
1389
|
-
this.uploadUrl = e.upload_url, this.
|
|
1392
|
+
this.uploadUrl = e.upload_url, this.failedUploadData = null;
|
|
1390
1393
|
}
|
|
1391
1394
|
async start(e) {
|
|
1392
1395
|
try {
|
|
@@ -1426,7 +1429,6 @@ var re = class {
|
|
|
1426
1429
|
return await this.transport.request({
|
|
1427
1430
|
method: "POST",
|
|
1428
1431
|
url: n,
|
|
1429
|
-
headers: this.uploadHeaders,
|
|
1430
1432
|
isUpload: !0,
|
|
1431
1433
|
uploadBlob: e
|
|
1432
1434
|
}), this.callbackRegistry.dispatch("onUploadEvent", {
|
|
@@ -1440,13 +1442,16 @@ var re = class {
|
|
|
1440
1442
|
failedUploads: [],
|
|
1441
1443
|
totalFiles: 1
|
|
1442
1444
|
};
|
|
1443
|
-
} catch (
|
|
1444
|
-
return this.
|
|
1445
|
+
} catch (n) {
|
|
1446
|
+
return this.failedUploadData = {
|
|
1447
|
+
fileName: t,
|
|
1448
|
+
blob: e
|
|
1449
|
+
}, this.callbackRegistry.dispatch("onUploadEvent", {
|
|
1445
1450
|
type: "failed",
|
|
1446
1451
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1447
1452
|
data: {
|
|
1448
1453
|
fileName: t,
|
|
1449
|
-
error:
|
|
1454
|
+
error: n?.message ?? "Upload failed"
|
|
1450
1455
|
}
|
|
1451
1456
|
}), {
|
|
1452
1457
|
failedUploads: [t],
|
|
@@ -1467,7 +1472,10 @@ var re = class {
|
|
|
1467
1472
|
try {
|
|
1468
1473
|
this.mediaRecorder && this.mediaRecorder.state !== "inactive" && this.mediaRecorder.stop();
|
|
1469
1474
|
} catch {}
|
|
1470
|
-
this.releaseMicStream(), this.mediaRecorder = null, this.audioChunks = [];
|
|
1475
|
+
this.releaseMicStream(), this.mediaRecorder = null, this.audioChunks = [], this.failedUploadData = null;
|
|
1476
|
+
}
|
|
1477
|
+
getFailedBlobData() {
|
|
1478
|
+
return this.failedUploadData ? [this.failedUploadData] : [];
|
|
1471
1479
|
}
|
|
1472
1480
|
stopMediaRecorder() {
|
|
1473
1481
|
return new Promise((e, t) => {
|
|
@@ -1547,7 +1555,7 @@ var re = class {
|
|
|
1547
1555
|
} catch (e) {
|
|
1548
1556
|
throw this.cleanupRecordingState(), this.dispatchStartError("validation_error", "recorder_init_failed", e), e;
|
|
1549
1557
|
}
|
|
1550
|
-
this.recorder instanceof
|
|
1558
|
+
this.recorder instanceof X && this.applyDiscoveryOverrides(this.recorder);
|
|
1551
1559
|
try {
|
|
1552
1560
|
await this.recorder.start(t.deviceId);
|
|
1553
1561
|
} catch (e) {
|
|
@@ -1579,7 +1587,7 @@ var re = class {
|
|
|
1579
1587
|
} catch (e) {
|
|
1580
1588
|
throw this.cleanupRecordingState(), this.dispatchStartError("validation_error", "recorder_init_failed", e), e;
|
|
1581
1589
|
}
|
|
1582
|
-
this.recorder instanceof
|
|
1590
|
+
this.recorder instanceof X && this.applyDiscoveryOverrides(this.recorder);
|
|
1583
1591
|
try {
|
|
1584
1592
|
await this.recorder.start(n?.deviceId);
|
|
1585
1593
|
} catch (e) {
|
|
@@ -1641,7 +1649,14 @@ var re = class {
|
|
|
1641
1649
|
failedUploads: e.failedUploads.length
|
|
1642
1650
|
}), e;
|
|
1643
1651
|
} catch (e) {
|
|
1644
|
-
return console.error("[ScribeSDK] Error stopping recording:", e), {
|
|
1652
|
+
return console.error("[ScribeSDK] Error stopping recording:", e), this.callbackRegistry.dispatch("onError", {
|
|
1653
|
+
type: "transport_error",
|
|
1654
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1655
|
+
error: {
|
|
1656
|
+
code: "stop_failed",
|
|
1657
|
+
message: e instanceof Error ? e.message : "Failed to stop recording"
|
|
1658
|
+
}
|
|
1659
|
+
}), {
|
|
1645
1660
|
failedUploads: [],
|
|
1646
1661
|
totalFiles: 0
|
|
1647
1662
|
};
|
|
@@ -1649,9 +1664,9 @@ var re = class {
|
|
|
1649
1664
|
this.cleanupRecordingState();
|
|
1650
1665
|
}
|
|
1651
1666
|
}
|
|
1652
|
-
|
|
1667
|
+
forceStop() {
|
|
1653
1668
|
if (!(!this.recorder || !this._isRecording)) try {
|
|
1654
|
-
|
|
1669
|
+
this.recorder.reset();
|
|
1655
1670
|
} catch {} finally {
|
|
1656
1671
|
this.callbackRegistry.dispatch("onRecordingStateChange", {
|
|
1657
1672
|
type: "ended",
|
|
@@ -1664,7 +1679,7 @@ var re = class {
|
|
|
1664
1679
|
}
|
|
1665
1680
|
}
|
|
1666
1681
|
updateAuthToken(e) {
|
|
1667
|
-
this.recorder && this.recorder instanceof
|
|
1682
|
+
this.recorder && this.recorder instanceof X && this.recorder.updateAuthToken(e), this.transport.setAuthToken(e);
|
|
1668
1683
|
}
|
|
1669
1684
|
reset() {
|
|
1670
1685
|
this.recorder && this.recorder.reset(), this.retryContext = null, this.cleanupRecordingState();
|
|
@@ -1722,7 +1737,7 @@ var re = class {
|
|
|
1722
1737
|
};
|
|
1723
1738
|
}
|
|
1724
1739
|
createRecorder(e) {
|
|
1725
|
-
return e === "single" ? new
|
|
1740
|
+
return e === "single" ? new Z(this.callbackRegistry, this.transport) : new X(this.callbackRegistry, this.transport, void 0, this.config.workerConfig);
|
|
1726
1741
|
}
|
|
1727
1742
|
buildUploadHeaders(e) {
|
|
1728
1743
|
let t = {};
|
|
@@ -1745,18 +1760,21 @@ var re = class {
|
|
|
1745
1760
|
});
|
|
1746
1761
|
}
|
|
1747
1762
|
preserveRetryContext() {
|
|
1748
|
-
if (!
|
|
1749
|
-
|
|
1750
|
-
|
|
1763
|
+
if (!this.activeSession?.upload_url) {
|
|
1764
|
+
this.retryContext = null;
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
let e = [];
|
|
1768
|
+
if (this.recorder instanceof X ? e = this.recorder.getFileManager().getFailedChunksWithBlobs().map((e) => ({
|
|
1769
|
+
fileName: e.fileName,
|
|
1770
|
+
blob: e.fileBlob
|
|
1771
|
+
})) : this.recorder instanceof Z && (e = this.recorder.getFailedBlobData()), e.length === 0) {
|
|
1751
1772
|
this.retryContext = null;
|
|
1752
1773
|
return;
|
|
1753
1774
|
}
|
|
1754
1775
|
this.retryContext = {
|
|
1755
1776
|
uploadUrl: this.activeSession.upload_url,
|
|
1756
|
-
failedChunks: e
|
|
1757
|
-
fileName: e.fileName,
|
|
1758
|
-
blob: e.fileBlob
|
|
1759
|
-
}))
|
|
1777
|
+
failedChunks: e
|
|
1760
1778
|
}, this.config.debug && console.log(`[ScribeSDK] Preserved ${e.length} failed uploads for retry`);
|
|
1761
1779
|
}
|
|
1762
1780
|
cleanupRecordingState() {
|
|
@@ -1769,7 +1787,7 @@ var re = class {
|
|
|
1769
1787
|
autoDiscovery: !0,
|
|
1770
1788
|
mode: l.DIRECT,
|
|
1771
1789
|
...e
|
|
1772
|
-
}, this.callbackRegistry = new w(), this.validator = new
|
|
1790
|
+
}, this.callbackRegistry = new w(), this.validator = new P(), this.transport = this.createTransport(), this.discoveryManager = new V(this.transport, this.validator, this.config.debug), this.sessionManager = new H(this.transport, this.validator, this.config.debug), this.recordingManager = new Q(this.callbackRegistry, this.sessionManager, this.discoveryManager, this.transport, {
|
|
1773
1791
|
debug: this.config.debug,
|
|
1774
1792
|
workerConfig: this.resolveWorkerConfig()
|
|
1775
1793
|
});
|
|
@@ -1788,7 +1806,15 @@ var re = class {
|
|
|
1788
1806
|
if (!e.success) return e;
|
|
1789
1807
|
}
|
|
1790
1808
|
let t = this.getEffectiveBaseUrl();
|
|
1791
|
-
return this.wrapResult(() =>
|
|
1809
|
+
return this.wrapResult(() => {
|
|
1810
|
+
try {
|
|
1811
|
+
let t = this.discoveryManager.getResolvedConfig();
|
|
1812
|
+
this.validator.validateAgainstDiscovery(e, t);
|
|
1813
|
+
} catch (e) {
|
|
1814
|
+
if (e instanceof m) throw e;
|
|
1815
|
+
}
|
|
1816
|
+
return this.recordingManager.start(t, e, this.config.accessToken);
|
|
1817
|
+
});
|
|
1792
1818
|
}
|
|
1793
1819
|
async startRecordingWithSession(e, t) {
|
|
1794
1820
|
if (!this.isInitialized) {
|
|
@@ -1840,7 +1866,7 @@ var re = class {
|
|
|
1840
1866
|
}
|
|
1841
1867
|
async cancelSession(e) {
|
|
1842
1868
|
let t = e ?? this.recordingManager.getActiveSession()?.session_id ?? this.sessionManager.getCurrentSession()?.session_id;
|
|
1843
|
-
return this.recordingManager.isRecording() &&
|
|
1869
|
+
return this.recordingManager.isRecording() && this.recordingManager.forceStop(), this.recordingManager.reset(), this.sessionManager.clearCurrentSession(), this.updateSession({
|
|
1844
1870
|
user_status: "cancelled",
|
|
1845
1871
|
processing_status: "cancelled"
|
|
1846
1872
|
}, t);
|
|
@@ -1906,14 +1932,14 @@ var re = class {
|
|
|
1906
1932
|
}) : Promise.resolve(void 0);
|
|
1907
1933
|
if (this.config.mode === l.IPC) {
|
|
1908
1934
|
if (!this.config.ipcTransport) throw new m("ipcTransport (IpcBridge) is required when mode is \"ipc\"");
|
|
1909
|
-
return new
|
|
1935
|
+
return new z({
|
|
1910
1936
|
bridge: this.config.ipcTransport,
|
|
1911
1937
|
accessToken: this.config.accessToken,
|
|
1912
1938
|
debug: this.config.debug,
|
|
1913
1939
|
onUnauthorized: e
|
|
1914
1940
|
});
|
|
1915
1941
|
}
|
|
1916
|
-
return new
|
|
1942
|
+
return new R({
|
|
1917
1943
|
accessToken: this.config.accessToken,
|
|
1918
1944
|
debug: this.config.debug,
|
|
1919
1945
|
onUnauthorized: e
|
|
@@ -1952,4 +1978,4 @@ async function se(e) {
|
|
|
1952
1978
|
return URL.createObjectURL(i);
|
|
1953
1979
|
}
|
|
1954
1980
|
//#endregion
|
|
1955
|
-
export { g as AuthenticationError, w as CallbackRegistry, c as CommunicationProtocol, h as DiscoveryError,
|
|
1981
|
+
export { g as AuthenticationError, w as CallbackRegistry, c as CommunicationProtocol, h as DiscoveryError, V as DiscoveryManager, u as ErrorCode, _ as ForbiddenError, d as HttpStatus, R as HttpTransport, z as IpcTransport, b as RateLimitError, Q as RecordingManager, ae as ScribeClient, p as ScribeError, y as SessionExpiredError, H as SessionManager, v as SessionNotFoundError, a as SessionStatus, o as TemplateStatus, x as TransportError, l as TransportMode, C as UploadError, s as UploadType, m as ValidationError, P as Validator, S as WorkerError, se as createWorkerBlobUrl, oe as getWorkerUrl };
|
package/dist/worker.bundle.js
CHANGED
|
@@ -11,4 +11,4 @@ data bits: %d
|
|
|
11
11
|
total bits: %d (remainder: %d)
|
|
12
12
|
bitsperframe: %d
|
|
13
13
|
`,8*r.main_data_begin,n.ResvSize,r.resvDrain_post,r.resvDrain_pre,8*n.sideinfo_len,a-r.resvDrain_post-8*n.sideinfo_len,a,a%8,i),t.err.println(`This is a fatal error. It has several possible causes:`),t.err.println(`90%% LAME compiled with buggy version of gcc using advanced optimizations`),t.err.println(` 9%% Your system is overclocked`),t.err.println(` 1%% bug in LAME encoding library`),n.ResvSize=r.main_data_begin*8),v>1e9){var o;for(o=0;o<u.MAX_HEADER_BUF;++o)n.header[o].write_timing-=v;v=0}return 0},this.copy_buffer=function(e,n,r,o,s){var c=y+1;if(c<=0)return 0;if(o!=0&&c>o)return-1;if(t.arraycopy(_,0,n,r,c),y=-1,b=0,s!=0){var l=a(1);if(l[0]=e.nMusicCRC,g.updateMusicCRC(l,n,r,c),e.nMusicCRC=l[0],c>0&&(e.VBR_seek_table.nBytesWritten+=c),e.decode_on_the_fly){for(var u=i([2,1152]),d=c,f=-1,h;f!=0;)if(f=m.hip_decode1_unclipped(e.hip,n,r,d,u[0],u[1]),d=0,f==-1&&(f=0),f>0){if(e.findPeakSample){for(h=0;h<f;h++)u[0][h]>e.PeakSample?e.PeakSample=u[0][h]:-u[0][h]>e.PeakSample&&(e.PeakSample=-u[0][h]);if(e.channels_out>1)for(h=0;h<f;h++)u[1][h]>e.PeakSample?e.PeakSample=u[1][h]:-u[1][h]>e.PeakSample&&(e.PeakSample=-u[1][h])}if(e.findReplayGain&&p.AnalyzeSamples(e.rgdata,u[0],0,u[1],0,f,e.channels_out)==GainAnalysis.GAIN_ANALYSIS_ERROR)return-6}}}return c},this.init_bit_stream_w=function(t){_=r(e.LAME_MAXMP3BUFFER),t.h_ptr=t.w_ptr=0,t.header[t.h_ptr].write_timing=0,y=-1,b=0,v=0}}return Dt=d,Dt}var At,jt;function Mt(){if(jt)return At;jt=1;var e=g,t=e.System,n=e.VbrMode,r=e.ShortBlock,i=e.new_float,a=e.new_int_n,o=e.new_short_n,s=e.assert,c=ie,l=se,u=qe,d=Ze,f=st,p=yt,m=kt(),h=bt,_=A();function v(){var e=D,g=this;v.V9=410,v.V8=420,v.V7=430,v.V6=440,v.V5=450,v.V4=460,v.V3=470,v.V2=480,v.V1=490,v.V0=500,v.R3MIX=1e3,v.STANDARD=1001,v.EXTREME=1002,v.INSANE=1003,v.STANDARD_FAST=1004,v.EXTREME_FAST=1005,v.MEDIUM=1006,v.MEDIUM_FAST=1007,v.LAME_MAXMP3BUFFER=147456;var y,b,x,S,C,w=new c,T,E,O;this.enc=new _,this.setModules=function(e,t,n,r,i,a,o,s,c){y=e,b=t,x=n,S=r,C=i,T=a,E=s,O=c,this.enc.setModules(b,w,S,T)};function k(){this.mask_adjust=0,this.mask_adjust_short=0,this.bo_l_weight=i(_.SBMAX_l),this.bo_s_weight=i(_.SBMAX_s)}function A(){this.lowerlimit=0}function j(e,t){this.lowpass=t}var M=4294479419;function N(t){var r;return t.class_id=M,r=t.internal_flags=new u,t.mode=e.NOT_SET,t.original=1,t.in_samplerate=44100,t.num_channels=2,t.num_samples=-1,t.bWriteVbrTag=!0,t.quality=-1,t.short_blocks=null,r.subblock_gain=-1,t.lowpassfreq=0,t.highpassfreq=0,t.lowpasswidth=-1,t.highpasswidth=-1,t.VBR=n.vbr_off,t.VBR_q=4,t.ATHcurve=-1,t.VBR_mean_bitrate_kbps=128,t.VBR_min_bitrate_kbps=0,t.VBR_max_bitrate_kbps=0,t.VBR_hard_min=0,r.VBR_min_bitrate=1,r.VBR_max_bitrate=13,t.quant_comp=-1,t.quant_comp_short=-1,t.msfix=-1,r.resample_ratio=1,r.OldValue[0]=180,r.OldValue[1]=180,r.CurrentStep[0]=4,r.CurrentStep[1]=4,r.masking_lower=1,r.nsPsy.attackthre=-1,r.nsPsy.attackthre_s=-1,t.scale=-1,t.athaa_type=-1,t.ATHtype=-1,t.athaa_loudapprox=-1,t.athaa_sensitivity=0,t.useTemporal=null,t.interChRatio=-1,r.mf_samples_to_encode=_.ENCDELAY+_.POSTDELAY,t.encoder_padding=0,r.mf_size=_.ENCDELAY-_.MDCTDELAY,t.findReplayGain=!1,t.decode_on_the_fly=!1,r.decode_on_the_fly=!1,r.findReplayGain=!1,r.findPeakSample=!1,r.RadioGain=0,r.AudiophileGain=0,r.noclipGainChange=0,r.noclipScale=-1,t.preset=0,t.write_id3tag_automatic=!0,0}this.lame_init=function(){var e=new l;return N(e),e.lame_allocated_gfp=1,e};function P(e){return e>1?0:e<=0?1:Math.cos(Math.PI/2*e)}this.nearestBitrateFullIndex=function(e){var t=[8,16,24,32,40,48,56,64,80,96,112,128,160,192,224,256,320],n=0,r=0,i=0,a=0;a=t[16],i=16,r=t[16],n=16;for(var o=0;o<16;o++)if(Math.max(e,t[o+1])!=e){a=t[o+1],i=o+1,r=t[o],n=o;break}return a-e>e-r?n:i};function F(e,t){var n=44100;return t>=48e3?n=48e3:t>=44100?n=44100:t>=32e3?n=32e3:t>=24e3?n=24e3:t>=22050?n=22050:t>=16e3?n=16e3:t>=12e3?n=12e3:t>=11025?n=11025:t>=8e3&&(n=8e3),e==-1?n:(e<=15960&&(n=44100),e<=15250&&(n=32e3),e<=11220&&(n=24e3),e<=9970&&(n=22050),e<=7230&&(n=16e3),e<=5420&&(n=12e3),e<=4510&&(n=11025),e<=3970&&(n=8e3),t<n?t>44100?48e3:t>32e3?44100:t>24e3?32e3:t>22050?24e3:t>16e3?22050:t>12e3?16e3:t>11025?12e3:t>8e3?11025:8e3:n)}function I(e,t){switch(e){case 44100:return t.version=1,0;case 48e3:return t.version=1,1;case 32e3:return t.version=1,2;case 22050:return t.version=0,0;case 24e3:return t.version=0,1;case 16e3:return t.version=0,2;case 11025:return t.version=0,0;case 12e3:return t.version=0,1;case 8e3:return t.version=0,2;default:return t.version=0,-1}}function L(e,t,n){n<16e3&&(t=2);for(var r=h.bitrate_table[t][1],i=2;i<=14;i++)h.bitrate_table[t][i]>0&&Math.abs(h.bitrate_table[t][i]-e)<Math.abs(r-e)&&(r=h.bitrate_table[t][i]);return r}function R(e,t,n){n<16e3&&(t=2);for(var r=0;r<=14;r++)if(h.bitrate_table[t][r]>0&&h.bitrate_table[t][r]==e)return r;return-1}function z(e,t){e.lowerlimit=[new j(8,2e3),new j(16,3700),new j(24,3900),new j(32,5500),new j(40,7e3),new j(48,7500),new j(56,1e4),new j(64,11e3),new j(80,13500),new j(96,15100),new j(112,15600),new j(128,17e3),new j(160,17500),new j(192,18600),new j(224,19400),new j(256,19700),new j(320,20500)][g.nearestBitrateFullIndex(t)].lowpass}function B(e){var n=e.internal_flags,r=32,i=-1;if(n.lowpass1>0){for(var a=999,o=0;o<=31;o++){var s=o/31;s>=n.lowpass2&&(r=Math.min(r,o)),n.lowpass1<s&&s<n.lowpass2&&(a=Math.min(a,o))}a==999?n.lowpass1=(r-.75)/31:n.lowpass1=(a-.75)/31,n.lowpass2=r/31}if(n.highpass2>0&&n.highpass2<.75/31*.9&&(n.highpass1=0,n.highpass2=0,t.err.println(`Warning: highpass filter disabled. highpass frequency too small
|
|
14
|
-
`)),n.highpass2>0){for(var c=-1,o=0;o<=31;o++){var s=o/31;s<=n.highpass1&&(i=Math.max(i,o)),n.highpass1<s&&s<n.highpass2&&(c=Math.max(c,o))}n.highpass1=i/31,c==-1?n.highpass2=(i+.75)/31:n.highpass2=(c+.75)/31}for(var o=0;o<32;o++){var l,u,s=o/31;l=n.highpass2>n.highpass1?P((n.highpass2-s)/(n.highpass2-n.highpass1+1e-20)):1,u=n.lowpass2>n.lowpass1?P((s-n.lowpass1)/(n.lowpass2-n.lowpass1+1e-20)):1,n.amp_filter[o]=l*u}}function V(e){var t=e.internal_flags;switch(e.quality){default:case 9:t.psymodel=0,t.noise_shaping=0,t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.use_best_huffman=0,t.full_outer_loop=0;break;case 8:e.quality=7;case 7:t.psymodel=1,t.noise_shaping=0,t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.use_best_huffman=0,t.full_outer_loop=0;break;case 6:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=0,t.full_outer_loop=0;break;case 5:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=0,t.full_outer_loop=0;break;case 4:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 3:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=1,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 2:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.substep_shaping==0&&(t.substep_shaping=2),t.noise_shaping_amp=1,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 1:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.substep_shaping==0&&(t.substep_shaping=2),t.noise_shaping_amp=2,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 0:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.substep_shaping==0&&(t.substep_shaping=2),t.noise_shaping_amp=2,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break}}function ee(e){var t=e.internal_flags;e.frameNum=0,e.write_id3tag_automatic&&E.id3tag_write_v2(e),t.bitrate_stereoMode_Hist=a([16,5]),t.bitrate_blockType_Hist=a([16,6]),t.PeakSample=0,e.bWriteVbrTag&&T.InitVbrTag(e)}this.lame_init_params=function(t){var i=t.internal_flags;if(i.Class_ID=0,i.ATH??=new d,i.PSY??=new k,i.rgdata??=new f,i.channels_in=t.num_channels,i.channels_in==1&&(t.mode=e.MONO),i.channels_out=t.mode==e.MONO?1:2,i.mode_ext=_.MPG_MD_MS_LR,t.mode==e.MONO&&(t.force_ms=!1),t.VBR==n.vbr_off&&t.VBR_mean_bitrate_kbps!=128&&t.brate==0&&(t.brate=t.VBR_mean_bitrate_kbps),t.VBR==n.vbr_off||t.VBR==n.vbr_mtrh||t.VBR==n.vbr_mt||(t.free_format=!1),t.VBR==n.vbr_off&&t.brate==0&&m.EQ(t.compression_ratio,0)&&(t.compression_ratio=11.025),t.VBR==n.vbr_off&&t.compression_ratio>0&&(t.out_samplerate==0&&(t.out_samplerate=map2MP3Frequency(int(.97*t.in_samplerate))),t.brate=0|t.out_samplerate*16*i.channels_out/(1e3*t.compression_ratio),i.samplerate_index=I(t.out_samplerate,t),t.free_format||(t.brate=L(t.brate,t.version,t.out_samplerate))),t.out_samplerate!=0&&(t.out_samplerate<16e3?(t.VBR_mean_bitrate_kbps=Math.max(t.VBR_mean_bitrate_kbps,8),t.VBR_mean_bitrate_kbps=Math.min(t.VBR_mean_bitrate_kbps,64)):t.out_samplerate<32e3?(t.VBR_mean_bitrate_kbps=Math.max(t.VBR_mean_bitrate_kbps,8),t.VBR_mean_bitrate_kbps=Math.min(t.VBR_mean_bitrate_kbps,160)):(t.VBR_mean_bitrate_kbps=Math.max(t.VBR_mean_bitrate_kbps,32),t.VBR_mean_bitrate_kbps=Math.min(t.VBR_mean_bitrate_kbps,320))),t.lowpassfreq==0){var a=16e3;switch(t.VBR){case n.vbr_off:var o=new A;z(o,t.brate),a=o.lowerlimit;break;case n.vbr_abr:var o=new A;z(o,t.VBR_mean_bitrate_kbps),a=o.lowerlimit;break;case n.vbr_rh:var l=[19500,19e3,18600,18e3,17500,16e3,15600,14900,12500,1e4,3950];if(0<=t.VBR_q&&t.VBR_q<=9){var u=l[t.VBR_q],g=l[t.VBR_q+1],v=t.VBR_q_frac;a=linear_int(u,g,v)}else a=19500;break;default:var l=[19500,19e3,18500,18e3,17500,16500,15500,14500,12500,9500,3950];if(0<=t.VBR_q&&t.VBR_q<=9){var u=l[t.VBR_q],g=l[t.VBR_q+1],v=t.VBR_q_frac;a=linear_int(u,g,v)}else a=19500}t.mode==e.MONO&&(t.VBR==n.vbr_off||t.VBR==n.vbr_abr)&&(a*=1.5),t.lowpassfreq=a|0}if(t.out_samplerate==0&&(2*t.lowpassfreq>t.in_samplerate&&(t.lowpassfreq=t.in_samplerate/2),t.out_samplerate=F(t.lowpassfreq|0,t.in_samplerate)),t.lowpassfreq=Math.min(20500,t.lowpassfreq),t.lowpassfreq=Math.min(t.out_samplerate/2,t.lowpassfreq),t.VBR==n.vbr_off&&(t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.brate)),t.VBR==n.vbr_abr&&(t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.VBR_mean_bitrate_kbps)),t.bWriteVbrTag||(t.findReplayGain=!1,t.decode_on_the_fly=!1,i.findPeakSample=!1),i.findReplayGain=t.findReplayGain,i.decode_on_the_fly=t.decode_on_the_fly,i.decode_on_the_fly&&(i.findPeakSample=!0),i.findReplayGain&&y.InitGainAnalysis(i.rgdata,t.out_samplerate)==GainAnalysis.INIT_GAIN_ANALYSIS_ERROR)return t.internal_flags=null,-6;switch(i.decode_on_the_fly&&!t.decode_only&&(i.hip!=null&&O.hip_decode_exit(i.hip),i.hip=O.hip_decode_init()),i.mode_gr=t.out_samplerate<=24e3?1:2,t.framesize=576*i.mode_gr,t.encoder_delay=_.ENCDELAY,i.resample_ratio=t.in_samplerate/t.out_samplerate,t.VBR){case n.vbr_mt:case n.vbr_rh:case n.vbr_mtrh:t.compression_ratio=[5.7,6.5,7.3,8.2,10,11.9,13,14,15,16.5][t.VBR_q];break;case n.vbr_abr:t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.VBR_mean_bitrate_kbps);break;default:t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.brate);break}if(t.mode==e.NOT_SET&&(t.mode=e.JOINT_STEREO),t.highpassfreq>0?(i.highpass1=2*t.highpassfreq,t.highpasswidth>=0?i.highpass2=2*(t.highpassfreq+t.highpasswidth):i.highpass2=2*t.highpassfreq,i.highpass1/=t.out_samplerate,i.highpass2/=t.out_samplerate):(i.highpass1=0,i.highpass2=0),t.lowpassfreq>0?(i.lowpass2=2*t.lowpassfreq,t.lowpasswidth>=0?(i.lowpass1=2*(t.lowpassfreq-t.lowpasswidth),i.lowpass1<0&&(i.lowpass1=0)):i.lowpass1=2*t.lowpassfreq,i.lowpass1/=t.out_samplerate,i.lowpass2/=t.out_samplerate):(i.lowpass1=0,i.lowpass2=0),B(t),i.samplerate_index=I(t.out_samplerate,t),i.samplerate_index<0)return t.internal_flags=null,-1;if(t.VBR==n.vbr_off){if(t.free_format)i.bitrate_index=0;else if(t.brate=L(t.brate,t.version,t.out_samplerate),i.bitrate_index=R(t.brate,t.version,t.out_samplerate),i.bitrate_index<=0)return t.internal_flags=null,-1}else i.bitrate_index=1;t.analysis&&(t.bWriteVbrTag=!1),i.pinfo!=null&&(t.bWriteVbrTag=!1),b.init_bit_stream_w(i);for(var T=i.samplerate_index+3*t.version+6*(t.out_samplerate<16e3),E=0;E<_.SBMAX_l+1;E++)i.scalefac_band.l[E]=S.sfBandIndex[T].l[E];for(var E=0;E<_.PSFB21+1;E++){var D=(i.scalefac_band.l[22]-i.scalefac_band.l[21])/_.PSFB21,j=i.scalefac_band.l[21]+E*D;i.scalefac_band.psfb21[E]=j}i.scalefac_band.psfb21[_.PSFB21]=576;for(var E=0;E<_.SBMAX_s+1;E++)i.scalefac_band.s[E]=S.sfBandIndex[T].s[E];for(var E=0;E<_.PSFB12+1;E++){var D=(i.scalefac_band.s[13]-i.scalefac_band.s[12])/_.PSFB12,j=i.scalefac_band.s[12]+E*D;i.scalefac_band.psfb12[E]=j}i.scalefac_band.psfb12[_.PSFB12]=192,t.version==1?i.sideinfo_len=i.channels_out==1?21:36:i.sideinfo_len=i.channels_out==1?13:21,t.error_protection&&(i.sideinfo_len+=2),ee(t),i.Class_ID=M;var N;for(N=0;N<19;N++)i.nsPsy.pefirbuf[N]=700*i.mode_gr*i.channels_out;switch(t.ATHtype==-1&&(t.ATHtype=4),s(t.VBR_q<=9),s(t.VBR_q>=0),t.VBR){case n.vbr_mt:t.VBR=n.vbr_mtrh;case n.vbr_mtrh:t.useTemporal??=!1,x.apply_preset(t,500-t.VBR_q*10,0),t.quality<0&&(t.quality=LAME_DEFAULT_QUALITY),t.quality<5&&(t.quality=0),t.quality>5&&(t.quality=5),i.PSY.mask_adjust=t.maskingadjust,i.PSY.mask_adjust_short=t.maskingadjust_short,t.experimentalY?i.sfb21_extra=!1:i.sfb21_extra=t.out_samplerate>44e3,i.iteration_loop=new VBRNewIterationLoop(C);break;case n.vbr_rh:x.apply_preset(t,500-t.VBR_q*10,0),i.PSY.mask_adjust=t.maskingadjust,i.PSY.mask_adjust_short=t.maskingadjust_short,t.experimentalY?i.sfb21_extra=!1:i.sfb21_extra=t.out_samplerate>44e3,t.quality>6&&(t.quality=6),t.quality<0&&(t.quality=LAME_DEFAULT_QUALITY),i.iteration_loop=new VBROldIterationLoop(C);break;default:var P;i.sfb21_extra=!1,t.quality<0&&(t.quality=LAME_DEFAULT_QUALITY),P=t.VBR,P==n.vbr_off&&(t.VBR_mean_bitrate_kbps=t.brate),x.apply_preset(t,t.VBR_mean_bitrate_kbps,0),t.VBR=P,i.PSY.mask_adjust=t.maskingadjust,i.PSY.mask_adjust_short=t.maskingadjust_short,P==n.vbr_off?i.iteration_loop=new p(C):i.iteration_loop=new ABRIterationLoop(C);break}if(s(t.scale>=0),t.VBR!=n.vbr_off){if(i.VBR_min_bitrate=1,i.VBR_max_bitrate=14,t.out_samplerate<16e3&&(i.VBR_max_bitrate=8),t.VBR_min_bitrate_kbps!=0&&(t.VBR_min_bitrate_kbps=L(t.VBR_min_bitrate_kbps,t.version,t.out_samplerate),i.VBR_min_bitrate=R(t.VBR_min_bitrate_kbps,t.version,t.out_samplerate),i.VBR_min_bitrate<0)||t.VBR_max_bitrate_kbps!=0&&(t.VBR_max_bitrate_kbps=L(t.VBR_max_bitrate_kbps,t.version,t.out_samplerate),i.VBR_max_bitrate=R(t.VBR_max_bitrate_kbps,t.version,t.out_samplerate),i.VBR_max_bitrate<0))return-1;t.VBR_min_bitrate_kbps=h.bitrate_table[t.version][i.VBR_min_bitrate],t.VBR_max_bitrate_kbps=h.bitrate_table[t.version][i.VBR_max_bitrate],t.VBR_mean_bitrate_kbps=Math.min(h.bitrate_table[t.version][i.VBR_max_bitrate],t.VBR_mean_bitrate_kbps),t.VBR_mean_bitrate_kbps=Math.max(h.bitrate_table[t.version][i.VBR_min_bitrate],t.VBR_mean_bitrate_kbps)}return t.tune&&(i.PSY.mask_adjust+=t.tune_value_a,i.PSY.mask_adjust_short+=t.tune_value_a),V(t),s(t.scale>=0),t.athaa_type<0?i.ATH.useAdjust=3:i.ATH.useAdjust=t.athaa_type,i.ATH.aaSensitivityP=10**(t.athaa_sensitivity/-10),t.short_blocks??=r.short_block_allowed,t.short_blocks==r.short_block_allowed&&(t.mode==e.JOINT_STEREO||t.mode==e.STEREO)&&(t.short_blocks=r.short_block_coupled),t.quant_comp<0&&(t.quant_comp=1),t.quant_comp_short<0&&(t.quant_comp_short=0),t.msfix<0&&(t.msfix=0),t.exp_nspsytune|=1,t.internal_flags.nsPsy.attackthre<0&&(t.internal_flags.nsPsy.attackthre=c.NSATTACKTHRE),t.internal_flags.nsPsy.attackthre_s<0&&(t.internal_flags.nsPsy.attackthre_s=c.NSATTACKTHRE_S),s(t.scale>=0),t.scale<0&&(t.scale=1),t.ATHtype<0&&(t.ATHtype=4),t.ATHcurve<0&&(t.ATHcurve=4),t.athaa_loudapprox<0&&(t.athaa_loudapprox=2),t.interChRatio<0&&(t.interChRatio=0),t.useTemporal??=!0,i.slot_lag=i.frac_SpF=0,t.VBR==n.vbr_off&&(i.slot_lag=i.frac_SpF=(t.version+1)*72e3*t.brate%t.out_samplerate|0),S.iteration_init(t),w.psymodel_init(t),s(t.scale>=0),0};function H(e,t){(e.in_buffer_0==null||e.in_buffer_nsamples<t)&&(e.in_buffer_0=i(t),e.in_buffer_1=i(t),e.in_buffer_nsamples=t)}this.lame_encode_flush=function(e,t,n,r){var i=e.internal_flags,a=o([2,1152]),s=0,c,l,u,d,f=i.mf_samples_to_encode-_.POSTDELAY,p=U(e);if(i.mf_samples_to_encode<1)return 0;for(c=0,e.in_samplerate!=e.out_samplerate&&(f+=16*e.out_samplerate/e.in_samplerate),u=e.framesize-f%e.framesize,u<576&&(u+=e.framesize),e.encoder_padding=u,d=(f+u)/e.framesize;d>0&&s>=0;){var m=p-i.mf_size,h=e.frameNum;m*=e.in_samplerate,m/=e.out_samplerate,m>1152&&(m=1152),m<1&&(m=1),l=r-c,r==0&&(l=0),s=this.lame_encode_buffer(e,a[0],a[1],m,t,n,l),n+=s,c+=s,d-=h==e.frameNum?0:1}if(i.mf_samples_to_encode=0,s<0||(l=r-c,r==0&&(l=0),b.flush_bitstream(e),s=b.copy_buffer(i,t,n,l,1),s<0))return s;if(n+=s,c+=s,l=r-c,r==0&&(l=0),e.write_id3tag_automatic){if(E.id3tag_write_v1(e),s=b.copy_buffer(i,t,n,l,0),s<0)return s;c+=s}return c},this.lame_encode_buffer=function(e,t,n,r,i,a,o){var s=e.internal_flags,c=[null,null];if(s.Class_ID!=M)return-3;if(r==0)return 0;H(s,r),c[0]=s.in_buffer_0,c[1]=s.in_buffer_1;for(var l=0;l<r;l++)c[0][l]=t[l],s.channels_in>1&&(c[1][l]=n[l]);return te(e,c[0],c[1],r,i,a,o)};function U(e){var t=_.BLKSIZE+e.framesize-_.FFTOFFSET;return t=Math.max(t,512+e.framesize-32),t}function te(e,t,n,r,i,a,o){var c=e.internal_flags,l=0,d,f,p,h,g,v=[null,null],x=[null,null];if(c.Class_ID!=M)return-3;if(r==0)return 0;if(g=b.copy_buffer(c,i,a,o,0),g<0)return g;if(a+=g,l+=g,x[0]=t,x[1]=n,m.NEQ(e.scale,0)&&m.NEQ(e.scale,1))for(f=0;f<r;++f)x[0][f]*=e.scale,c.channels_out==2&&(x[1][f]*=e.scale);if(m.NEQ(e.scale_left,0)&&m.NEQ(e.scale_left,1))for(f=0;f<r;++f)x[0][f]*=e.scale_left;if(m.NEQ(e.scale_right,0)&&m.NEQ(e.scale_right,1))for(f=0;f<r;++f)x[1][f]*=e.scale_right;if(e.num_channels==2&&c.channels_out==1)for(f=0;f<r;++f)x[0][f]=.5*(x[0][f]+x[1][f]),x[1][f]=0;h=U(e),v[0]=c.mfbuf[0],v[1]=c.mfbuf[1];for(var S=0;r>0;){var C=[null,null],w=0,T=0;C[0]=x[0],C[1]=x[1];var E=new ne;if(oe(e,v,C,S,r,E),w=E.n_in,T=E.n_out,c.findReplayGain&&!c.decode_on_the_fly&&y.AnalyzeSamples(c.rgdata,v[0],c.mf_size,v[1],c.mf_size,T,c.channels_out)==GainAnalysis.GAIN_ANALYSIS_ERROR)return-6;if(r-=w,S+=w,c.channels_out,c.mf_size+=T,s(c.mf_size<=u.MFSIZE),c.mf_samples_to_encode<1&&(c.mf_samples_to_encode=_.ENCDELAY+_.POSTDELAY),c.mf_samples_to_encode+=T,c.mf_size>=h){var D=o-l;if(o==0&&(D=0),d=W(e,v[0],v[1],i,a,D),d<0)return d;for(a+=d,l+=d,c.mf_size-=e.framesize,c.mf_samples_to_encode-=e.framesize,p=0;p<c.channels_out;p++)for(f=0;f<c.mf_size;f++)v[p][f]=v[p][f+e.framesize]}}return l}function W(e,t,n,r,i,a){var o=g.enc.lame_encode_mp3_frame(e,t,n,r,i,a);return e.frameNum++,o}function ne(){this.n_in=0,this.n_out=0}function G(){this.num_used=0}function re(e,t){return t==0?e:re(t,e%t)}function ie(e,t,n){var r=Math.PI*t;e/=n,e<0&&(e=0),e>1&&(e=1);var i=e-.5,a=.42-.5*Math.cos(2*e*Math.PI)+.08*Math.cos(4*e*Math.PI);return Math.abs(i)<1e-9?r/Math.PI:a*Math.sin(n*r*i)/(Math.PI*n*i)}function ae(e,t,n,r,a,o,c,l,d){var f=e.internal_flags,p,m=0,h,g=e.out_samplerate/re(e.out_samplerate,e.in_samplerate);g>u.BPC&&(g=u.BPC);var _=+(Math.abs(f.resample_ratio-Math.floor(.5+f.resample_ratio))<1e-4),v=1/f.resample_ratio;v>1&&(v=1);var y=31;y%2==0&&--y,y+=_;var b=y+1;if(f.fill_buffer_resample_init==0){for(f.inbuf_old[0]=i(b),f.inbuf_old[1]=i(b),p=0;p<=2*g;++p)f.blackfilt[p]=i(b);for(f.itime[0]=0,f.itime[1]=0,m=0;m<=2*g;m++){var x=0,S=(m-g)/(2*g);for(p=0;p<=y;p++)x+=f.blackfilt[m][p]=ie(p-S,v,y);for(p=0;p<=y;p++)f.blackfilt[m][p]/=x}f.fill_buffer_resample_init=1}var C=f.inbuf_old[d];for(h=0;h<r;h++){var w,T;if(w=h*f.resample_ratio,m=0|Math.floor(w-f.itime[d]),y+m-y/2>=c)break;var S=w-f.itime[d]-(m+y%2*.5);T=0|Math.floor(S*2*g+g+.5);var E=0;for(p=0;p<=y;++p){var D=0|p+m-y/2,O=D<0?C[b+D]:a[o+D];E+=O*f.blackfilt[T][p]}t[n+h]=E}if(l.num_used=Math.min(c,y+m-y/2),f.itime[d]+=l.num_used-h*f.resample_ratio,l.num_used>=b)for(p=0;p<b;p++)C[p]=a[o+l.num_used+p-b];else{var k=b-l.num_used;for(p=0;p<k;++p)C[p]=C[p+l.num_used];for(m=0;p<b;++p,++m)C[p]=a[o+m];s(m==l.num_used)}return h}function oe(e,t,n,r,i,a){var o=e.internal_flags;if(o.resample_ratio<.9999||o.resample_ratio>1.0001)for(var s=0;s<o.channels_out;s++){var c=new G;a.n_out=ae(e,t[s],o.mf_size,e.framesize,n[s],r,i,c,s),a.n_in=c.num_used}else{a.n_out=Math.min(e.framesize,i),a.n_in=a.n_out;for(var l=0;l<a.n_out;++l)t[0][o.mf_size+l]=n[0][r+l],o.channels_out==2&&(t[1][o.mf_size+l]=n[1][r+l])}}}return At=v,At}var Nt=g.VbrMode;function Pt(){var e=Mt();function t(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){this.vbr_q=e,this.quant_comp=t,this.quant_comp_s=n,this.expY=r,this.st_lrm=i,this.st_s=a,this.masking_adj=o,this.masking_adj_short=s,this.ath_lower=c,this.ath_curve=l,this.ath_sensitivity=u,this.interch=d,this.safejoint=f,this.sfb21mod=p,this.msfix=m}function n(e,t,n,r,i,a,o,s,c,l,u,d,f,p){this.quant_comp=t,this.quant_comp_s=n,this.safejoint=r,this.nsmsfix=i,this.st_lrm=a,this.st_s=o,this.nsbass=s,this.scale=c,this.masking_adj=l,this.ath_lower=u,this.ath_curve=d,this.interch=f,this.sfscale=p}var r;this.setModules=function(e){r=e};var i=[new t(0,9,9,0,5.2,125,-4.2,-6.3,4.8,1,0,0,2,21,.97),new t(1,9,9,0,5.3,125,-3.6,-5.6,4.5,1.5,0,0,2,21,1.35),new t(2,9,9,0,5.6,125,-2.2,-3.5,2.8,2,0,0,2,21,1.49),new t(3,9,9,1,5.8,130,-1.8,-2.8,2.6,3,-4,0,2,20,1.64),new t(4,9,9,1,6,135,-.7,-1.1,1.1,3.5,-8,0,2,0,1.79),new t(5,9,9,1,6.4,140,.5,.4,-7.5,4,-12,2e-4,0,0,1.95),new t(6,9,9,1,6.6,145,.67,.65,-14.7,6.5,-19,4e-4,0,0,2.3),new t(7,9,9,1,6.6,145,.8,.75,-19.7,8,-22,6e-4,0,0,2.7),new t(8,9,9,1,6.6,145,1.2,1.15,-27.5,10,-23,7e-4,0,0,0),new t(9,9,9,1,6.6,145,1.6,1.6,-36,11,-25,8e-4,0,0,0),new t(10,9,9,1,6.6,145,2,2,-36,12,-25,8e-4,0,0,0)],a=[new t(0,9,9,0,4.2,25,-7,-4,7.5,1,0,0,2,26,.97),new t(1,9,9,0,4.2,25,-5.6,-3.6,4.5,1.5,0,0,2,21,1.35),new t(2,9,9,0,4.2,25,-4.4,-1.8,2,2,0,0,2,18,1.49),new t(3,9,9,1,4.2,25,-3.4,-1.25,1.1,3,-4,0,2,15,1.64),new t(4,9,9,1,4.2,25,-2.2,.1,0,3.5,-8,0,2,0,1.79),new t(5,9,9,1,4.2,25,-1,1.65,-7.7,4,-12,2e-4,0,0,1.95),new t(6,9,9,1,4.2,25,-0,2.47,-7.7,6.5,-19,4e-4,0,0,2),new t(7,9,9,1,4.2,25,.5,2,-14.5,8,-22,6e-4,0,0,2),new t(8,9,9,1,4.2,25,1,2.4,-22,10,-23,7e-4,0,0,2),new t(9,9,9,1,4.2,25,1.5,2.95,-30,11,-25,8e-4,0,0,2),new t(10,9,9,1,4.2,25,2,2.95,-36,12,-30,8e-4,0,0,2)];function o(e,t,n){var r=e.VBR==Nt.vbr_rh?i:a,o=e.VBR_q_frac,s=r[t],c=r[t+1],u=s;s.st_lrm+=o*(c.st_lrm-s.st_lrm),s.st_s+=o*(c.st_s-s.st_s),s.masking_adj+=o*(c.masking_adj-s.masking_adj),s.masking_adj_short+=o*(c.masking_adj_short-s.masking_adj_short),s.ath_lower+=o*(c.ath_lower-s.ath_lower),s.ath_curve+=o*(c.ath_curve-s.ath_curve),s.ath_sensitivity+=o*(c.ath_sensitivity-s.ath_sensitivity),s.interch+=o*(c.interch-s.interch),s.msfix+=o*(c.msfix-s.msfix),l(e,u.vbr_q),n==0&&Math.abs(e.quant_comp- -1)>0||(e.quant_comp=u.quant_comp),n==0&&Math.abs(e.quant_comp_short- -1)>0||(e.quant_comp_short=u.quant_comp_s),u.expY!=0&&(e.experimentalY=u.expY!=0),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre- -1)>0||(e.internal_flags.nsPsy.attackthre=u.st_lrm),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre_s- -1)>0||(e.internal_flags.nsPsy.attackthre_s=u.st_s),n==0&&Math.abs(e.maskingadjust-0)>0||(e.maskingadjust=u.masking_adj),n==0&&Math.abs(e.maskingadjust_short-0)>0||(e.maskingadjust_short=u.masking_adj_short),n==0&&Math.abs(-e.ATHlower*10-0)>0||(e.ATHlower=-u.ath_lower/10),n==0&&Math.abs(e.ATHcurve- -1)>0||(e.ATHcurve=u.ath_curve),n==0&&Math.abs(e.athaa_sensitivity- -1)>0||(e.athaa_sensitivity=u.ath_sensitivity),u.interch>0&&(n==0&&Math.abs(e.interChRatio- -1)>0||(e.interChRatio=u.interch)),u.safejoint>0&&(e.exp_nspsytune|=u.safejoint),u.sfb21mod>0&&(e.exp_nspsytune|=u.sfb21mod<<20),n==0&&Math.abs(e.msfix- -1)>0||(e.msfix=u.msfix),n==0&&(e.VBR_q=t,e.VBR_q_frac=o)}var s=[new n(8,9,9,0,0,6.6,145,0,.95,0,-30,11,.0012,1),new n(16,9,9,0,0,6.6,145,0,.95,0,-25,11,.001,1),new n(24,9,9,0,0,6.6,145,0,.95,0,-20,11,.001,1),new n(32,9,9,0,0,6.6,145,0,.95,0,-15,11,.001,1),new n(40,9,9,0,0,6.6,145,0,.95,0,-10,11,9e-4,1),new n(48,9,9,0,0,6.6,145,0,.95,0,-10,11,9e-4,1),new n(56,9,9,0,0,6.6,145,0,.95,0,-6,11,8e-4,1),new n(64,9,9,0,0,6.6,145,0,.95,0,-2,11,8e-4,1),new n(80,9,9,0,0,6.6,145,0,.95,0,0,8,7e-4,1),new n(96,9,9,0,2.5,6.6,145,0,.95,0,1,5.5,6e-4,1),new n(112,9,9,0,2.25,6.6,145,0,.95,0,2,4.5,5e-4,1),new n(128,9,9,0,1.95,6.4,140,0,.95,0,3,4,2e-4,1),new n(160,9,9,1,1.79,6,135,0,.95,-2,5,3.5,0,1),new n(192,9,9,1,1.49,5.6,125,0,.97,-4,7,3,0,0),new n(224,9,9,1,1.25,5.2,125,0,.98,-6,9,2,0,0),new n(256,9,9,1,.97,5.2,125,0,1,-8,10,1,0,0),new n(320,9,9,1,.9,5.2,125,0,1,-10,12,0,0,0)];function c(e,t,n){var i=t,a=r.nearestBitrateFullIndex(t);if(e.VBR=Nt.vbr_abr,e.VBR_mean_bitrate_kbps=i,e.VBR_mean_bitrate_kbps=Math.min(e.VBR_mean_bitrate_kbps,320),e.VBR_mean_bitrate_kbps=Math.max(e.VBR_mean_bitrate_kbps,8),e.brate=e.VBR_mean_bitrate_kbps,e.VBR_mean_bitrate_kbps>320&&(e.disable_reservoir=!0),s[a].safejoint>0&&(e.exp_nspsytune|=2),s[a].sfscale>0&&(e.internal_flags.noise_shaping=2),Math.abs(s[a].nsbass)>0){var o=int(s[a].nsbass*4);o<0&&(o+=64),e.exp_nspsytune|=o<<2}return n==0&&Math.abs(e.quant_comp- -1)>0||(e.quant_comp=s[a].quant_comp),n==0&&Math.abs(e.quant_comp_short- -1)>0||(e.quant_comp_short=s[a].quant_comp_s),n==0&&Math.abs(e.msfix- -1)>0||(e.msfix=s[a].nsmsfix),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre- -1)>0||(e.internal_flags.nsPsy.attackthre=s[a].st_lrm),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre_s- -1)>0||(e.internal_flags.nsPsy.attackthre_s=s[a].st_s),n==0&&Math.abs(e.scale- -1)>0||(e.scale=s[a].scale),n==0&&Math.abs(e.maskingadjust-0)>0||(e.maskingadjust=s[a].masking_adj),s[a].masking_adj>0?n==0&&Math.abs(e.maskingadjust_short-0)>0||(e.maskingadjust_short=s[a].masking_adj*.9):n==0&&Math.abs(e.maskingadjust_short-0)>0||(e.maskingadjust_short=s[a].masking_adj*1.1),n==0&&Math.abs(-e.ATHlower*10-0)>0||(e.ATHlower=-s[a].ath_lower/10),n==0&&Math.abs(e.ATHcurve- -1)>0||(e.ATHcurve=s[a].ath_curve),n==0&&Math.abs(e.interChRatio- -1)>0||(e.interChRatio=s[a].interch),t}this.apply_preset=function(t,n,r){switch(n){case e.R3MIX:n=e.V3,t.VBR=Nt.vbr_mtrh;break;case e.MEDIUM:n=e.V4,t.VBR=Nt.vbr_rh;break;case e.MEDIUM_FAST:n=e.V4,t.VBR=Nt.vbr_mtrh;break;case e.STANDARD:n=e.V2,t.VBR=Nt.vbr_rh;break;case e.STANDARD_FAST:n=e.V2,t.VBR=Nt.vbr_mtrh;break;case e.EXTREME:n=e.V0,t.VBR=Nt.vbr_rh;break;case e.EXTREME_FAST:n=e.V0,t.VBR=Nt.vbr_mtrh;break;case e.INSANE:return n=320,t.preset=n,c(t,n,r),t.VBR=Nt.vbr_off,n}switch(t.preset=n,n){case e.V9:return o(t,9,r),n;case e.V8:return o(t,8,r),n;case e.V7:return o(t,7,r),n;case e.V6:return o(t,6,r),n;case e.V5:return o(t,5,r),n;case e.V4:return o(t,4,r),n;case e.V3:return o(t,3,r),n;case e.V2:return o(t,2,r),n;case e.V1:return o(t,1,r),n;case e.V0:return o(t,0,r),n}return 8<=n&&n<=320?c(t,n,r):(t.preset=0,n)};function l(e,t){var n=0;return 0>t&&(n=-1,t=0),9<t&&(n=-1,t=9),e.VBR_q=t,e.VBR_q_frac=0,n}}var Ft=Pt;function It(){this.setModules=function(e,t){}}var Lt=It;function Rt(){this.over_noise=0,this.tot_noise=0,this.max_noise=0,this.over_count=0,this.over_SSD=0,this.bits=0}var zt=Rt,Bt=g,Vt=Bt.new_float,Ht=Bt.new_int;function Ut(){this.global_gain=0,this.sfb_count1=0,this.step=Ht(39),this.noise=Vt(39),this.noise_log=Vt(39)}var Wt=Ut,Gt=g,Kt=Gt.System,qt=Gt.VbrMode,Jt=Gt.Util,Yt=Gt.Arrays,Xt=Gt.new_float,Zt=Gt.assert,Qt=Lt,$t=zt,en=Wt,$=A(),tn=ge,nn=ue;function rn(){var e;this.rv=null;var t;this.qupvt=null;var n,r=new Qt,i;this.setModules=function(a,o,s,c){e=a,t=o,this.rv=o,n=s,this.qupvt=s,i=c,r.setModules(n,i)},this.ms_convert=function(e,t){for(var n=0;n<576;++n){var r=e.tt[t][0].xr[n],i=e.tt[t][1].xr[n];e.tt[t][0].xr[n]=(r+i)*(Jt.SQRT2*.5),e.tt[t][1].xr[n]=(r-i)*(Jt.SQRT2*.5)}};function a(e,t,n,r){r=0;for(var i=0;i<=n;++i){var a=Math.abs(e.xr[i]);r+=a,t[i]=Math.sqrt(a*Math.sqrt(a)),t[i]>e.xrpow_max&&(e.xrpow_max=t[i])}return r}this.init_xrpow=function(e,t,n){var r=0,i=0|t.max_nonzero_coeff;if(t.xrpow_max=0,Yt.fill(n,i,576,0),r=a(t,n,i,r),r>1e-20){var o=0;e.substep_shaping&2&&(o=1);for(var s=0;s<t.psymax;s++)e.pseudohalf[s]=o;return!0}return Yt.fill(t.l3_enc,0,576,0),!1};function o(e,t){var r=e.ATH,i=t.xr;if(t.block_type!=$.SHORT_TYPE)for(var a=!1,o=$.PSFB21-1;o>=0&&!a;o--){var s=e.scalefac_band.psfb21[o],c=e.scalefac_band.psfb21[o+1],l=n.athAdjust(r.adjust,r.psfb21[o],r.floor);e.nsPsy.longfact[21]>1e-12&&(l*=e.nsPsy.longfact[21]);for(var u=c-1;u>=s;u--)if(Math.abs(i[u])<l)i[u]=0;else{a=!0;break}}else for(var d=0;d<3;d++)for(var a=!1,o=$.PSFB12-1;o>=0&&!a;o--){var s=e.scalefac_band.s[12]*3+(e.scalefac_band.s[13]-e.scalefac_band.s[12])*d+(e.scalefac_band.psfb12[o]-e.scalefac_band.psfb12[0]),c=s+(e.scalefac_band.psfb12[o+1]-e.scalefac_band.psfb12[o]),f=n.athAdjust(r.adjust,r.psfb12[o],r.floor);e.nsPsy.shortfact[12]>1e-12&&(f*=e.nsPsy.shortfact[12]);for(var u=c-1;u>=s;u--)if(Math.abs(i[u])<f)i[u]=0;else{a=!0;break}}}this.init_outer_loop=function(e,t){t.part2_3_length=0,t.big_values=0,t.count1=0,t.global_gain=210,t.scalefac_compress=0,t.table_select[0]=0,t.table_select[1]=0,t.table_select[2]=0,t.subblock_gain[0]=0,t.subblock_gain[1]=0,t.subblock_gain[2]=0,t.subblock_gain[3]=0,t.region0_count=0,t.region1_count=0,t.preflag=0,t.scalefac_scale=0,t.count1table_select=0,t.part2_length=0,t.sfb_lmax=$.SBPSY_l,t.sfb_smin=$.SBPSY_s,t.psy_lmax=e.sfb21_extra?$.SBMAX_l:$.SBPSY_l,t.psymax=t.psy_lmax,t.sfbmax=t.sfb_lmax,t.sfbdivide=11;for(var r=0;r<$.SBMAX_l;r++)t.width[r]=e.scalefac_band.l[r+1]-e.scalefac_band.l[r],t.window[r]=3;if(t.block_type==$.SHORT_TYPE){var i=Xt(576);t.sfb_smin=0,t.sfb_lmax=0,t.mixed_block_flag!=0&&(t.sfb_smin=3,t.sfb_lmax=e.mode_gr*2+4),t.psymax=t.sfb_lmax+3*((e.sfb21_extra?$.SBMAX_s:$.SBPSY_s)-t.sfb_smin),t.sfbmax=t.sfb_lmax+3*($.SBPSY_s-t.sfb_smin),t.sfbdivide=t.sfbmax-18,t.psy_lmax=t.sfb_lmax;var a=e.scalefac_band.l[t.sfb_lmax];Kt.arraycopy(t.xr,0,i,0,576);for(var r=t.sfb_smin;r<$.SBMAX_s;r++)for(var s=e.scalefac_band.s[r],c=e.scalefac_band.s[r+1],l=0;l<3;l++)for(var u=s;u<c;u++)t.xr[a++]=i[3*u+l];for(var d=t.sfb_lmax,r=t.sfb_smin;r<$.SBMAX_s;r++)t.width[d]=t.width[d+1]=t.width[d+2]=e.scalefac_band.s[r+1]-e.scalefac_band.s[r],t.window[d]=0,t.window[d+1]=1,t.window[d+2]=2,d+=3}t.count1bits=0,t.sfb_partition_table=n.nr_of_sfb_block[0][0],t.slen[0]=0,t.slen[1]=0,t.slen[2]=0,t.slen[3]=0,t.max_nonzero_coeff=575,Yt.fill(t.scalefac,0),o(e,t)};function s(e){this.ordinal=e}s.BINSEARCH_NONE=new s(0),s.BINSEARCH_UP=new s(1),s.BINSEARCH_DOWN=new s(2);function c(e,t,n,r,a){var o,c=e.CurrentStep[r],l=!1,u=e.OldValue[r],d=s.BINSEARCH_NONE;for(t.global_gain=u,n-=t.part2_length;;){var f;if(o=i.count_bits(e,a,t,null),c==1||o==n)break;o>n?(d==s.BINSEARCH_DOWN&&(l=!0),l&&(c/=2),d=s.BINSEARCH_UP,f=c):(d==s.BINSEARCH_UP&&(l=!0),l&&(c/=2),d=s.BINSEARCH_DOWN,f=-c),t.global_gain+=f,t.global_gain<0&&(t.global_gain=0,l=!0),t.global_gain>255&&(t.global_gain=255,l=!0)}for(Zt(t.global_gain>=0),Zt(t.global_gain<256);o>n&&t.global_gain<255;)t.global_gain++,o=i.count_bits(e,a,t,null);return e.CurrentStep[r]=u-t.global_gain>=4?4:2,e.OldValue[r]=t.global_gain,t.part2_3_length=o,o}this.trancate_smallspectrums=function(e,t,r,a){var o=Xt(nn.SFBMAX);if(!(!(e.substep_shaping&4)&&t.block_type==$.SHORT_TYPE||e.substep_shaping&128)){n.calc_noise(t,r,o,new $t,null);for(var s=0;s<576;s++){var c=0;t.l3_enc[s]!=0&&(c=Math.abs(t.xr[s])),a[s]=c}var s=0,l=8;t.block_type==$.SHORT_TYPE&&(l=6);do{var u,d,f,p,m=t.width[l];if(s+=m,!(o[l]>=1)&&(Yt.sort(a,s-m,m),!BitStream.EQ(a[s-1],0))){u=(1-o[l])*r[l],d=0,p=0;do{var h;for(f=1;p+f<m&&!BitStream.NEQ(a[p+s-m],a[p+s+f-m]);f++);if(h=a[p+s-m]*a[p+s-m]*f,u<h){p!=0&&(d=a[p+s-m-1]);break}u-=h,p+=f}while(p<m);if(!BitStream.EQ(d,0))do Math.abs(t.xr[s-m])<=d&&(t.l3_enc[s-m]=0);while(--m>0)}}while(++l<t.psymax);t.part2_3_length=i.noquant_count_bits(e,t,null)}};function l(e){for(var t=0;t<e.sfbmax;t++)if(e.scalefac[t]+e.subblock_gain[e.window[t]]==0)return!1;return!0}function u(e){return Jt.FAST_LOG10(.368+.632*e*e*e)}function d(e,t){for(var n=1e-37,r=0;r<t.psymax;r++)n+=u(e[r]);return Math.max(1e-20,n)}function f(e,t,n,r,i){var a;switch(e){default:case 9:t.over_count>0?(a=n.over_SSD<=t.over_SSD,n.over_SSD==t.over_SSD&&(a=n.bits<t.bits)):a=n.max_noise<0&&n.max_noise*10+n.bits<=t.max_noise*10+t.bits;break;case 0:a=n.over_count<t.over_count||n.over_count==t.over_count&&n.over_noise<t.over_noise||n.over_count==t.over_count&&BitStream.EQ(n.over_noise,t.over_noise)&&n.tot_noise<t.tot_noise;break;case 8:n.max_noise=d(i,r);case 1:a=n.max_noise<t.max_noise;break;case 2:a=n.tot_noise<t.tot_noise;break;case 3:a=n.tot_noise<t.tot_noise&&n.max_noise<t.max_noise;break;case 4:a=n.max_noise<=0&&t.max_noise>.2||n.max_noise<=0&&t.max_noise<0&&t.max_noise>n.max_noise-.2&&n.tot_noise<t.tot_noise||n.max_noise<=0&&t.max_noise>0&&t.max_noise>n.max_noise-.2&&n.tot_noise<t.tot_noise+t.over_noise||n.max_noise>0&&t.max_noise>-.05&&t.max_noise>n.max_noise-.1&&n.tot_noise+n.over_noise<t.tot_noise+t.over_noise||n.max_noise>0&&t.max_noise>-.1&&t.max_noise>n.max_noise-.15&&n.tot_noise+n.over_noise+n.over_noise<t.tot_noise+t.over_noise+t.over_noise;break;case 5:a=n.over_noise<t.over_noise||BitStream.EQ(n.over_noise,t.over_noise)&&n.tot_noise<t.tot_noise;break;case 6:a=n.over_noise<t.over_noise||BitStream.EQ(n.over_noise,t.over_noise)&&(n.max_noise<t.max_noise||BitStream.EQ(n.max_noise,t.max_noise)&&n.tot_noise<=t.tot_noise);break;case 7:a=n.over_count<t.over_count||n.over_noise<t.over_noise;break}return t.over_count==0&&(a&&=n.bits<t.bits),a}function p(e,t,n,r,i){for(var a=e.internal_flags,o=t.scalefac_scale==0?1.2968395546510096:1.6817928305074292,s=0,c=0;c<t.sfbmax;c++)s<n[c]&&(s=n[c]);var l=a.noise_shaping_amp;switch(l==3&&(l=i?2:1),l){case 2:break;case 1:s>1?s**=.5:s*=.95;break;default:s>1?s=1:s*=.95;break}for(var u=0,c=0;c<t.sfbmax;c++){var d=t.width[c],f;if(u+=d,!(n[c]<s)){if(a.substep_shaping&2&&(a.pseudohalf[c]=+(a.pseudohalf[c]==0),a.pseudohalf[c]==0&&a.noise_shaping_amp==2))return;for(t.scalefac[c]++,f=-d;f<0;f++)r[u+f]*=o,r[u+f]>t.xrpow_max&&(t.xrpow_max=r[u+f]);if(a.noise_shaping_amp==2)return}}}function m(e,t){for(var r=1.2968395546510096,i=0,a=0;a<e.sfbmax;a++){var o=e.width[a],s=e.scalefac[a];if(e.preflag!=0&&(s+=n.pretab[a]),i+=o,s&1){s++;for(var c=-o;c<0;c++)t[i+c]*=r,t[i+c]>e.xrpow_max&&(e.xrpow_max=t[i+c])}e.scalefac[a]=s>>1}e.preflag=0,e.scalefac_scale=1}function h(e,t,r){var i,a=t.scalefac;for(i=0;i<t.sfb_lmax;i++)if(a[i]>=16)return!0;for(var o=0;o<3;o++){var s=0,c=0;for(i=t.sfb_lmax+o;i<t.sfbdivide;i+=3)s<a[i]&&(s=a[i]);for(;i<t.sfbmax;i+=3)c<a[i]&&(c=a[i]);if(!(s<16&&c<8)){if(t.subblock_gain[o]>=7)return!0;t.subblock_gain[o]++;var l=e.scalefac_band.l[t.sfb_lmax];for(i=t.sfb_lmax+o;i<t.sfbmax;i+=3){var u,d=t.width[i],f=a[i];if(f-=4>>t.scalefac_scale,f>=0){a[i]=f,l+=d*3;continue}a[i]=0;var p=210+(f<<t.scalefac_scale+1);u=n.IPOW20(p),l+=d*(o+1);for(var m=-d;m<0;m++)r[l+m]*=u,r[l+m]>t.xrpow_max&&(t.xrpow_max=r[l+m]);l+=d*(3-o-1)}var u=n.IPOW20(202);l+=t.width[i]*(o+1);for(var m=-t.width[i];m<0;m++)r[l+m]*=u,r[l+m]>t.xrpow_max&&(t.xrpow_max=r[l+m])}}return!1}function g(e,t,n,r,a){var o=e.internal_flags;p(e,t,n,r,a);var s=l(t);return s?!1:(s=o.mode_gr==2?i.scale_bitcount(t):i.scale_bitcount_lsf(o,t),s?(o.noise_shaping>1&&(Yt.fill(o.pseudohalf,0),t.scalefac_scale==0?(m(t,r),s=!1):t.block_type==$.SHORT_TYPE&&o.subblock_gain>0&&(s=h(o,t,r)||l(t))),s||=o.mode_gr==2?i.scale_bitcount(t):i.scale_bitcount_lsf(o,t),!s):!0)}this.outer_loop=function(e,t,r,a,o,s){var l=e.internal_flags,u=new tn,d=Xt(576),p=Xt(nn.SFBMAX),m=new $t,h,_=new en,v=9999999,y=!1,b=!1,x=0;if(c(l,t,s,o,a),l.noise_shaping==0)return 100;n.calc_noise(t,r,p,m,_),m.bits=t.part2_3_length,u.assign(t);var S=0;for(Kt.arraycopy(a,0,d,0,576);!y;){do{var C=new $t,w,T=255;if(w=l.substep_shaping&2?20:3,l.sfb21_extra&&(p[u.sfbmax]>1||u.block_type==$.SHORT_TYPE&&(p[u.sfbmax+1]>1||p[u.sfbmax+2]>1))||!g(e,u,p,a,b))break;u.scalefac_scale!=0&&(T=254);var E=s-u.part2_length;if(E<=0)break;for(;(u.part2_3_length=i.count_bits(l,a,u,_))>E&&u.global_gain<=T;)u.global_gain++;if(u.global_gain>T)break;if(m.over_count==0){for(;(u.part2_3_length=i.count_bits(l,a,u,_))>v&&u.global_gain<=T;)u.global_gain++;if(u.global_gain>T)break}if(n.calc_noise(u,r,p,C,_),C.bits=u.part2_3_length,h=t.block_type==$.SHORT_TYPE?e.quant_comp_short:e.quant_comp,h=+!!f(h,m,C,u,p),h!=0)v=t.part2_3_length,m=C,t.assign(u),S=0,Kt.arraycopy(a,0,d,0,576);else if(l.full_outer_loop==0&&(++S>w&&m.over_count==0||l.noise_shaping_amp==3&&b&&S>30||l.noise_shaping_amp==3&&b&&u.global_gain-x>15))break}while(u.global_gain+u.scalefac_scale<255);l.noise_shaping_amp==3?b?y=!0:(u.assign(t),Kt.arraycopy(d,0,a,0,576),S=0,x=u.global_gain,b=!0):y=!0}return Zt(t.global_gain+t.scalefac_scale<=255),e.VBR==qt.vbr_rh||e.VBR==qt.vbr_mtrh?Kt.arraycopy(d,0,a,0,576):l.substep_shaping&1&&trancate_smallspectrums(l,t,r,a),m.over_count},this.iteration_finish_one=function(e,n,r){var a=e.l3_side,o=a.tt[n][r];i.best_scalefac_store(e,n,r,a),e.use_best_huffman==1&&i.best_huffman_divide(e,o),t.ResvAdjust(e,o)},this.VBR_encode_granule=function(e,t,n,r,i,a,o){var s=e.internal_flags,c=new tn,l=Xt(576),u=o,d=o+1,f=(o+a)/2,p,m,h=0,g=s.sfb21_extra;Zt(u<=LameInternalFlags.MAX_BITS_PER_CHANNEL),Yt.fill(c.l3_enc,0);do f>u-42?s.sfb21_extra=!1:s.sfb21_extra=g,m=outer_loop(e,t,n,r,i,f),m<=0?(h=1,d=t.part2_3_length,c.assign(t),Kt.arraycopy(r,0,l,0,576),o=d-32,p=o-a,f=(o+a)/2):(a=f+32,p=o-a,f=(o+a)/2,h!=0&&(h=2,t.assign(c),Kt.arraycopy(l,0,r,0,576)));while(p>12);s.sfb21_extra=g,h==2&&Kt.arraycopy(c.l3_enc,0,t.l3_enc,0,576),Zt(t.part2_3_length<=u)},this.get_framebits=function(n,r){var i=n.internal_flags;i.bitrate_index=i.VBR_min_bitrate;var a=e.getframebits(n);i.bitrate_index=1,a=e.getframebits(n);for(var o=1;o<=i.VBR_max_bitrate;o++){i.bitrate_index=o;var s=new MeanBits(a);r[o]=t.ResvFrameBegin(n,s),a=s.bits}},this.VBR_old_prepare=function(e,r,i,a,o,s,c,l,u){var d=e.internal_flags,f,p=0,m=1,h=0;d.bitrate_index=d.VBR_max_bitrate;var g=t.ResvFrameBegin(e,new MeanBits(0))/d.mode_gr;get_framebits(e,s);for(var _=0;_<d.mode_gr;_++){var v=n.on_pe(e,r,l[_],g,_,0);d.mode_ext==$.MPG_MD_MS_LR&&(ms_convert(d.l3_side,_),n.reduce_side(l[_],i[_],g,v));for(var y=0;y<d.channels_out;++y){var b=d.l3_side.tt[_][y];b.block_type==$.SHORT_TYPE?(p=2.56/(1+Math.exp(3.5-r[_][y]/300))-.14,f=d.PSY.mask_adjust_short-p):(p=1.28/(1+Math.exp(3.5-r[_][y]/300))-.05,f=d.PSY.mask_adjust-p),d.masking_lower=10**(f*.1),init_outer_loop(d,b),u[_][y]=n.calc_xmin(e,a[_][y],b,o[_][y]),u[_][y]!=0&&(m=0),c[_][y]=126,h+=l[_][y]}}for(var _=0;_<d.mode_gr;_++)for(var y=0;y<d.channels_out;y++)h>s[d.VBR_max_bitrate]&&(l[_][y]*=s[d.VBR_max_bitrate],l[_][y]/=h),c[_][y]>l[_][y]&&(c[_][y]=l[_][y]);return m},this.bitpressure_strategy=function(e,t,n,r){for(var i=0;i<e.mode_gr;i++)for(var a=0;a<e.channels_out;a++){for(var o=e.l3_side.tt[i][a],s=t[i][a],c=0,l=0;l<o.psy_lmax;l++)s[c++]*=1+.029*l*l/$.SBMAX_l/$.SBMAX_l;if(o.block_type==$.SHORT_TYPE)for(var l=o.sfb_smin;l<$.SBMAX_s;l++)s[c++]*=1+.029*l*l/$.SBMAX_s/$.SBMAX_s,s[c++]*=1+.029*l*l/$.SBMAX_s/$.SBMAX_s,s[c++]*=1+.029*l*l/$.SBMAX_s/$.SBMAX_s;r[i][a]=0|Math.max(n[i][a],.9*r[i][a])}},this.VBR_new_prepare=function(e,r,i,a,o,s){var c=e.internal_flags,l=1,u=0,d=0,f;if(e.free_format){c.bitrate_index=0;var p=new MeanBits(u);f=t.ResvFrameBegin(e,p),u=p.bits,o[0]=f}else{c.bitrate_index=c.VBR_max_bitrate;var p=new MeanBits(u);t.ResvFrameBegin(e,p),u=p.bits,get_framebits(e,o),f=o[c.VBR_max_bitrate]}for(var m=0;m<c.mode_gr;m++){n.on_pe(e,r,s[m],u,m,0),c.mode_ext==$.MPG_MD_MS_LR&&ms_convert(c.l3_side,m);for(var h=0;h<c.channels_out;++h){var g=c.l3_side.tt[m][h];c.masking_lower=10**(c.PSY.mask_adjust*.1),init_outer_loop(c,g),n.calc_xmin(e,i[m][h],g,a[m][h])!=0&&(l=0),d+=s[m][h]}}for(var m=0;m<c.mode_gr;m++)for(var h=0;h<c.channels_out;h++)d>f&&(s[m][h]*=f,s[m][h]/=d);return l},this.calc_target_bits=function(r,i,a,o,s,c){var l=r.internal_flags,u=l.l3_side,d,f,p,m,h=0;l.bitrate_index=l.VBR_max_bitrate;var g=new MeanBits(h);for(c[0]=t.ResvFrameBegin(r,g),h=g.bits,l.bitrate_index=1,h=e.getframebits(r)-l.sideinfo_len*8,s[0]=h/(l.mode_gr*l.channels_out),h=r.VBR_mean_bitrate_kbps*r.framesize*1e3,l.substep_shaping&1&&(h*=1.09),h/=r.out_samplerate,h-=l.sideinfo_len*8,h/=l.mode_gr*l.channels_out,d=.93+.07*(11-r.compression_ratio)/5.5,d<.9&&(d=.9),d>1&&(d=1),f=0;f<l.mode_gr;f++){var _=0;for(p=0;p<l.channels_out;p++){if(o[f][p]=int(d*h),i[f][p]>700){var v=int((i[f][p]-700)/1.4),y=u.tt[f][p];o[f][p]=int(d*h),y.block_type==$.SHORT_TYPE&&v<h/2&&(v=h/2),v>h*3/2?v=h*3/2:v<0&&(v=0),o[f][p]+=v}o[f][p]>LameInternalFlags.MAX_BITS_PER_CHANNEL&&(o[f][p]=LameInternalFlags.MAX_BITS_PER_CHANNEL),_+=o[f][p]}if(_>LameInternalFlags.MAX_BITS_PER_GRANULE)for(p=0;p<l.channels_out;++p)o[f][p]*=LameInternalFlags.MAX_BITS_PER_GRANULE,o[f][p]/=_}if(l.mode_ext==$.MPG_MD_MS_LR)for(f=0;f<l.mode_gr;f++)n.reduce_side(o[f],a[f],h*l.channels_out,LameInternalFlags.MAX_BITS_PER_GRANULE);for(m=0,f=0;f<l.mode_gr;f++)for(p=0;p<l.channels_out;p++)o[f][p]>LameInternalFlags.MAX_BITS_PER_CHANNEL&&(o[f][p]=LameInternalFlags.MAX_BITS_PER_CHANNEL),m+=o[f][p];if(m>c[0])for(f=0;f<l.mode_gr;f++)for(p=0;p<l.channels_out;p++)o[f][p]*=c[0],o[f][p]/=m}}var an=rn,on=g.assert;function sn(){var e;this.setModules=function(t){e=t},this.ResvFrameBegin=function(t,n){var r=t.internal_flags,i,a=r.l3_side,o=e.getframebits(t);n.bits=(o-r.sideinfo_len*8)/r.mode_gr;var s=8*256*r.mode_gr-8;t.brate>320?i=8*int(t.brate*1e3/(t.out_samplerate/1152)/8+.5):(i=8*1440,t.strict_ISO&&(i=8*int(32e4/(t.out_samplerate/1152)/8+.5))),r.ResvMax=i-o,r.ResvMax>s&&(r.ResvMax=s),(r.ResvMax<0||t.disable_reservoir)&&(r.ResvMax=0);var c=n.bits*r.mode_gr+Math.min(r.ResvSize,r.ResvMax);return c>i&&(c=i),on(r.ResvMax%8==0),on(r.ResvMax>=0),a.resvDrain_pre=0,r.pinfo!=null&&(r.pinfo.mean_bits=n.bits/2,r.pinfo.resvsize=r.ResvSize),c},this.ResvMaxBits=function(e,t,n,r){var i=e.internal_flags,a,o=i.ResvSize,s=i.ResvMax;r!=0&&(o+=t),i.substep_shaping&1&&(s*=.9),n.bits=t,o*10>s*9?(a=o-s*9/10,n.bits+=a,i.substep_shaping|=128):(a=0,i.substep_shaping&=127,!e.disable_reservoir&&!(i.substep_shaping&1)&&(n.bits-=.1*t));var c=o<i.ResvMax*6/10?o:i.ResvMax*6/10;return c-=a,c<0&&(c=0),c},this.ResvAdjust=function(e,t){e.ResvSize-=t.part2_3_length+t.part2_length},this.ResvFrameEnd=function(e,t){var n,r=e.l3_side;e.ResvSize+=t*e.mode_gr;var i=0;r.resvDrain_post=0,r.resvDrain_pre=0,(n=e.ResvSize%8)!=0&&(i+=n),n=e.ResvSize-i-e.ResvMax,n>0&&(i+=n);var a=Math.min(r.main_data_begin*8,i)/8;r.resvDrain_pre+=8*a,i-=8*a,e.ResvSize-=8*a,r.main_data_begin-=a,r.resvDrain_post+=i,e.ResvSize-=i}}var cn=sn;function ln(){var e=`http://www.mp3dev.org/`,t=3,n=98,r=4,i=0,a=93;this.getLameVersion=function(){return t+`.`+n+`.`+r},this.getLameShortVersion=function(){return t+`.`+n+`.`+r},this.getLameVeryShortVersion=function(){return`LAME`+t+`.`+n+`r`},this.getPsyVersion=function(){return i+`.`+a},this.getLameUrl=function(){return e},this.getLameOsBitness=function(){return`32bits`}}var un=ln,dn=g,fn=dn.System,pn=dn.VbrMode,mn=dn.ShortBlock,hn=dn.Arrays,gn=dn.new_byte,_n=dn.assert;vn.NUMTOCENTRIES=100,vn.MAXFRAMESIZE=2880;function vn(){var e,t,n;this.setModules=function(r,i,a){e=r,t=i,n=a};var r=1,i=2,a=4,o=8,s=vn.NUMTOCENTRIES,c=vn.MAXFRAMESIZE,l=s+4+4+4+4+4+9+1+1+8+1+1+3+1+1+2+4+2+2,u=128,d=64,f=32,p=null,m=`Xing`,h=`Info`,g=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];function _(e,t){if(e.nVbrNumFrames++,e.sum+=t,e.seen++,!(e.seen<e.want)&&(e.pos<e.size&&(e.bag[e.pos]=e.sum,e.pos++,e.seen=0),e.pos==e.size)){for(var n=1;n<e.size;n+=2)e.bag[n/2]=e.bag[n];e.want*=2,e.pos/=2}}function v(e,t){if(!(e.pos<=0))for(var n=1;n<s;++n){var r=n/s,i,a,o=0|Math.floor(r*e.pos);o>e.pos-1&&(o=e.pos-1),i=e.bag[o],a=e.sum;var c=0|256*i/a;c>255&&(c=255),t[n]=255&c}}this.addVbrFrame=function(e){var t=e.internal_flags,n=Tables.bitrate_table[e.version][t.bitrate_index];_n(t.VBR_seek_table.bag!=null),_(t.VBR_seek_table,n)};function y(e,t){var n=e[t+0]&255;return n<<=8,n|=e[t+1]&255,n<<=8,n|=e[t+2]&255,n<<=8,n|=e[t+3]&255,n}function b(e,t,n){e[t+0]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255}function x(e,t,n){e[t+0]=n>>8&255,e[t+1]=n&255}function S(e,t){return new String(e,t,m.length(),p).equals(m)||new String(e,t,h.length(),p).equals(h)}function C(e,t,n){return 255&(e<<t|n&~(-1<<t))}function w(t,n){var r=t.internal_flags;n[0]=C(n[0],8,255),n[1]=C(n[1],3,7),n[1]=C(n[1],1,t.out_samplerate<16e3?0:1),n[1]=C(n[1],1,t.version),n[1]=C(n[1],2,1),n[1]=C(n[1],1,+!t.error_protection),n[2]=C(n[2],4,r.bitrate_index),n[2]=C(n[2],2,r.samplerate_index),n[2]=C(n[2],1,0),n[2]=C(n[2],1,t.extension),n[3]=C(n[3],2,t.mode.ordinal()),n[3]=C(n[3],2,r.mode_ext),n[3]=C(n[3],1,t.copyright),n[3]=C(n[3],1,t.original),n[3]=C(n[3],2,t.emphasis),n[0]=255;var i=n[1]&241,a=t.version==1?u:t.out_samplerate<16e3?f:d;t.VBR==pn.vbr_off&&(a=t.brate);var o=t.free_format?0:255&16*e.BitrateIndex(a,t.version,t.out_samplerate);t.version==1?(n[1]=255&(i|10),i=n[2]&13,n[2]=255&(o|i)):(n[1]=255&(i|2),i=n[2]&13,n[2]=255&(o|i))}this.getVbrTag=function(e){var t=new VBRTagData,n=0;t.flags=0;var c=e[n+1]>>3&1,l=e[n+2]>>2&3,u=e[n+3]>>6&3,d=e[n+2]>>4&15;if(d=Tables.bitrate_table[c][d],e[n+1]>>4==14?t.samprate=Tables.samplerate_table[2][l]:t.samprate=Tables.samplerate_table[c][l],c==0?u==3?n+=13:n+=21:u==3?n+=21:n+=36,!S(e,n))return null;n+=4,t.hId=c;var f=t.flags=y(e,n);if(n+=4,f&r&&(t.frames=y(e,n),n+=4),f&i&&(t.bytes=y(e,n),n+=4),f&a){if(t.toc!=null)for(var p=0;p<s;p++)t.toc[p]=e[n+p];n+=s}t.vbrScale=-1,f&o&&(t.vbrScale=y(e,n),n+=4),t.headersize=(c+1)*72e3*d/t.samprate,n+=21;var m=e[n+0]<<4;m+=e[n+1]>>4;var h=(e[n+1]&15)<<8;return h+=e[n+2]&255,(m<0||m>3e3)&&(m=-1),(h<0||h>3e3)&&(h=-1),t.encDelay=m,t.encPadding=h,t},this.InitVbrTag=function(e){var n=e.internal_flags,r=e.version==1?u:e.out_samplerate<16e3?f:d;e.VBR==pn.vbr_off&&(r=e.brate);var i=(e.version+1)*72e3*r/e.out_samplerate,a=n.sideinfo_len+l;if(n.VBR_seek_table.TotalFrameSize=i,i<a||i>c){e.bWriteVbrTag=!1;return}n.VBR_seek_table.nVbrNumFrames=0,n.VBR_seek_table.nBytesWritten=0,n.VBR_seek_table.sum=0,n.VBR_seek_table.seen=0,n.VBR_seek_table.want=1,n.VBR_seek_table.pos=0,n.VBR_seek_table.bag??(n.VBR_seek_table.bag=new int[400],n.VBR_seek_table.size=400);var o=gn(c);w(e,o);for(var s=n.VBR_seek_table.TotalFrameSize,p=0;p<s;++p)t.add_dummy_byte(e,o[p]&255,1)};function T(e,t){var n=t^e;return t=t>>8^g[n&255],t}this.updateMusicCRC=function(e,t,n,r){for(var i=0;i<r;++i)e[0]=T(t[n+i],e[0])};function E(e,t,r,i,a){var o=e.internal_flags,s=0,c=e.encoder_delay,l=e.encoder_padding,u=100-10*e.VBR_q-e.quality,d=n.getLameVeryShortVersion(),f,p=0,m,h=[1,5,3,2,4,0,3],g=0|(e.lowpassfreq/100+.5>255?255:e.lowpassfreq/100+.5),_=0,v=0,y=0,S=e.internal_flags.noise_shaping,C=0,w=0,E=0,D=0,O=0,k=(e.exp_nspsytune&1)!=0,A=(e.exp_nspsytune&2)!=0,j=!1,M=!1,N=e.internal_flags.nogap_total,P=e.internal_flags.nogap_current,F=e.ATHtype,I=0,L;switch(e.VBR){case vbr_abr:L=e.VBR_mean_bitrate_kbps;break;case vbr_off:L=e.brate;break;default:L=e.VBR_min_bitrate_kbps}switch(f=e.VBR.ordinal()<h.length?h[e.VBR.ordinal()]:0,m=16*p+f,o.findReplayGain&&(o.RadioGain>510&&(o.RadioGain=510),o.RadioGain<-510&&(o.RadioGain=-510),v=8192,v|=3072,o.RadioGain>=0?v|=o.RadioGain:(v|=512,v|=-o.RadioGain)),o.findPeakSample&&(_=Math.abs(0|o.PeakSample/32767*2**23+.5)),N!=-1&&(P>0&&(M=!0),P<N-1&&(j=!0)),I=F+(!!k<<4)+(!!A<<5)+(!!j<<6)+(!!M<<7),u<0&&(u=0),e.mode){case MONO:C=0;break;case STEREO:C=1;break;case DUAL_CHANNEL:C=2;break;case JOINT_STEREO:C=e.force_ms?4:3;break;case NOT_SET:default:C=7;break}E=e.in_samplerate<=32e3?0:e.in_samplerate==48e3?2:e.in_samplerate>48e3?3:1,(e.short_blocks==mn.short_block_forced||e.short_blocks==mn.short_block_dispensed||e.lowpassfreq==-1&&e.highpassfreq==-1||e.scale_left<e.scale_right||e.scale_left>e.scale_right||e.disable_reservoir&&e.brate<320||e.noATH||e.ATHonly||F==0||e.in_samplerate<=32e3)&&(w=1),D=S+(C<<2)+(w<<5)+(E<<6),O=o.nMusicCRC,b(r,i+s,u),s+=4;for(var R=0;R<9;R++)r[i+s+R]=255&d.charAt(R);s+=9,r[i+s]=255&m,s++,r[i+s]=255&g,s++,b(r,i+s,_),s+=4,x(r,i+s,v),s+=2,x(r,i+s,y),s+=2,r[i+s]=255&I,s++,L>=255?r[i+s]=255:r[i+s]=255&L,s++,r[i+s]=255&c>>4,r[i+s+1]=255&(c<<4)+(l>>8),r[i+s+2]=255&l,s+=3,r[i+s]=255&D,s++,r[i+ s++]=0,x(r,i+s,e.preset),s+=2,b(r,i+s,t),s+=4,x(r,i+s,O),s+=2;for(var z=0;z<s;z++)a=T(r[i+z],a);return x(r,i+s,a),s+=2,s}function D(e){e.seek(0);var t=gn(10);e.readFully(t);var n;return n=new String(t,`ISO-8859-1`).startsWith(`ID3`)?0:((t[6]&127)<<21|(t[7]&127)<<14|(t[8]&127)<<7|t[9]&127)+t.length,n}this.getLameTagFrame=function(e,n){var c=e.internal_flags;if(!e.bWriteVbrTag||c.Class_ID!=Lame.LAME_ID||c.VBR_seek_table.pos<=0)return 0;if(n.length<c.VBR_seek_table.TotalFrameSize)return c.VBR_seek_table.TotalFrameSize;hn.fill(n,0,c.VBR_seek_table.TotalFrameSize,0),w(e,n);var l=gn(s);if(e.free_format)for(var u=1;u<s;++u)l[u]=255&255*u/100;else v(c.VBR_seek_table,l);var d=c.sideinfo_len;e.error_protection&&(d-=2),e.VBR==pn.vbr_off?(n[d++]=255&h.charAt(0),n[d++]=255&h.charAt(1),n[d++]=255&h.charAt(2),n[d++]=255&h.charAt(3)):(n[d++]=255&m.charAt(0),n[d++]=255&m.charAt(1),n[d++]=255&m.charAt(2),n[d++]=255&m.charAt(3)),b(n,d,r+i+a+o),d+=4,b(n,d,c.VBR_seek_table.nVbrNumFrames),d+=4;var f=c.VBR_seek_table.nBytesWritten+c.VBR_seek_table.TotalFrameSize;b(n,d,0|f),d+=4,fn.arraycopy(l,0,n,d,l.length),d+=l.length,e.error_protection&&t.CRC_writeheader(c,n);for(var p=0,u=0;u<d;u++)p=T(n[u],p);return d+=E(e,f,n,d,p),c.VBR_seek_table.TotalFrameSize},this.putVbrTag=function(e,t){if(e.internal_flags.VBR_seek_table.pos<=0||(t.seek(t.length()),t.length()==0))return-1;var n=D(t);t.seek(n);var r=gn(c),i=getLameTagFrame(e,r);return i>r.length?-1:(i<1||t.write(r,0,i),0)}}var yn=vn,bn=g,xn=bn.new_byte,Sn=bn.assert,Cn=Mt(),wn=Ft,Tn=tt,En=Ct(),Dn=an,On=Et(),kn=cn,An=D,jn=kt();A();var Mn=un,Nn=yn;function Pn(){this.setModules=function(e,t){}}function Fn(){this.setModules=function(e,t,n){}}function In(){}function Ln(){this.setModules=function(e,t){}}function Rn(e,t,n){arguments.length!=3&&(console.error(`WARN: Mp3Encoder(channels, samplerate, kbps) not specified`),e=1,t=44100,n=128);var r=new Cn,i=new Pn,a=new Tn,o=new jn,s=new wn,c=new En,l=new Dn,u=new Nn,d=new Mn,f=new Ln,p=new kn,m=new On,h=new Fn,g=new In;r.setModules(a,o,s,c,l,u,d,f,g),o.setModules(a,g,d,u),f.setModules(o,d),s.setModules(r),l.setModules(o,p,c,m),c.setModules(m,p,r.enc.psy),p.setModules(o),m.setModules(c),u.setModules(r,o,d),i.setModules(h,g),h.setModules(d,f,s);var _=r.lame_init();_.num_channels=e,_.in_samplerate=t,_.brate=n,_.mode=An.STEREO,_.quality=3,_.bWriteVbrTag=!1,_.disable_reservoir=!0,_.write_id3tag_automatic=!1,r.lame_init_params(_);var v=1152,y=0|1.25*v+7200,b=xn(y);this.encodeBuffer=function(t,n){e==1&&(n=t),Sn(t.length==n.length),t.length>v&&(v=t.length,y=0|1.25*v+7200,b=xn(y));var i=r.lame_encode_buffer(_,t,n,t.length,b,0,y);return new Int8Array(b.subarray(0,i))},this.flush=function(){var e=r.lame_encode_flush(_,b,0,y);return new Int8Array(b.subarray(0,e))}}function zn(){this.dataOffset=0,this.dataLen=0,this.channels=0,this.sampleRate=0}function Bn(e){return e.charCodeAt(0)<<24|e.charCodeAt(1)<<16|e.charCodeAt(2)<<8|e.charCodeAt(3)}zn.RIFF=Bn(`RIFF`),zn.WAVE=Bn(`WAVE`),zn.fmt_=Bn(`fmt `),zn.data=Bn(`data`),zn.readHeader=function(e){var t=new zn,n=e.getUint32(0,!1);if(zn.RIFF==n&&(e.getUint32(4,!0),zn.WAVE==e.getUint32(8,!1)&&zn.fmt_==e.getUint32(12,!1))){var r=e.getUint32(16,!0),i=20;switch(r){case 16:case 18:t.channels=e.getUint16(i+2,!0),t.sampleRate=e.getUint32(i+4,!0);break;default:throw`extended fmt chunk not implemented`}i+=r;for(var a=zn.data,o=0;a!=n&&(n=e.getUint32(i,!1),o=e.getUint32(i+4,!0),a!=n);)i+=o+8;return t.dataLen=o,t.dataOffset=i+8,t}};var Vn=e.Mp3Encoder=Rn;e.WavHeader=zn;var Hn=1024,Un=16e3;Hn/Un,Un/Hn;var Wn={m4a:`audio/m4a`,wav:`audio/wav`,mp3:`audio/mpeg`};function Gn(e,t=Un,n=128){try{let r=new Vn(1,t,n),i=new Int16Array(e.length);for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]));i[t]=n<0?n*32768:n*32767}let a=[],o=r.encodeBuffer(i);o&&o.length>0&&a.push(o);let s=r.flush();return s&&s.length>0&&a.push(s),a.length===0?null:new Blob(a,{type:Wn.mp3})}catch(e){return console.error(`[ScribeSDK] MP3 encoding failed:`,e),null}}var Kn=3,qn=2e3,Jn,Yn=new Set,Xn=[];function Zn(e){for(let t of Xn)try{t.postMessage(e)}catch{}}async function Qn(e,t,n,r){let i=`Upload failed after retries`,a;for(let o=0;o<=Kn;o++)try{let s=e.endsWith(`/`)?`${e}${t}`:`${e}/${t}`,c={"Content-Type":`audio/mp3`,...r};Jn&&(c.Authorization=`Bearer ${Jn}`);let l=await fetch(s,{method:`POST`,body:n,headers:c});if(l.ok)return{success:!0};if(a=l.status,i=await $n(l),l.status===401){Zn({type:`token_required`}),await er(qn);continue}if(l.status>=400&&l.status<500&&l.status!==408&&l.status!==429)return{success:!1,error:i,statusCode:a};o<Kn&&await er(qn)}catch(e){i=e?.message??`Network error`,o<Kn&&await er(qn)}return{success:!1,error:i,statusCode:a}}async function $n(e){try{let t=await e.json();return t?.error?.message??t?.message??e.statusText??`Request failed`}catch{return e.statusText??`HTTP ${e.status}`}}function er(e){return new Promise(t=>setTimeout(t,e))}async function tr(e,t,n,r){try{let i=Gn(e);if(!i){Zn({type:`upload_failed`,fileName:t,error:`MP3 encoding failed`});return}let a=await Qn(n,t,i,r);a.success?Zn({type:`upload_success`,fileName:t}):Zn({type:`upload_failed`,fileName:t,error:a.error??`Upload failed after retries`,blob:i})}catch(e){Zn({type:`upload_failed`,fileName:t,error:e?.message??`Unknown error`})}}function nr(e){switch(e.type){case`compress_and_upload`:{let t=tr(e.audioFrames,e.fileName,e.uploadUrl,e.headers);Yn.add(t),t.finally(()=>Yn.delete(t));break}case`wait_for_all_uploads`:Promise.all(Yn).then(()=>{Zn({type:`all_uploads_complete`})});break;case`update_auth_token`:Jn=e.token;break;case`terminate`:for(let e of Xn)try{e.close()}catch{}self.close();break}}var rr=self;rr.onconnect=e=>{let t=e.ports[0];Xn.push(t),t.onmessage=e=>{nr(e.data)},t.start()}})();
|
|
14
|
+
`)),n.highpass2>0){for(var c=-1,o=0;o<=31;o++){var s=o/31;s<=n.highpass1&&(i=Math.max(i,o)),n.highpass1<s&&s<n.highpass2&&(c=Math.max(c,o))}n.highpass1=i/31,c==-1?n.highpass2=(i+.75)/31:n.highpass2=(c+.75)/31}for(var o=0;o<32;o++){var l,u,s=o/31;l=n.highpass2>n.highpass1?P((n.highpass2-s)/(n.highpass2-n.highpass1+1e-20)):1,u=n.lowpass2>n.lowpass1?P((s-n.lowpass1)/(n.lowpass2-n.lowpass1+1e-20)):1,n.amp_filter[o]=l*u}}function V(e){var t=e.internal_flags;switch(e.quality){default:case 9:t.psymodel=0,t.noise_shaping=0,t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.use_best_huffman=0,t.full_outer_loop=0;break;case 8:e.quality=7;case 7:t.psymodel=1,t.noise_shaping=0,t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.use_best_huffman=0,t.full_outer_loop=0;break;case 6:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=0,t.full_outer_loop=0;break;case 5:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=0,t.full_outer_loop=0;break;case 4:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=0,t.noise_shaping_stop=0,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 3:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.noise_shaping_amp=1,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 2:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.substep_shaping==0&&(t.substep_shaping=2),t.noise_shaping_amp=1,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 1:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.substep_shaping==0&&(t.substep_shaping=2),t.noise_shaping_amp=2,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break;case 0:t.psymodel=1,t.noise_shaping==0&&(t.noise_shaping=1),t.substep_shaping==0&&(t.substep_shaping=2),t.noise_shaping_amp=2,t.noise_shaping_stop=1,t.subblock_gain==-1&&(t.subblock_gain=1),t.use_best_huffman=1,t.full_outer_loop=0;break}}function ee(e){var t=e.internal_flags;e.frameNum=0,e.write_id3tag_automatic&&E.id3tag_write_v2(e),t.bitrate_stereoMode_Hist=a([16,5]),t.bitrate_blockType_Hist=a([16,6]),t.PeakSample=0,e.bWriteVbrTag&&T.InitVbrTag(e)}this.lame_init_params=function(t){var i=t.internal_flags;if(i.Class_ID=0,i.ATH??=new d,i.PSY??=new k,i.rgdata??=new f,i.channels_in=t.num_channels,i.channels_in==1&&(t.mode=e.MONO),i.channels_out=t.mode==e.MONO?1:2,i.mode_ext=_.MPG_MD_MS_LR,t.mode==e.MONO&&(t.force_ms=!1),t.VBR==n.vbr_off&&t.VBR_mean_bitrate_kbps!=128&&t.brate==0&&(t.brate=t.VBR_mean_bitrate_kbps),t.VBR==n.vbr_off||t.VBR==n.vbr_mtrh||t.VBR==n.vbr_mt||(t.free_format=!1),t.VBR==n.vbr_off&&t.brate==0&&m.EQ(t.compression_ratio,0)&&(t.compression_ratio=11.025),t.VBR==n.vbr_off&&t.compression_ratio>0&&(t.out_samplerate==0&&(t.out_samplerate=map2MP3Frequency(int(.97*t.in_samplerate))),t.brate=0|t.out_samplerate*16*i.channels_out/(1e3*t.compression_ratio),i.samplerate_index=I(t.out_samplerate,t),t.free_format||(t.brate=L(t.brate,t.version,t.out_samplerate))),t.out_samplerate!=0&&(t.out_samplerate<16e3?(t.VBR_mean_bitrate_kbps=Math.max(t.VBR_mean_bitrate_kbps,8),t.VBR_mean_bitrate_kbps=Math.min(t.VBR_mean_bitrate_kbps,64)):t.out_samplerate<32e3?(t.VBR_mean_bitrate_kbps=Math.max(t.VBR_mean_bitrate_kbps,8),t.VBR_mean_bitrate_kbps=Math.min(t.VBR_mean_bitrate_kbps,160)):(t.VBR_mean_bitrate_kbps=Math.max(t.VBR_mean_bitrate_kbps,32),t.VBR_mean_bitrate_kbps=Math.min(t.VBR_mean_bitrate_kbps,320))),t.lowpassfreq==0){var a=16e3;switch(t.VBR){case n.vbr_off:var o=new A;z(o,t.brate),a=o.lowerlimit;break;case n.vbr_abr:var o=new A;z(o,t.VBR_mean_bitrate_kbps),a=o.lowerlimit;break;case n.vbr_rh:var l=[19500,19e3,18600,18e3,17500,16e3,15600,14900,12500,1e4,3950];if(0<=t.VBR_q&&t.VBR_q<=9){var u=l[t.VBR_q],g=l[t.VBR_q+1],v=t.VBR_q_frac;a=linear_int(u,g,v)}else a=19500;break;default:var l=[19500,19e3,18500,18e3,17500,16500,15500,14500,12500,9500,3950];if(0<=t.VBR_q&&t.VBR_q<=9){var u=l[t.VBR_q],g=l[t.VBR_q+1],v=t.VBR_q_frac;a=linear_int(u,g,v)}else a=19500}t.mode==e.MONO&&(t.VBR==n.vbr_off||t.VBR==n.vbr_abr)&&(a*=1.5),t.lowpassfreq=a|0}if(t.out_samplerate==0&&(2*t.lowpassfreq>t.in_samplerate&&(t.lowpassfreq=t.in_samplerate/2),t.out_samplerate=F(t.lowpassfreq|0,t.in_samplerate)),t.lowpassfreq=Math.min(20500,t.lowpassfreq),t.lowpassfreq=Math.min(t.out_samplerate/2,t.lowpassfreq),t.VBR==n.vbr_off&&(t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.brate)),t.VBR==n.vbr_abr&&(t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.VBR_mean_bitrate_kbps)),t.bWriteVbrTag||(t.findReplayGain=!1,t.decode_on_the_fly=!1,i.findPeakSample=!1),i.findReplayGain=t.findReplayGain,i.decode_on_the_fly=t.decode_on_the_fly,i.decode_on_the_fly&&(i.findPeakSample=!0),i.findReplayGain&&y.InitGainAnalysis(i.rgdata,t.out_samplerate)==GainAnalysis.INIT_GAIN_ANALYSIS_ERROR)return t.internal_flags=null,-6;switch(i.decode_on_the_fly&&!t.decode_only&&(i.hip!=null&&O.hip_decode_exit(i.hip),i.hip=O.hip_decode_init()),i.mode_gr=t.out_samplerate<=24e3?1:2,t.framesize=576*i.mode_gr,t.encoder_delay=_.ENCDELAY,i.resample_ratio=t.in_samplerate/t.out_samplerate,t.VBR){case n.vbr_mt:case n.vbr_rh:case n.vbr_mtrh:t.compression_ratio=[5.7,6.5,7.3,8.2,10,11.9,13,14,15,16.5][t.VBR_q];break;case n.vbr_abr:t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.VBR_mean_bitrate_kbps);break;default:t.compression_ratio=t.out_samplerate*16*i.channels_out/(1e3*t.brate);break}if(t.mode==e.NOT_SET&&(t.mode=e.JOINT_STEREO),t.highpassfreq>0?(i.highpass1=2*t.highpassfreq,t.highpasswidth>=0?i.highpass2=2*(t.highpassfreq+t.highpasswidth):i.highpass2=2*t.highpassfreq,i.highpass1/=t.out_samplerate,i.highpass2/=t.out_samplerate):(i.highpass1=0,i.highpass2=0),t.lowpassfreq>0?(i.lowpass2=2*t.lowpassfreq,t.lowpasswidth>=0?(i.lowpass1=2*(t.lowpassfreq-t.lowpasswidth),i.lowpass1<0&&(i.lowpass1=0)):i.lowpass1=2*t.lowpassfreq,i.lowpass1/=t.out_samplerate,i.lowpass2/=t.out_samplerate):(i.lowpass1=0,i.lowpass2=0),B(t),i.samplerate_index=I(t.out_samplerate,t),i.samplerate_index<0)return t.internal_flags=null,-1;if(t.VBR==n.vbr_off){if(t.free_format)i.bitrate_index=0;else if(t.brate=L(t.brate,t.version,t.out_samplerate),i.bitrate_index=R(t.brate,t.version,t.out_samplerate),i.bitrate_index<=0)return t.internal_flags=null,-1}else i.bitrate_index=1;t.analysis&&(t.bWriteVbrTag=!1),i.pinfo!=null&&(t.bWriteVbrTag=!1),b.init_bit_stream_w(i);for(var T=i.samplerate_index+3*t.version+6*(t.out_samplerate<16e3),E=0;E<_.SBMAX_l+1;E++)i.scalefac_band.l[E]=S.sfBandIndex[T].l[E];for(var E=0;E<_.PSFB21+1;E++){var D=(i.scalefac_band.l[22]-i.scalefac_band.l[21])/_.PSFB21,j=i.scalefac_band.l[21]+E*D;i.scalefac_band.psfb21[E]=j}i.scalefac_band.psfb21[_.PSFB21]=576;for(var E=0;E<_.SBMAX_s+1;E++)i.scalefac_band.s[E]=S.sfBandIndex[T].s[E];for(var E=0;E<_.PSFB12+1;E++){var D=(i.scalefac_band.s[13]-i.scalefac_band.s[12])/_.PSFB12,j=i.scalefac_band.s[12]+E*D;i.scalefac_band.psfb12[E]=j}i.scalefac_band.psfb12[_.PSFB12]=192,t.version==1?i.sideinfo_len=i.channels_out==1?21:36:i.sideinfo_len=i.channels_out==1?13:21,t.error_protection&&(i.sideinfo_len+=2),ee(t),i.Class_ID=M;var N;for(N=0;N<19;N++)i.nsPsy.pefirbuf[N]=700*i.mode_gr*i.channels_out;switch(t.ATHtype==-1&&(t.ATHtype=4),s(t.VBR_q<=9),s(t.VBR_q>=0),t.VBR){case n.vbr_mt:t.VBR=n.vbr_mtrh;case n.vbr_mtrh:t.useTemporal??=!1,x.apply_preset(t,500-t.VBR_q*10,0),t.quality<0&&(t.quality=LAME_DEFAULT_QUALITY),t.quality<5&&(t.quality=0),t.quality>5&&(t.quality=5),i.PSY.mask_adjust=t.maskingadjust,i.PSY.mask_adjust_short=t.maskingadjust_short,t.experimentalY?i.sfb21_extra=!1:i.sfb21_extra=t.out_samplerate>44e3,i.iteration_loop=new VBRNewIterationLoop(C);break;case n.vbr_rh:x.apply_preset(t,500-t.VBR_q*10,0),i.PSY.mask_adjust=t.maskingadjust,i.PSY.mask_adjust_short=t.maskingadjust_short,t.experimentalY?i.sfb21_extra=!1:i.sfb21_extra=t.out_samplerate>44e3,t.quality>6&&(t.quality=6),t.quality<0&&(t.quality=LAME_DEFAULT_QUALITY),i.iteration_loop=new VBROldIterationLoop(C);break;default:var P;i.sfb21_extra=!1,t.quality<0&&(t.quality=LAME_DEFAULT_QUALITY),P=t.VBR,P==n.vbr_off&&(t.VBR_mean_bitrate_kbps=t.brate),x.apply_preset(t,t.VBR_mean_bitrate_kbps,0),t.VBR=P,i.PSY.mask_adjust=t.maskingadjust,i.PSY.mask_adjust_short=t.maskingadjust_short,P==n.vbr_off?i.iteration_loop=new p(C):i.iteration_loop=new ABRIterationLoop(C);break}if(s(t.scale>=0),t.VBR!=n.vbr_off){if(i.VBR_min_bitrate=1,i.VBR_max_bitrate=14,t.out_samplerate<16e3&&(i.VBR_max_bitrate=8),t.VBR_min_bitrate_kbps!=0&&(t.VBR_min_bitrate_kbps=L(t.VBR_min_bitrate_kbps,t.version,t.out_samplerate),i.VBR_min_bitrate=R(t.VBR_min_bitrate_kbps,t.version,t.out_samplerate),i.VBR_min_bitrate<0)||t.VBR_max_bitrate_kbps!=0&&(t.VBR_max_bitrate_kbps=L(t.VBR_max_bitrate_kbps,t.version,t.out_samplerate),i.VBR_max_bitrate=R(t.VBR_max_bitrate_kbps,t.version,t.out_samplerate),i.VBR_max_bitrate<0))return-1;t.VBR_min_bitrate_kbps=h.bitrate_table[t.version][i.VBR_min_bitrate],t.VBR_max_bitrate_kbps=h.bitrate_table[t.version][i.VBR_max_bitrate],t.VBR_mean_bitrate_kbps=Math.min(h.bitrate_table[t.version][i.VBR_max_bitrate],t.VBR_mean_bitrate_kbps),t.VBR_mean_bitrate_kbps=Math.max(h.bitrate_table[t.version][i.VBR_min_bitrate],t.VBR_mean_bitrate_kbps)}return t.tune&&(i.PSY.mask_adjust+=t.tune_value_a,i.PSY.mask_adjust_short+=t.tune_value_a),V(t),s(t.scale>=0),t.athaa_type<0?i.ATH.useAdjust=3:i.ATH.useAdjust=t.athaa_type,i.ATH.aaSensitivityP=10**(t.athaa_sensitivity/-10),t.short_blocks??=r.short_block_allowed,t.short_blocks==r.short_block_allowed&&(t.mode==e.JOINT_STEREO||t.mode==e.STEREO)&&(t.short_blocks=r.short_block_coupled),t.quant_comp<0&&(t.quant_comp=1),t.quant_comp_short<0&&(t.quant_comp_short=0),t.msfix<0&&(t.msfix=0),t.exp_nspsytune|=1,t.internal_flags.nsPsy.attackthre<0&&(t.internal_flags.nsPsy.attackthre=c.NSATTACKTHRE),t.internal_flags.nsPsy.attackthre_s<0&&(t.internal_flags.nsPsy.attackthre_s=c.NSATTACKTHRE_S),s(t.scale>=0),t.scale<0&&(t.scale=1),t.ATHtype<0&&(t.ATHtype=4),t.ATHcurve<0&&(t.ATHcurve=4),t.athaa_loudapprox<0&&(t.athaa_loudapprox=2),t.interChRatio<0&&(t.interChRatio=0),t.useTemporal??=!0,i.slot_lag=i.frac_SpF=0,t.VBR==n.vbr_off&&(i.slot_lag=i.frac_SpF=(t.version+1)*72e3*t.brate%t.out_samplerate|0),S.iteration_init(t),w.psymodel_init(t),s(t.scale>=0),0};function H(e,t){(e.in_buffer_0==null||e.in_buffer_nsamples<t)&&(e.in_buffer_0=i(t),e.in_buffer_1=i(t),e.in_buffer_nsamples=t)}this.lame_encode_flush=function(e,t,n,r){var i=e.internal_flags,a=o([2,1152]),s=0,c,l,u,d,f=i.mf_samples_to_encode-_.POSTDELAY,p=U(e);if(i.mf_samples_to_encode<1)return 0;for(c=0,e.in_samplerate!=e.out_samplerate&&(f+=16*e.out_samplerate/e.in_samplerate),u=e.framesize-f%e.framesize,u<576&&(u+=e.framesize),e.encoder_padding=u,d=(f+u)/e.framesize;d>0&&s>=0;){var m=p-i.mf_size,h=e.frameNum;m*=e.in_samplerate,m/=e.out_samplerate,m>1152&&(m=1152),m<1&&(m=1),l=r-c,r==0&&(l=0),s=this.lame_encode_buffer(e,a[0],a[1],m,t,n,l),n+=s,c+=s,d-=h==e.frameNum?0:1}if(i.mf_samples_to_encode=0,s<0||(l=r-c,r==0&&(l=0),b.flush_bitstream(e),s=b.copy_buffer(i,t,n,l,1),s<0))return s;if(n+=s,c+=s,l=r-c,r==0&&(l=0),e.write_id3tag_automatic){if(E.id3tag_write_v1(e),s=b.copy_buffer(i,t,n,l,0),s<0)return s;c+=s}return c},this.lame_encode_buffer=function(e,t,n,r,i,a,o){var s=e.internal_flags,c=[null,null];if(s.Class_ID!=M)return-3;if(r==0)return 0;H(s,r),c[0]=s.in_buffer_0,c[1]=s.in_buffer_1;for(var l=0;l<r;l++)c[0][l]=t[l],s.channels_in>1&&(c[1][l]=n[l]);return te(e,c[0],c[1],r,i,a,o)};function U(e){var t=_.BLKSIZE+e.framesize-_.FFTOFFSET;return t=Math.max(t,512+e.framesize-32),t}function te(e,t,n,r,i,a,o){var c=e.internal_flags,l=0,d,f,p,h,g,v=[null,null],x=[null,null];if(c.Class_ID!=M)return-3;if(r==0)return 0;if(g=b.copy_buffer(c,i,a,o,0),g<0)return g;if(a+=g,l+=g,x[0]=t,x[1]=n,m.NEQ(e.scale,0)&&m.NEQ(e.scale,1))for(f=0;f<r;++f)x[0][f]*=e.scale,c.channels_out==2&&(x[1][f]*=e.scale);if(m.NEQ(e.scale_left,0)&&m.NEQ(e.scale_left,1))for(f=0;f<r;++f)x[0][f]*=e.scale_left;if(m.NEQ(e.scale_right,0)&&m.NEQ(e.scale_right,1))for(f=0;f<r;++f)x[1][f]*=e.scale_right;if(e.num_channels==2&&c.channels_out==1)for(f=0;f<r;++f)x[0][f]=.5*(x[0][f]+x[1][f]),x[1][f]=0;h=U(e),v[0]=c.mfbuf[0],v[1]=c.mfbuf[1];for(var S=0;r>0;){var C=[null,null],w=0,T=0;C[0]=x[0],C[1]=x[1];var E=new ne;if(oe(e,v,C,S,r,E),w=E.n_in,T=E.n_out,c.findReplayGain&&!c.decode_on_the_fly&&y.AnalyzeSamples(c.rgdata,v[0],c.mf_size,v[1],c.mf_size,T,c.channels_out)==GainAnalysis.GAIN_ANALYSIS_ERROR)return-6;if(r-=w,S+=w,c.channels_out,c.mf_size+=T,s(c.mf_size<=u.MFSIZE),c.mf_samples_to_encode<1&&(c.mf_samples_to_encode=_.ENCDELAY+_.POSTDELAY),c.mf_samples_to_encode+=T,c.mf_size>=h){var D=o-l;if(o==0&&(D=0),d=W(e,v[0],v[1],i,a,D),d<0)return d;for(a+=d,l+=d,c.mf_size-=e.framesize,c.mf_samples_to_encode-=e.framesize,p=0;p<c.channels_out;p++)for(f=0;f<c.mf_size;f++)v[p][f]=v[p][f+e.framesize]}}return l}function W(e,t,n,r,i,a){var o=g.enc.lame_encode_mp3_frame(e,t,n,r,i,a);return e.frameNum++,o}function ne(){this.n_in=0,this.n_out=0}function G(){this.num_used=0}function re(e,t){return t==0?e:re(t,e%t)}function ie(e,t,n){var r=Math.PI*t;e/=n,e<0&&(e=0),e>1&&(e=1);var i=e-.5,a=.42-.5*Math.cos(2*e*Math.PI)+.08*Math.cos(4*e*Math.PI);return Math.abs(i)<1e-9?r/Math.PI:a*Math.sin(n*r*i)/(Math.PI*n*i)}function ae(e,t,n,r,a,o,c,l,d){var f=e.internal_flags,p,m=0,h,g=e.out_samplerate/re(e.out_samplerate,e.in_samplerate);g>u.BPC&&(g=u.BPC);var _=+(Math.abs(f.resample_ratio-Math.floor(.5+f.resample_ratio))<1e-4),v=1/f.resample_ratio;v>1&&(v=1);var y=31;y%2==0&&--y,y+=_;var b=y+1;if(f.fill_buffer_resample_init==0){for(f.inbuf_old[0]=i(b),f.inbuf_old[1]=i(b),p=0;p<=2*g;++p)f.blackfilt[p]=i(b);for(f.itime[0]=0,f.itime[1]=0,m=0;m<=2*g;m++){var x=0,S=(m-g)/(2*g);for(p=0;p<=y;p++)x+=f.blackfilt[m][p]=ie(p-S,v,y);for(p=0;p<=y;p++)f.blackfilt[m][p]/=x}f.fill_buffer_resample_init=1}var C=f.inbuf_old[d];for(h=0;h<r;h++){var w,T;if(w=h*f.resample_ratio,m=0|Math.floor(w-f.itime[d]),y+m-y/2>=c)break;var S=w-f.itime[d]-(m+y%2*.5);T=0|Math.floor(S*2*g+g+.5);var E=0;for(p=0;p<=y;++p){var D=0|p+m-y/2,O=D<0?C[b+D]:a[o+D];E+=O*f.blackfilt[T][p]}t[n+h]=E}if(l.num_used=Math.min(c,y+m-y/2),f.itime[d]+=l.num_used-h*f.resample_ratio,l.num_used>=b)for(p=0;p<b;p++)C[p]=a[o+l.num_used+p-b];else{var k=b-l.num_used;for(p=0;p<k;++p)C[p]=C[p+l.num_used];for(m=0;p<b;++p,++m)C[p]=a[o+m];s(m==l.num_used)}return h}function oe(e,t,n,r,i,a){var o=e.internal_flags;if(o.resample_ratio<.9999||o.resample_ratio>1.0001)for(var s=0;s<o.channels_out;s++){var c=new G;a.n_out=ae(e,t[s],o.mf_size,e.framesize,n[s],r,i,c,s),a.n_in=c.num_used}else{a.n_out=Math.min(e.framesize,i),a.n_in=a.n_out;for(var l=0;l<a.n_out;++l)t[0][o.mf_size+l]=n[0][r+l],o.channels_out==2&&(t[1][o.mf_size+l]=n[1][r+l])}}}return At=v,At}var Nt=g.VbrMode;function Pt(){var e=Mt();function t(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){this.vbr_q=e,this.quant_comp=t,this.quant_comp_s=n,this.expY=r,this.st_lrm=i,this.st_s=a,this.masking_adj=o,this.masking_adj_short=s,this.ath_lower=c,this.ath_curve=l,this.ath_sensitivity=u,this.interch=d,this.safejoint=f,this.sfb21mod=p,this.msfix=m}function n(e,t,n,r,i,a,o,s,c,l,u,d,f,p){this.quant_comp=t,this.quant_comp_s=n,this.safejoint=r,this.nsmsfix=i,this.st_lrm=a,this.st_s=o,this.nsbass=s,this.scale=c,this.masking_adj=l,this.ath_lower=u,this.ath_curve=d,this.interch=f,this.sfscale=p}var r;this.setModules=function(e){r=e};var i=[new t(0,9,9,0,5.2,125,-4.2,-6.3,4.8,1,0,0,2,21,.97),new t(1,9,9,0,5.3,125,-3.6,-5.6,4.5,1.5,0,0,2,21,1.35),new t(2,9,9,0,5.6,125,-2.2,-3.5,2.8,2,0,0,2,21,1.49),new t(3,9,9,1,5.8,130,-1.8,-2.8,2.6,3,-4,0,2,20,1.64),new t(4,9,9,1,6,135,-.7,-1.1,1.1,3.5,-8,0,2,0,1.79),new t(5,9,9,1,6.4,140,.5,.4,-7.5,4,-12,2e-4,0,0,1.95),new t(6,9,9,1,6.6,145,.67,.65,-14.7,6.5,-19,4e-4,0,0,2.3),new t(7,9,9,1,6.6,145,.8,.75,-19.7,8,-22,6e-4,0,0,2.7),new t(8,9,9,1,6.6,145,1.2,1.15,-27.5,10,-23,7e-4,0,0,0),new t(9,9,9,1,6.6,145,1.6,1.6,-36,11,-25,8e-4,0,0,0),new t(10,9,9,1,6.6,145,2,2,-36,12,-25,8e-4,0,0,0)],a=[new t(0,9,9,0,4.2,25,-7,-4,7.5,1,0,0,2,26,.97),new t(1,9,9,0,4.2,25,-5.6,-3.6,4.5,1.5,0,0,2,21,1.35),new t(2,9,9,0,4.2,25,-4.4,-1.8,2,2,0,0,2,18,1.49),new t(3,9,9,1,4.2,25,-3.4,-1.25,1.1,3,-4,0,2,15,1.64),new t(4,9,9,1,4.2,25,-2.2,.1,0,3.5,-8,0,2,0,1.79),new t(5,9,9,1,4.2,25,-1,1.65,-7.7,4,-12,2e-4,0,0,1.95),new t(6,9,9,1,4.2,25,-0,2.47,-7.7,6.5,-19,4e-4,0,0,2),new t(7,9,9,1,4.2,25,.5,2,-14.5,8,-22,6e-4,0,0,2),new t(8,9,9,1,4.2,25,1,2.4,-22,10,-23,7e-4,0,0,2),new t(9,9,9,1,4.2,25,1.5,2.95,-30,11,-25,8e-4,0,0,2),new t(10,9,9,1,4.2,25,2,2.95,-36,12,-30,8e-4,0,0,2)];function o(e,t,n){var r=e.VBR==Nt.vbr_rh?i:a,o=e.VBR_q_frac,s=r[t],c=r[t+1],u=s;s.st_lrm+=o*(c.st_lrm-s.st_lrm),s.st_s+=o*(c.st_s-s.st_s),s.masking_adj+=o*(c.masking_adj-s.masking_adj),s.masking_adj_short+=o*(c.masking_adj_short-s.masking_adj_short),s.ath_lower+=o*(c.ath_lower-s.ath_lower),s.ath_curve+=o*(c.ath_curve-s.ath_curve),s.ath_sensitivity+=o*(c.ath_sensitivity-s.ath_sensitivity),s.interch+=o*(c.interch-s.interch),s.msfix+=o*(c.msfix-s.msfix),l(e,u.vbr_q),n==0&&Math.abs(e.quant_comp- -1)>0||(e.quant_comp=u.quant_comp),n==0&&Math.abs(e.quant_comp_short- -1)>0||(e.quant_comp_short=u.quant_comp_s),u.expY!=0&&(e.experimentalY=u.expY!=0),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre- -1)>0||(e.internal_flags.nsPsy.attackthre=u.st_lrm),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre_s- -1)>0||(e.internal_flags.nsPsy.attackthre_s=u.st_s),n==0&&Math.abs(e.maskingadjust-0)>0||(e.maskingadjust=u.masking_adj),n==0&&Math.abs(e.maskingadjust_short-0)>0||(e.maskingadjust_short=u.masking_adj_short),n==0&&Math.abs(-e.ATHlower*10-0)>0||(e.ATHlower=-u.ath_lower/10),n==0&&Math.abs(e.ATHcurve- -1)>0||(e.ATHcurve=u.ath_curve),n==0&&Math.abs(e.athaa_sensitivity- -1)>0||(e.athaa_sensitivity=u.ath_sensitivity),u.interch>0&&(n==0&&Math.abs(e.interChRatio- -1)>0||(e.interChRatio=u.interch)),u.safejoint>0&&(e.exp_nspsytune|=u.safejoint),u.sfb21mod>0&&(e.exp_nspsytune|=u.sfb21mod<<20),n==0&&Math.abs(e.msfix- -1)>0||(e.msfix=u.msfix),n==0&&(e.VBR_q=t,e.VBR_q_frac=o)}var s=[new n(8,9,9,0,0,6.6,145,0,.95,0,-30,11,.0012,1),new n(16,9,9,0,0,6.6,145,0,.95,0,-25,11,.001,1),new n(24,9,9,0,0,6.6,145,0,.95,0,-20,11,.001,1),new n(32,9,9,0,0,6.6,145,0,.95,0,-15,11,.001,1),new n(40,9,9,0,0,6.6,145,0,.95,0,-10,11,9e-4,1),new n(48,9,9,0,0,6.6,145,0,.95,0,-10,11,9e-4,1),new n(56,9,9,0,0,6.6,145,0,.95,0,-6,11,8e-4,1),new n(64,9,9,0,0,6.6,145,0,.95,0,-2,11,8e-4,1),new n(80,9,9,0,0,6.6,145,0,.95,0,0,8,7e-4,1),new n(96,9,9,0,2.5,6.6,145,0,.95,0,1,5.5,6e-4,1),new n(112,9,9,0,2.25,6.6,145,0,.95,0,2,4.5,5e-4,1),new n(128,9,9,0,1.95,6.4,140,0,.95,0,3,4,2e-4,1),new n(160,9,9,1,1.79,6,135,0,.95,-2,5,3.5,0,1),new n(192,9,9,1,1.49,5.6,125,0,.97,-4,7,3,0,0),new n(224,9,9,1,1.25,5.2,125,0,.98,-6,9,2,0,0),new n(256,9,9,1,.97,5.2,125,0,1,-8,10,1,0,0),new n(320,9,9,1,.9,5.2,125,0,1,-10,12,0,0,0)];function c(e,t,n){var i=t,a=r.nearestBitrateFullIndex(t);if(e.VBR=Nt.vbr_abr,e.VBR_mean_bitrate_kbps=i,e.VBR_mean_bitrate_kbps=Math.min(e.VBR_mean_bitrate_kbps,320),e.VBR_mean_bitrate_kbps=Math.max(e.VBR_mean_bitrate_kbps,8),e.brate=e.VBR_mean_bitrate_kbps,e.VBR_mean_bitrate_kbps>320&&(e.disable_reservoir=!0),s[a].safejoint>0&&(e.exp_nspsytune|=2),s[a].sfscale>0&&(e.internal_flags.noise_shaping=2),Math.abs(s[a].nsbass)>0){var o=int(s[a].nsbass*4);o<0&&(o+=64),e.exp_nspsytune|=o<<2}return n==0&&Math.abs(e.quant_comp- -1)>0||(e.quant_comp=s[a].quant_comp),n==0&&Math.abs(e.quant_comp_short- -1)>0||(e.quant_comp_short=s[a].quant_comp_s),n==0&&Math.abs(e.msfix- -1)>0||(e.msfix=s[a].nsmsfix),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre- -1)>0||(e.internal_flags.nsPsy.attackthre=s[a].st_lrm),n==0&&Math.abs(e.internal_flags.nsPsy.attackthre_s- -1)>0||(e.internal_flags.nsPsy.attackthre_s=s[a].st_s),n==0&&Math.abs(e.scale- -1)>0||(e.scale=s[a].scale),n==0&&Math.abs(e.maskingadjust-0)>0||(e.maskingadjust=s[a].masking_adj),s[a].masking_adj>0?n==0&&Math.abs(e.maskingadjust_short-0)>0||(e.maskingadjust_short=s[a].masking_adj*.9):n==0&&Math.abs(e.maskingadjust_short-0)>0||(e.maskingadjust_short=s[a].masking_adj*1.1),n==0&&Math.abs(-e.ATHlower*10-0)>0||(e.ATHlower=-s[a].ath_lower/10),n==0&&Math.abs(e.ATHcurve- -1)>0||(e.ATHcurve=s[a].ath_curve),n==0&&Math.abs(e.interChRatio- -1)>0||(e.interChRatio=s[a].interch),t}this.apply_preset=function(t,n,r){switch(n){case e.R3MIX:n=e.V3,t.VBR=Nt.vbr_mtrh;break;case e.MEDIUM:n=e.V4,t.VBR=Nt.vbr_rh;break;case e.MEDIUM_FAST:n=e.V4,t.VBR=Nt.vbr_mtrh;break;case e.STANDARD:n=e.V2,t.VBR=Nt.vbr_rh;break;case e.STANDARD_FAST:n=e.V2,t.VBR=Nt.vbr_mtrh;break;case e.EXTREME:n=e.V0,t.VBR=Nt.vbr_rh;break;case e.EXTREME_FAST:n=e.V0,t.VBR=Nt.vbr_mtrh;break;case e.INSANE:return n=320,t.preset=n,c(t,n,r),t.VBR=Nt.vbr_off,n}switch(t.preset=n,n){case e.V9:return o(t,9,r),n;case e.V8:return o(t,8,r),n;case e.V7:return o(t,7,r),n;case e.V6:return o(t,6,r),n;case e.V5:return o(t,5,r),n;case e.V4:return o(t,4,r),n;case e.V3:return o(t,3,r),n;case e.V2:return o(t,2,r),n;case e.V1:return o(t,1,r),n;case e.V0:return o(t,0,r),n}return 8<=n&&n<=320?c(t,n,r):(t.preset=0,n)};function l(e,t){var n=0;return 0>t&&(n=-1,t=0),9<t&&(n=-1,t=9),e.VBR_q=t,e.VBR_q_frac=0,n}}var Ft=Pt;function It(){this.setModules=function(e,t){}}var Lt=It;function Rt(){this.over_noise=0,this.tot_noise=0,this.max_noise=0,this.over_count=0,this.over_SSD=0,this.bits=0}var zt=Rt,Bt=g,Vt=Bt.new_float,Ht=Bt.new_int;function Ut(){this.global_gain=0,this.sfb_count1=0,this.step=Ht(39),this.noise=Vt(39),this.noise_log=Vt(39)}var Wt=Ut,Gt=g,Kt=Gt.System,qt=Gt.VbrMode,Jt=Gt.Util,Yt=Gt.Arrays,Xt=Gt.new_float,Zt=Gt.assert,Qt=Lt,$t=zt,en=Wt,$=A(),tn=ge,nn=ue;function rn(){var e;this.rv=null;var t;this.qupvt=null;var n,r=new Qt,i;this.setModules=function(a,o,s,c){e=a,t=o,this.rv=o,n=s,this.qupvt=s,i=c,r.setModules(n,i)},this.ms_convert=function(e,t){for(var n=0;n<576;++n){var r=e.tt[t][0].xr[n],i=e.tt[t][1].xr[n];e.tt[t][0].xr[n]=(r+i)*(Jt.SQRT2*.5),e.tt[t][1].xr[n]=(r-i)*(Jt.SQRT2*.5)}};function a(e,t,n,r){r=0;for(var i=0;i<=n;++i){var a=Math.abs(e.xr[i]);r+=a,t[i]=Math.sqrt(a*Math.sqrt(a)),t[i]>e.xrpow_max&&(e.xrpow_max=t[i])}return r}this.init_xrpow=function(e,t,n){var r=0,i=0|t.max_nonzero_coeff;if(t.xrpow_max=0,Yt.fill(n,i,576,0),r=a(t,n,i,r),r>1e-20){var o=0;e.substep_shaping&2&&(o=1);for(var s=0;s<t.psymax;s++)e.pseudohalf[s]=o;return!0}return Yt.fill(t.l3_enc,0,576,0),!1};function o(e,t){var r=e.ATH,i=t.xr;if(t.block_type!=$.SHORT_TYPE)for(var a=!1,o=$.PSFB21-1;o>=0&&!a;o--){var s=e.scalefac_band.psfb21[o],c=e.scalefac_band.psfb21[o+1],l=n.athAdjust(r.adjust,r.psfb21[o],r.floor);e.nsPsy.longfact[21]>1e-12&&(l*=e.nsPsy.longfact[21]);for(var u=c-1;u>=s;u--)if(Math.abs(i[u])<l)i[u]=0;else{a=!0;break}}else for(var d=0;d<3;d++)for(var a=!1,o=$.PSFB12-1;o>=0&&!a;o--){var s=e.scalefac_band.s[12]*3+(e.scalefac_band.s[13]-e.scalefac_band.s[12])*d+(e.scalefac_band.psfb12[o]-e.scalefac_band.psfb12[0]),c=s+(e.scalefac_band.psfb12[o+1]-e.scalefac_band.psfb12[o]),f=n.athAdjust(r.adjust,r.psfb12[o],r.floor);e.nsPsy.shortfact[12]>1e-12&&(f*=e.nsPsy.shortfact[12]);for(var u=c-1;u>=s;u--)if(Math.abs(i[u])<f)i[u]=0;else{a=!0;break}}}this.init_outer_loop=function(e,t){t.part2_3_length=0,t.big_values=0,t.count1=0,t.global_gain=210,t.scalefac_compress=0,t.table_select[0]=0,t.table_select[1]=0,t.table_select[2]=0,t.subblock_gain[0]=0,t.subblock_gain[1]=0,t.subblock_gain[2]=0,t.subblock_gain[3]=0,t.region0_count=0,t.region1_count=0,t.preflag=0,t.scalefac_scale=0,t.count1table_select=0,t.part2_length=0,t.sfb_lmax=$.SBPSY_l,t.sfb_smin=$.SBPSY_s,t.psy_lmax=e.sfb21_extra?$.SBMAX_l:$.SBPSY_l,t.psymax=t.psy_lmax,t.sfbmax=t.sfb_lmax,t.sfbdivide=11;for(var r=0;r<$.SBMAX_l;r++)t.width[r]=e.scalefac_band.l[r+1]-e.scalefac_band.l[r],t.window[r]=3;if(t.block_type==$.SHORT_TYPE){var i=Xt(576);t.sfb_smin=0,t.sfb_lmax=0,t.mixed_block_flag!=0&&(t.sfb_smin=3,t.sfb_lmax=e.mode_gr*2+4),t.psymax=t.sfb_lmax+3*((e.sfb21_extra?$.SBMAX_s:$.SBPSY_s)-t.sfb_smin),t.sfbmax=t.sfb_lmax+3*($.SBPSY_s-t.sfb_smin),t.sfbdivide=t.sfbmax-18,t.psy_lmax=t.sfb_lmax;var a=e.scalefac_band.l[t.sfb_lmax];Kt.arraycopy(t.xr,0,i,0,576);for(var r=t.sfb_smin;r<$.SBMAX_s;r++)for(var s=e.scalefac_band.s[r],c=e.scalefac_band.s[r+1],l=0;l<3;l++)for(var u=s;u<c;u++)t.xr[a++]=i[3*u+l];for(var d=t.sfb_lmax,r=t.sfb_smin;r<$.SBMAX_s;r++)t.width[d]=t.width[d+1]=t.width[d+2]=e.scalefac_band.s[r+1]-e.scalefac_band.s[r],t.window[d]=0,t.window[d+1]=1,t.window[d+2]=2,d+=3}t.count1bits=0,t.sfb_partition_table=n.nr_of_sfb_block[0][0],t.slen[0]=0,t.slen[1]=0,t.slen[2]=0,t.slen[3]=0,t.max_nonzero_coeff=575,Yt.fill(t.scalefac,0),o(e,t)};function s(e){this.ordinal=e}s.BINSEARCH_NONE=new s(0),s.BINSEARCH_UP=new s(1),s.BINSEARCH_DOWN=new s(2);function c(e,t,n,r,a){var o,c=e.CurrentStep[r],l=!1,u=e.OldValue[r],d=s.BINSEARCH_NONE;for(t.global_gain=u,n-=t.part2_length;;){var f;if(o=i.count_bits(e,a,t,null),c==1||o==n)break;o>n?(d==s.BINSEARCH_DOWN&&(l=!0),l&&(c/=2),d=s.BINSEARCH_UP,f=c):(d==s.BINSEARCH_UP&&(l=!0),l&&(c/=2),d=s.BINSEARCH_DOWN,f=-c),t.global_gain+=f,t.global_gain<0&&(t.global_gain=0,l=!0),t.global_gain>255&&(t.global_gain=255,l=!0)}for(Zt(t.global_gain>=0),Zt(t.global_gain<256);o>n&&t.global_gain<255;)t.global_gain++,o=i.count_bits(e,a,t,null);return e.CurrentStep[r]=u-t.global_gain>=4?4:2,e.OldValue[r]=t.global_gain,t.part2_3_length=o,o}this.trancate_smallspectrums=function(e,t,r,a){var o=Xt(nn.SFBMAX);if(!(!(e.substep_shaping&4)&&t.block_type==$.SHORT_TYPE||e.substep_shaping&128)){n.calc_noise(t,r,o,new $t,null);for(var s=0;s<576;s++){var c=0;t.l3_enc[s]!=0&&(c=Math.abs(t.xr[s])),a[s]=c}var s=0,l=8;t.block_type==$.SHORT_TYPE&&(l=6);do{var u,d,f,p,m=t.width[l];if(s+=m,!(o[l]>=1)&&(Yt.sort(a,s-m,m),!BitStream.EQ(a[s-1],0))){u=(1-o[l])*r[l],d=0,p=0;do{var h;for(f=1;p+f<m&&!BitStream.NEQ(a[p+s-m],a[p+s+f-m]);f++);if(h=a[p+s-m]*a[p+s-m]*f,u<h){p!=0&&(d=a[p+s-m-1]);break}u-=h,p+=f}while(p<m);if(!BitStream.EQ(d,0))do Math.abs(t.xr[s-m])<=d&&(t.l3_enc[s-m]=0);while(--m>0)}}while(++l<t.psymax);t.part2_3_length=i.noquant_count_bits(e,t,null)}};function l(e){for(var t=0;t<e.sfbmax;t++)if(e.scalefac[t]+e.subblock_gain[e.window[t]]==0)return!1;return!0}function u(e){return Jt.FAST_LOG10(.368+.632*e*e*e)}function d(e,t){for(var n=1e-37,r=0;r<t.psymax;r++)n+=u(e[r]);return Math.max(1e-20,n)}function f(e,t,n,r,i){var a;switch(e){default:case 9:t.over_count>0?(a=n.over_SSD<=t.over_SSD,n.over_SSD==t.over_SSD&&(a=n.bits<t.bits)):a=n.max_noise<0&&n.max_noise*10+n.bits<=t.max_noise*10+t.bits;break;case 0:a=n.over_count<t.over_count||n.over_count==t.over_count&&n.over_noise<t.over_noise||n.over_count==t.over_count&&BitStream.EQ(n.over_noise,t.over_noise)&&n.tot_noise<t.tot_noise;break;case 8:n.max_noise=d(i,r);case 1:a=n.max_noise<t.max_noise;break;case 2:a=n.tot_noise<t.tot_noise;break;case 3:a=n.tot_noise<t.tot_noise&&n.max_noise<t.max_noise;break;case 4:a=n.max_noise<=0&&t.max_noise>.2||n.max_noise<=0&&t.max_noise<0&&t.max_noise>n.max_noise-.2&&n.tot_noise<t.tot_noise||n.max_noise<=0&&t.max_noise>0&&t.max_noise>n.max_noise-.2&&n.tot_noise<t.tot_noise+t.over_noise||n.max_noise>0&&t.max_noise>-.05&&t.max_noise>n.max_noise-.1&&n.tot_noise+n.over_noise<t.tot_noise+t.over_noise||n.max_noise>0&&t.max_noise>-.1&&t.max_noise>n.max_noise-.15&&n.tot_noise+n.over_noise+n.over_noise<t.tot_noise+t.over_noise+t.over_noise;break;case 5:a=n.over_noise<t.over_noise||BitStream.EQ(n.over_noise,t.over_noise)&&n.tot_noise<t.tot_noise;break;case 6:a=n.over_noise<t.over_noise||BitStream.EQ(n.over_noise,t.over_noise)&&(n.max_noise<t.max_noise||BitStream.EQ(n.max_noise,t.max_noise)&&n.tot_noise<=t.tot_noise);break;case 7:a=n.over_count<t.over_count||n.over_noise<t.over_noise;break}return t.over_count==0&&(a&&=n.bits<t.bits),a}function p(e,t,n,r,i){for(var a=e.internal_flags,o=t.scalefac_scale==0?1.2968395546510096:1.6817928305074292,s=0,c=0;c<t.sfbmax;c++)s<n[c]&&(s=n[c]);var l=a.noise_shaping_amp;switch(l==3&&(l=i?2:1),l){case 2:break;case 1:s>1?s**=.5:s*=.95;break;default:s>1?s=1:s*=.95;break}for(var u=0,c=0;c<t.sfbmax;c++){var d=t.width[c],f;if(u+=d,!(n[c]<s)){if(a.substep_shaping&2&&(a.pseudohalf[c]=+(a.pseudohalf[c]==0),a.pseudohalf[c]==0&&a.noise_shaping_amp==2))return;for(t.scalefac[c]++,f=-d;f<0;f++)r[u+f]*=o,r[u+f]>t.xrpow_max&&(t.xrpow_max=r[u+f]);if(a.noise_shaping_amp==2)return}}}function m(e,t){for(var r=1.2968395546510096,i=0,a=0;a<e.sfbmax;a++){var o=e.width[a],s=e.scalefac[a];if(e.preflag!=0&&(s+=n.pretab[a]),i+=o,s&1){s++;for(var c=-o;c<0;c++)t[i+c]*=r,t[i+c]>e.xrpow_max&&(e.xrpow_max=t[i+c])}e.scalefac[a]=s>>1}e.preflag=0,e.scalefac_scale=1}function h(e,t,r){var i,a=t.scalefac;for(i=0;i<t.sfb_lmax;i++)if(a[i]>=16)return!0;for(var o=0;o<3;o++){var s=0,c=0;for(i=t.sfb_lmax+o;i<t.sfbdivide;i+=3)s<a[i]&&(s=a[i]);for(;i<t.sfbmax;i+=3)c<a[i]&&(c=a[i]);if(!(s<16&&c<8)){if(t.subblock_gain[o]>=7)return!0;t.subblock_gain[o]++;var l=e.scalefac_band.l[t.sfb_lmax];for(i=t.sfb_lmax+o;i<t.sfbmax;i+=3){var u,d=t.width[i],f=a[i];if(f-=4>>t.scalefac_scale,f>=0){a[i]=f,l+=d*3;continue}a[i]=0;var p=210+(f<<t.scalefac_scale+1);u=n.IPOW20(p),l+=d*(o+1);for(var m=-d;m<0;m++)r[l+m]*=u,r[l+m]>t.xrpow_max&&(t.xrpow_max=r[l+m]);l+=d*(3-o-1)}var u=n.IPOW20(202);l+=t.width[i]*(o+1);for(var m=-t.width[i];m<0;m++)r[l+m]*=u,r[l+m]>t.xrpow_max&&(t.xrpow_max=r[l+m])}}return!1}function g(e,t,n,r,a){var o=e.internal_flags;p(e,t,n,r,a);var s=l(t);return s?!1:(s=o.mode_gr==2?i.scale_bitcount(t):i.scale_bitcount_lsf(o,t),s?(o.noise_shaping>1&&(Yt.fill(o.pseudohalf,0),t.scalefac_scale==0?(m(t,r),s=!1):t.block_type==$.SHORT_TYPE&&o.subblock_gain>0&&(s=h(o,t,r)||l(t))),s||=o.mode_gr==2?i.scale_bitcount(t):i.scale_bitcount_lsf(o,t),!s):!0)}this.outer_loop=function(e,t,r,a,o,s){var l=e.internal_flags,u=new tn,d=Xt(576),p=Xt(nn.SFBMAX),m=new $t,h,_=new en,v=9999999,y=!1,b=!1,x=0;if(c(l,t,s,o,a),l.noise_shaping==0)return 100;n.calc_noise(t,r,p,m,_),m.bits=t.part2_3_length,u.assign(t);var S=0;for(Kt.arraycopy(a,0,d,0,576);!y;){do{var C=new $t,w,T=255;if(w=l.substep_shaping&2?20:3,l.sfb21_extra&&(p[u.sfbmax]>1||u.block_type==$.SHORT_TYPE&&(p[u.sfbmax+1]>1||p[u.sfbmax+2]>1))||!g(e,u,p,a,b))break;u.scalefac_scale!=0&&(T=254);var E=s-u.part2_length;if(E<=0)break;for(;(u.part2_3_length=i.count_bits(l,a,u,_))>E&&u.global_gain<=T;)u.global_gain++;if(u.global_gain>T)break;if(m.over_count==0){for(;(u.part2_3_length=i.count_bits(l,a,u,_))>v&&u.global_gain<=T;)u.global_gain++;if(u.global_gain>T)break}if(n.calc_noise(u,r,p,C,_),C.bits=u.part2_3_length,h=t.block_type==$.SHORT_TYPE?e.quant_comp_short:e.quant_comp,h=+!!f(h,m,C,u,p),h!=0)v=t.part2_3_length,m=C,t.assign(u),S=0,Kt.arraycopy(a,0,d,0,576);else if(l.full_outer_loop==0&&(++S>w&&m.over_count==0||l.noise_shaping_amp==3&&b&&S>30||l.noise_shaping_amp==3&&b&&u.global_gain-x>15))break}while(u.global_gain+u.scalefac_scale<255);l.noise_shaping_amp==3?b?y=!0:(u.assign(t),Kt.arraycopy(d,0,a,0,576),S=0,x=u.global_gain,b=!0):y=!0}return Zt(t.global_gain+t.scalefac_scale<=255),e.VBR==qt.vbr_rh||e.VBR==qt.vbr_mtrh?Kt.arraycopy(d,0,a,0,576):l.substep_shaping&1&&trancate_smallspectrums(l,t,r,a),m.over_count},this.iteration_finish_one=function(e,n,r){var a=e.l3_side,o=a.tt[n][r];i.best_scalefac_store(e,n,r,a),e.use_best_huffman==1&&i.best_huffman_divide(e,o),t.ResvAdjust(e,o)},this.VBR_encode_granule=function(e,t,n,r,i,a,o){var s=e.internal_flags,c=new tn,l=Xt(576),u=o,d=o+1,f=(o+a)/2,p,m,h=0,g=s.sfb21_extra;Zt(u<=LameInternalFlags.MAX_BITS_PER_CHANNEL),Yt.fill(c.l3_enc,0);do f>u-42?s.sfb21_extra=!1:s.sfb21_extra=g,m=outer_loop(e,t,n,r,i,f),m<=0?(h=1,d=t.part2_3_length,c.assign(t),Kt.arraycopy(r,0,l,0,576),o=d-32,p=o-a,f=(o+a)/2):(a=f+32,p=o-a,f=(o+a)/2,h!=0&&(h=2,t.assign(c),Kt.arraycopy(l,0,r,0,576)));while(p>12);s.sfb21_extra=g,h==2&&Kt.arraycopy(c.l3_enc,0,t.l3_enc,0,576),Zt(t.part2_3_length<=u)},this.get_framebits=function(n,r){var i=n.internal_flags;i.bitrate_index=i.VBR_min_bitrate;var a=e.getframebits(n);i.bitrate_index=1,a=e.getframebits(n);for(var o=1;o<=i.VBR_max_bitrate;o++){i.bitrate_index=o;var s=new MeanBits(a);r[o]=t.ResvFrameBegin(n,s),a=s.bits}},this.VBR_old_prepare=function(e,r,i,a,o,s,c,l,u){var d=e.internal_flags,f,p=0,m=1,h=0;d.bitrate_index=d.VBR_max_bitrate;var g=t.ResvFrameBegin(e,new MeanBits(0))/d.mode_gr;get_framebits(e,s);for(var _=0;_<d.mode_gr;_++){var v=n.on_pe(e,r,l[_],g,_,0);d.mode_ext==$.MPG_MD_MS_LR&&(ms_convert(d.l3_side,_),n.reduce_side(l[_],i[_],g,v));for(var y=0;y<d.channels_out;++y){var b=d.l3_side.tt[_][y];b.block_type==$.SHORT_TYPE?(p=2.56/(1+Math.exp(3.5-r[_][y]/300))-.14,f=d.PSY.mask_adjust_short-p):(p=1.28/(1+Math.exp(3.5-r[_][y]/300))-.05,f=d.PSY.mask_adjust-p),d.masking_lower=10**(f*.1),init_outer_loop(d,b),u[_][y]=n.calc_xmin(e,a[_][y],b,o[_][y]),u[_][y]!=0&&(m=0),c[_][y]=126,h+=l[_][y]}}for(var _=0;_<d.mode_gr;_++)for(var y=0;y<d.channels_out;y++)h>s[d.VBR_max_bitrate]&&(l[_][y]*=s[d.VBR_max_bitrate],l[_][y]/=h),c[_][y]>l[_][y]&&(c[_][y]=l[_][y]);return m},this.bitpressure_strategy=function(e,t,n,r){for(var i=0;i<e.mode_gr;i++)for(var a=0;a<e.channels_out;a++){for(var o=e.l3_side.tt[i][a],s=t[i][a],c=0,l=0;l<o.psy_lmax;l++)s[c++]*=1+.029*l*l/$.SBMAX_l/$.SBMAX_l;if(o.block_type==$.SHORT_TYPE)for(var l=o.sfb_smin;l<$.SBMAX_s;l++)s[c++]*=1+.029*l*l/$.SBMAX_s/$.SBMAX_s,s[c++]*=1+.029*l*l/$.SBMAX_s/$.SBMAX_s,s[c++]*=1+.029*l*l/$.SBMAX_s/$.SBMAX_s;r[i][a]=0|Math.max(n[i][a],.9*r[i][a])}},this.VBR_new_prepare=function(e,r,i,a,o,s){var c=e.internal_flags,l=1,u=0,d=0,f;if(e.free_format){c.bitrate_index=0;var p=new MeanBits(u);f=t.ResvFrameBegin(e,p),u=p.bits,o[0]=f}else{c.bitrate_index=c.VBR_max_bitrate;var p=new MeanBits(u);t.ResvFrameBegin(e,p),u=p.bits,get_framebits(e,o),f=o[c.VBR_max_bitrate]}for(var m=0;m<c.mode_gr;m++){n.on_pe(e,r,s[m],u,m,0),c.mode_ext==$.MPG_MD_MS_LR&&ms_convert(c.l3_side,m);for(var h=0;h<c.channels_out;++h){var g=c.l3_side.tt[m][h];c.masking_lower=10**(c.PSY.mask_adjust*.1),init_outer_loop(c,g),n.calc_xmin(e,i[m][h],g,a[m][h])!=0&&(l=0),d+=s[m][h]}}for(var m=0;m<c.mode_gr;m++)for(var h=0;h<c.channels_out;h++)d>f&&(s[m][h]*=f,s[m][h]/=d);return l},this.calc_target_bits=function(r,i,a,o,s,c){var l=r.internal_flags,u=l.l3_side,d,f,p,m,h=0;l.bitrate_index=l.VBR_max_bitrate;var g=new MeanBits(h);for(c[0]=t.ResvFrameBegin(r,g),h=g.bits,l.bitrate_index=1,h=e.getframebits(r)-l.sideinfo_len*8,s[0]=h/(l.mode_gr*l.channels_out),h=r.VBR_mean_bitrate_kbps*r.framesize*1e3,l.substep_shaping&1&&(h*=1.09),h/=r.out_samplerate,h-=l.sideinfo_len*8,h/=l.mode_gr*l.channels_out,d=.93+.07*(11-r.compression_ratio)/5.5,d<.9&&(d=.9),d>1&&(d=1),f=0;f<l.mode_gr;f++){var _=0;for(p=0;p<l.channels_out;p++){if(o[f][p]=int(d*h),i[f][p]>700){var v=int((i[f][p]-700)/1.4),y=u.tt[f][p];o[f][p]=int(d*h),y.block_type==$.SHORT_TYPE&&v<h/2&&(v=h/2),v>h*3/2?v=h*3/2:v<0&&(v=0),o[f][p]+=v}o[f][p]>LameInternalFlags.MAX_BITS_PER_CHANNEL&&(o[f][p]=LameInternalFlags.MAX_BITS_PER_CHANNEL),_+=o[f][p]}if(_>LameInternalFlags.MAX_BITS_PER_GRANULE)for(p=0;p<l.channels_out;++p)o[f][p]*=LameInternalFlags.MAX_BITS_PER_GRANULE,o[f][p]/=_}if(l.mode_ext==$.MPG_MD_MS_LR)for(f=0;f<l.mode_gr;f++)n.reduce_side(o[f],a[f],h*l.channels_out,LameInternalFlags.MAX_BITS_PER_GRANULE);for(m=0,f=0;f<l.mode_gr;f++)for(p=0;p<l.channels_out;p++)o[f][p]>LameInternalFlags.MAX_BITS_PER_CHANNEL&&(o[f][p]=LameInternalFlags.MAX_BITS_PER_CHANNEL),m+=o[f][p];if(m>c[0])for(f=0;f<l.mode_gr;f++)for(p=0;p<l.channels_out;p++)o[f][p]*=c[0],o[f][p]/=m}}var an=rn,on=g.assert;function sn(){var e;this.setModules=function(t){e=t},this.ResvFrameBegin=function(t,n){var r=t.internal_flags,i,a=r.l3_side,o=e.getframebits(t);n.bits=(o-r.sideinfo_len*8)/r.mode_gr;var s=8*256*r.mode_gr-8;t.brate>320?i=8*int(t.brate*1e3/(t.out_samplerate/1152)/8+.5):(i=8*1440,t.strict_ISO&&(i=8*int(32e4/(t.out_samplerate/1152)/8+.5))),r.ResvMax=i-o,r.ResvMax>s&&(r.ResvMax=s),(r.ResvMax<0||t.disable_reservoir)&&(r.ResvMax=0);var c=n.bits*r.mode_gr+Math.min(r.ResvSize,r.ResvMax);return c>i&&(c=i),on(r.ResvMax%8==0),on(r.ResvMax>=0),a.resvDrain_pre=0,r.pinfo!=null&&(r.pinfo.mean_bits=n.bits/2,r.pinfo.resvsize=r.ResvSize),c},this.ResvMaxBits=function(e,t,n,r){var i=e.internal_flags,a,o=i.ResvSize,s=i.ResvMax;r!=0&&(o+=t),i.substep_shaping&1&&(s*=.9),n.bits=t,o*10>s*9?(a=o-s*9/10,n.bits+=a,i.substep_shaping|=128):(a=0,i.substep_shaping&=127,!e.disable_reservoir&&!(i.substep_shaping&1)&&(n.bits-=.1*t));var c=o<i.ResvMax*6/10?o:i.ResvMax*6/10;return c-=a,c<0&&(c=0),c},this.ResvAdjust=function(e,t){e.ResvSize-=t.part2_3_length+t.part2_length},this.ResvFrameEnd=function(e,t){var n,r=e.l3_side;e.ResvSize+=t*e.mode_gr;var i=0;r.resvDrain_post=0,r.resvDrain_pre=0,(n=e.ResvSize%8)!=0&&(i+=n),n=e.ResvSize-i-e.ResvMax,n>0&&(i+=n);var a=Math.min(r.main_data_begin*8,i)/8;r.resvDrain_pre+=8*a,i-=8*a,e.ResvSize-=8*a,r.main_data_begin-=a,r.resvDrain_post+=i,e.ResvSize-=i}}var cn=sn;function ln(){var e=`http://www.mp3dev.org/`,t=3,n=98,r=4,i=0,a=93;this.getLameVersion=function(){return t+`.`+n+`.`+r},this.getLameShortVersion=function(){return t+`.`+n+`.`+r},this.getLameVeryShortVersion=function(){return`LAME`+t+`.`+n+`r`},this.getPsyVersion=function(){return i+`.`+a},this.getLameUrl=function(){return e},this.getLameOsBitness=function(){return`32bits`}}var un=ln,dn=g,fn=dn.System,pn=dn.VbrMode,mn=dn.ShortBlock,hn=dn.Arrays,gn=dn.new_byte,_n=dn.assert;vn.NUMTOCENTRIES=100,vn.MAXFRAMESIZE=2880;function vn(){var e,t,n;this.setModules=function(r,i,a){e=r,t=i,n=a};var r=1,i=2,a=4,o=8,s=vn.NUMTOCENTRIES,c=vn.MAXFRAMESIZE,l=s+4+4+4+4+4+9+1+1+8+1+1+3+1+1+2+4+2+2,u=128,d=64,f=32,p=null,m=`Xing`,h=`Info`,g=[0,49345,49537,320,49921,960,640,49729,50689,1728,1920,51009,1280,50625,50305,1088,52225,3264,3456,52545,3840,53185,52865,3648,2560,51905,52097,2880,51457,2496,2176,51265,55297,6336,6528,55617,6912,56257,55937,6720,7680,57025,57217,8e3,56577,7616,7296,56385,5120,54465,54657,5440,55041,6080,5760,54849,53761,4800,4992,54081,4352,53697,53377,4160,61441,12480,12672,61761,13056,62401,62081,12864,13824,63169,63361,14144,62721,13760,13440,62529,15360,64705,64897,15680,65281,16320,16e3,65089,64001,15040,15232,64321,14592,63937,63617,14400,10240,59585,59777,10560,60161,11200,10880,59969,60929,11968,12160,61249,11520,60865,60545,11328,58369,9408,9600,58689,9984,59329,59009,9792,8704,58049,58241,9024,57601,8640,8320,57409,40961,24768,24960,41281,25344,41921,41601,25152,26112,42689,42881,26432,42241,26048,25728,42049,27648,44225,44417,27968,44801,28608,28288,44609,43521,27328,27520,43841,26880,43457,43137,26688,30720,47297,47489,31040,47873,31680,31360,47681,48641,32448,32640,48961,32e3,48577,48257,31808,46081,29888,30080,46401,30464,47041,46721,30272,29184,45761,45953,29504,45313,29120,28800,45121,20480,37057,37249,20800,37633,21440,21120,37441,38401,22208,22400,38721,21760,38337,38017,21568,39937,23744,23936,40257,24320,40897,40577,24128,23040,39617,39809,23360,39169,22976,22656,38977,34817,18624,18816,35137,19200,35777,35457,19008,19968,36545,36737,20288,36097,19904,19584,35905,17408,33985,34177,17728,34561,18368,18048,34369,33281,17088,17280,33601,16640,33217,32897,16448];function _(e,t){if(e.nVbrNumFrames++,e.sum+=t,e.seen++,!(e.seen<e.want)&&(e.pos<e.size&&(e.bag[e.pos]=e.sum,e.pos++,e.seen=0),e.pos==e.size)){for(var n=1;n<e.size;n+=2)e.bag[n/2]=e.bag[n];e.want*=2,e.pos/=2}}function v(e,t){if(!(e.pos<=0))for(var n=1;n<s;++n){var r=n/s,i,a,o=0|Math.floor(r*e.pos);o>e.pos-1&&(o=e.pos-1),i=e.bag[o],a=e.sum;var c=0|256*i/a;c>255&&(c=255),t[n]=255&c}}this.addVbrFrame=function(e){var t=e.internal_flags,n=Tables.bitrate_table[e.version][t.bitrate_index];_n(t.VBR_seek_table.bag!=null),_(t.VBR_seek_table,n)};function y(e,t){var n=e[t+0]&255;return n<<=8,n|=e[t+1]&255,n<<=8,n|=e[t+2]&255,n<<=8,n|=e[t+3]&255,n}function b(e,t,n){e[t+0]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=n&255}function x(e,t,n){e[t+0]=n>>8&255,e[t+1]=n&255}function S(e,t){return new String(e,t,m.length(),p).equals(m)||new String(e,t,h.length(),p).equals(h)}function C(e,t,n){return 255&(e<<t|n&~(-1<<t))}function w(t,n){var r=t.internal_flags;n[0]=C(n[0],8,255),n[1]=C(n[1],3,7),n[1]=C(n[1],1,t.out_samplerate<16e3?0:1),n[1]=C(n[1],1,t.version),n[1]=C(n[1],2,1),n[1]=C(n[1],1,+!t.error_protection),n[2]=C(n[2],4,r.bitrate_index),n[2]=C(n[2],2,r.samplerate_index),n[2]=C(n[2],1,0),n[2]=C(n[2],1,t.extension),n[3]=C(n[3],2,t.mode.ordinal()),n[3]=C(n[3],2,r.mode_ext),n[3]=C(n[3],1,t.copyright),n[3]=C(n[3],1,t.original),n[3]=C(n[3],2,t.emphasis),n[0]=255;var i=n[1]&241,a=t.version==1?u:t.out_samplerate<16e3?f:d;t.VBR==pn.vbr_off&&(a=t.brate);var o=t.free_format?0:255&16*e.BitrateIndex(a,t.version,t.out_samplerate);t.version==1?(n[1]=255&(i|10),i=n[2]&13,n[2]=255&(o|i)):(n[1]=255&(i|2),i=n[2]&13,n[2]=255&(o|i))}this.getVbrTag=function(e){var t=new VBRTagData,n=0;t.flags=0;var c=e[n+1]>>3&1,l=e[n+2]>>2&3,u=e[n+3]>>6&3,d=e[n+2]>>4&15;if(d=Tables.bitrate_table[c][d],e[n+1]>>4==14?t.samprate=Tables.samplerate_table[2][l]:t.samprate=Tables.samplerate_table[c][l],c==0?u==3?n+=13:n+=21:u==3?n+=21:n+=36,!S(e,n))return null;n+=4,t.hId=c;var f=t.flags=y(e,n);if(n+=4,f&r&&(t.frames=y(e,n),n+=4),f&i&&(t.bytes=y(e,n),n+=4),f&a){if(t.toc!=null)for(var p=0;p<s;p++)t.toc[p]=e[n+p];n+=s}t.vbrScale=-1,f&o&&(t.vbrScale=y(e,n),n+=4),t.headersize=(c+1)*72e3*d/t.samprate,n+=21;var m=e[n+0]<<4;m+=e[n+1]>>4;var h=(e[n+1]&15)<<8;return h+=e[n+2]&255,(m<0||m>3e3)&&(m=-1),(h<0||h>3e3)&&(h=-1),t.encDelay=m,t.encPadding=h,t},this.InitVbrTag=function(e){var n=e.internal_flags,r=e.version==1?u:e.out_samplerate<16e3?f:d;e.VBR==pn.vbr_off&&(r=e.brate);var i=(e.version+1)*72e3*r/e.out_samplerate,a=n.sideinfo_len+l;if(n.VBR_seek_table.TotalFrameSize=i,i<a||i>c){e.bWriteVbrTag=!1;return}n.VBR_seek_table.nVbrNumFrames=0,n.VBR_seek_table.nBytesWritten=0,n.VBR_seek_table.sum=0,n.VBR_seek_table.seen=0,n.VBR_seek_table.want=1,n.VBR_seek_table.pos=0,n.VBR_seek_table.bag??(n.VBR_seek_table.bag=new int[400],n.VBR_seek_table.size=400);var o=gn(c);w(e,o);for(var s=n.VBR_seek_table.TotalFrameSize,p=0;p<s;++p)t.add_dummy_byte(e,o[p]&255,1)};function T(e,t){var n=t^e;return t=t>>8^g[n&255],t}this.updateMusicCRC=function(e,t,n,r){for(var i=0;i<r;++i)e[0]=T(t[n+i],e[0])};function E(e,t,r,i,a){var o=e.internal_flags,s=0,c=e.encoder_delay,l=e.encoder_padding,u=100-10*e.VBR_q-e.quality,d=n.getLameVeryShortVersion(),f,p=0,m,h=[1,5,3,2,4,0,3],g=0|(e.lowpassfreq/100+.5>255?255:e.lowpassfreq/100+.5),_=0,v=0,y=0,S=e.internal_flags.noise_shaping,C=0,w=0,E=0,D=0,O=0,k=(e.exp_nspsytune&1)!=0,A=(e.exp_nspsytune&2)!=0,j=!1,M=!1,N=e.internal_flags.nogap_total,P=e.internal_flags.nogap_current,F=e.ATHtype,I=0,L;switch(e.VBR){case vbr_abr:L=e.VBR_mean_bitrate_kbps;break;case vbr_off:L=e.brate;break;default:L=e.VBR_min_bitrate_kbps}switch(f=e.VBR.ordinal()<h.length?h[e.VBR.ordinal()]:0,m=16*p+f,o.findReplayGain&&(o.RadioGain>510&&(o.RadioGain=510),o.RadioGain<-510&&(o.RadioGain=-510),v=8192,v|=3072,o.RadioGain>=0?v|=o.RadioGain:(v|=512,v|=-o.RadioGain)),o.findPeakSample&&(_=Math.abs(0|o.PeakSample/32767*2**23+.5)),N!=-1&&(P>0&&(M=!0),P<N-1&&(j=!0)),I=F+(!!k<<4)+(!!A<<5)+(!!j<<6)+(!!M<<7),u<0&&(u=0),e.mode){case MONO:C=0;break;case STEREO:C=1;break;case DUAL_CHANNEL:C=2;break;case JOINT_STEREO:C=e.force_ms?4:3;break;case NOT_SET:default:C=7;break}E=e.in_samplerate<=32e3?0:e.in_samplerate==48e3?2:e.in_samplerate>48e3?3:1,(e.short_blocks==mn.short_block_forced||e.short_blocks==mn.short_block_dispensed||e.lowpassfreq==-1&&e.highpassfreq==-1||e.scale_left<e.scale_right||e.scale_left>e.scale_right||e.disable_reservoir&&e.brate<320||e.noATH||e.ATHonly||F==0||e.in_samplerate<=32e3)&&(w=1),D=S+(C<<2)+(w<<5)+(E<<6),O=o.nMusicCRC,b(r,i+s,u),s+=4;for(var R=0;R<9;R++)r[i+s+R]=255&d.charAt(R);s+=9,r[i+s]=255&m,s++,r[i+s]=255&g,s++,b(r,i+s,_),s+=4,x(r,i+s,v),s+=2,x(r,i+s,y),s+=2,r[i+s]=255&I,s++,L>=255?r[i+s]=255:r[i+s]=255&L,s++,r[i+s]=255&c>>4,r[i+s+1]=255&(c<<4)+(l>>8),r[i+s+2]=255&l,s+=3,r[i+s]=255&D,s++,r[i+ s++]=0,x(r,i+s,e.preset),s+=2,b(r,i+s,t),s+=4,x(r,i+s,O),s+=2;for(var z=0;z<s;z++)a=T(r[i+z],a);return x(r,i+s,a),s+=2,s}function D(e){e.seek(0);var t=gn(10);e.readFully(t);var n;return n=new String(t,`ISO-8859-1`).startsWith(`ID3`)?0:((t[6]&127)<<21|(t[7]&127)<<14|(t[8]&127)<<7|t[9]&127)+t.length,n}this.getLameTagFrame=function(e,n){var c=e.internal_flags;if(!e.bWriteVbrTag||c.Class_ID!=Lame.LAME_ID||c.VBR_seek_table.pos<=0)return 0;if(n.length<c.VBR_seek_table.TotalFrameSize)return c.VBR_seek_table.TotalFrameSize;hn.fill(n,0,c.VBR_seek_table.TotalFrameSize,0),w(e,n);var l=gn(s);if(e.free_format)for(var u=1;u<s;++u)l[u]=255&255*u/100;else v(c.VBR_seek_table,l);var d=c.sideinfo_len;e.error_protection&&(d-=2),e.VBR==pn.vbr_off?(n[d++]=255&h.charAt(0),n[d++]=255&h.charAt(1),n[d++]=255&h.charAt(2),n[d++]=255&h.charAt(3)):(n[d++]=255&m.charAt(0),n[d++]=255&m.charAt(1),n[d++]=255&m.charAt(2),n[d++]=255&m.charAt(3)),b(n,d,r+i+a+o),d+=4,b(n,d,c.VBR_seek_table.nVbrNumFrames),d+=4;var f=c.VBR_seek_table.nBytesWritten+c.VBR_seek_table.TotalFrameSize;b(n,d,0|f),d+=4,fn.arraycopy(l,0,n,d,l.length),d+=l.length,e.error_protection&&t.CRC_writeheader(c,n);for(var p=0,u=0;u<d;u++)p=T(n[u],p);return d+=E(e,f,n,d,p),c.VBR_seek_table.TotalFrameSize},this.putVbrTag=function(e,t){if(e.internal_flags.VBR_seek_table.pos<=0||(t.seek(t.length()),t.length()==0))return-1;var n=D(t);t.seek(n);var r=gn(c),i=getLameTagFrame(e,r);return i>r.length?-1:(i<1||t.write(r,0,i),0)}}var yn=vn,bn=g,xn=bn.new_byte,Sn=bn.assert,Cn=Mt(),wn=Ft,Tn=tt,En=Ct(),Dn=an,On=Et(),kn=cn,An=D,jn=kt();A();var Mn=un,Nn=yn;function Pn(){this.setModules=function(e,t){}}function Fn(){this.setModules=function(e,t,n){}}function In(){}function Ln(){this.setModules=function(e,t){}}function Rn(e,t,n){arguments.length!=3&&(console.error(`WARN: Mp3Encoder(channels, samplerate, kbps) not specified`),e=1,t=44100,n=128);var r=new Cn,i=new Pn,a=new Tn,o=new jn,s=new wn,c=new En,l=new Dn,u=new Nn,d=new Mn,f=new Ln,p=new kn,m=new On,h=new Fn,g=new In;r.setModules(a,o,s,c,l,u,d,f,g),o.setModules(a,g,d,u),f.setModules(o,d),s.setModules(r),l.setModules(o,p,c,m),c.setModules(m,p,r.enc.psy),p.setModules(o),m.setModules(c),u.setModules(r,o,d),i.setModules(h,g),h.setModules(d,f,s);var _=r.lame_init();_.num_channels=e,_.in_samplerate=t,_.brate=n,_.mode=An.STEREO,_.quality=3,_.bWriteVbrTag=!1,_.disable_reservoir=!0,_.write_id3tag_automatic=!1,r.lame_init_params(_);var v=1152,y=0|1.25*v+7200,b=xn(y);this.encodeBuffer=function(t,n){e==1&&(n=t),Sn(t.length==n.length),t.length>v&&(v=t.length,y=0|1.25*v+7200,b=xn(y));var i=r.lame_encode_buffer(_,t,n,t.length,b,0,y);return new Int8Array(b.subarray(0,i))},this.flush=function(){var e=r.lame_encode_flush(_,b,0,y);return new Int8Array(b.subarray(0,e))}}function zn(){this.dataOffset=0,this.dataLen=0,this.channels=0,this.sampleRate=0}function Bn(e){return e.charCodeAt(0)<<24|e.charCodeAt(1)<<16|e.charCodeAt(2)<<8|e.charCodeAt(3)}zn.RIFF=Bn(`RIFF`),zn.WAVE=Bn(`WAVE`),zn.fmt_=Bn(`fmt `),zn.data=Bn(`data`),zn.readHeader=function(e){var t=new zn,n=e.getUint32(0,!1);if(zn.RIFF==n&&(e.getUint32(4,!0),zn.WAVE==e.getUint32(8,!1)&&zn.fmt_==e.getUint32(12,!1))){var r=e.getUint32(16,!0),i=20;switch(r){case 16:case 18:t.channels=e.getUint16(i+2,!0),t.sampleRate=e.getUint32(i+4,!0);break;default:throw`extended fmt chunk not implemented`}i+=r;for(var a=zn.data,o=0;a!=n&&(n=e.getUint32(i,!1),o=e.getUint32(i+4,!0),a!=n);)i+=o+8;return t.dataLen=o,t.dataOffset=i+8,t}};var Vn=e.Mp3Encoder=Rn;e.WavHeader=zn;var Hn=1024,Un=16e3;Hn/Un,Un/Hn;var Wn={m4a:`audio/m4a`,wav:`audio/wav`,mp3:`audio/mpeg`};function Gn(e,t=Un,n=128){try{let r=new Vn(1,t,n),i=new Int16Array(e.length);for(let t=0;t<e.length;t++){let n=Math.max(-1,Math.min(1,e[t]));i[t]=n<0?n*32768:n*32767}let a=[],o=r.encodeBuffer(i);o&&o.length>0&&a.push(o);let s=r.flush();return s&&s.length>0&&a.push(s),a.length===0?null:new Blob(a,{type:Wn.mp3})}catch(e){return console.error(`[ScribeSDK] MP3 encoding failed:`,e),null}}var Kn=3,qn=2e3,Jn=1e4,Yn,Xn=[],Zn=new Map,Qn=null;function $n(e,t){try{e.postMessage(t)}catch{}}function er(e){for(let t of Xn)$n(t,e)}function tr(){return new Promise(e=>{let t=Qn;Qn=()=>{t?.(),e()},setTimeout(()=>{e()},Jn)})}async function nr(e,t,n,r){let i=`Upload failed after retries`,a;for(let o=0;o<=Kn;o++)try{let s=e.endsWith(`/`)?`${e}${t}`:`${e}/${t}`,c={"Content-Type":`audio/mp3`,...r};Yn&&(c.Authorization=`Bearer ${Yn}`);let l=await fetch(s,{method:`POST`,body:n,headers:c});if(l.ok)return{success:!0};if(a=l.status,i=await rr(l),l.status===401){er({type:`token_required`}),await tr();continue}if(l.status>=400&&l.status<500&&l.status!==408&&l.status!==429)return{success:!1,error:i,statusCode:a};o<Kn&&await ir(qn)}catch(e){i=e?.message??`Network error`,o<Kn&&await ir(qn)}return{success:!1,error:i,statusCode:a}}async function rr(e){try{let t=await e.json();return t?.error?.message??t?.message??e.statusText??`Request failed`}catch{return e.statusText??`HTTP ${e.status}`}}function ir(e){return new Promise(t=>setTimeout(t,e))}async function ar(e,t,n,r,i){try{let a=Gn(e);if(!a){$n(i,{type:`upload_failed`,fileName:t,error:`MP3 encoding failed`});return}let o=await nr(n,t,a,r);o.success?$n(i,{type:`upload_success`,fileName:t}):$n(i,{type:`upload_failed`,fileName:t,error:o.error??`Upload failed after retries`,blob:a})}catch(e){$n(i,{type:`upload_failed`,fileName:t,error:e?.message??`Unknown error`})}}function or(e,t){switch(e.type){case`compress_and_upload`:{Zn.has(t)||Zn.set(t,new Set);let n=Zn.get(t),r=ar(e.audioFrames,e.fileName,e.uploadUrl,e.headers,t);n.add(r),r.finally(()=>n.delete(r));break}case`wait_for_all_uploads`:{let e=Zn.get(t)??new Set;Promise.all(e).then(()=>{$n(t,{type:`all_uploads_complete`})});break}case`update_auth_token`:Yn=e.token,Qn&&=(Qn(),null);break;case`terminate`:{let e=Xn.indexOf(t);e>=0&&Xn.splice(e,1),Zn.delete(t);try{t.close()}catch{}Xn.length===0&&self.close();break}}}var sr=self;sr.onconnect=e=>{let t=e.ports[0];Xn.push(t),t.onmessage=e=>{or(e.data,t)},t.start()}})();
|