diff --git a/src/services/atracdenc-worker.ts b/src/services/atracdenc-worker.ts index 6a86485..d632d02 100644 --- a/src/services/atracdenc-worker.ts +++ b/src/services/atracdenc-worker.ts @@ -22,6 +22,10 @@ export class AtracdencProcess { return eventData.data.result as Uint8Array; } + terminate() { + this.worker.terminate(); + } + handleMessage(ev: MessageEvent) { this.messageCallback!(ev); this.messageCallback = undefined; @@ -65,7 +69,6 @@ if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScop }, [result] ); - self.close(); } }; } else { diff --git a/src/services/audio-export.ts b/src/services/audio-export.ts index 75d73c7..82834c9 100644 --- a/src/services/audio-export.ts +++ b/src/services/audio-export.ts @@ -80,11 +80,12 @@ export class FFMpegAudioExportService implements AudioExportService { } async export({ format }: { format: string }) { + let result: ArrayBuffer; if (format === `SP`) { const outFileName = `${this.outFileNameNoExt}.raw`; await this.ffmpegProcess.transcode(this.inFileName, outFileName, '-f s16be -ar 44100'); let { data } = await this.ffmpegProcess.read(outFileName); - return data.buffer; + result = data.buffer; } else { const outFileName = `${this.outFileNameNoExt}.wav`; await this.ffmpegProcess.transcode(this.inFileName, outFileName, '-f wav -ar 44100'); @@ -101,8 +102,10 @@ export class FFMpegAudioExportService implements AudioExportService { bitrate = `64`; break; } - let result = await this.atracdencProcess!.encode(data.buffer, bitrate); - return result; + result = await this.atracdencProcess!.encode(data.buffer, bitrate); } + this.ffmpegProcess.worker.terminate(); + this.atracdencProcess!.terminate(); + return result; } } diff --git a/src/services/netmd.ts b/src/services/netmd.ts index d22df29..3107fd3 100644 --- a/src/services/netmd.ts +++ b/src/services/netmd.ts @@ -111,6 +111,8 @@ export class NetMDUSBService implements NetMDService { written = writtenBytes; updateProgress(); }); + + w.terminate(); } async play() {