refactor: formaliza formatos de áudio e alinhamento PCM

This commit is contained in:
alex alves
2026-11-03 16:43:22 -03:00
parent 4d7ff46a36
commit 76d15b8e52
23 changed files with 349 additions and 82 deletions

View File

@@ -62,6 +62,22 @@ export class PCMPlayer {
return this.analyser;
}
configure(format) {
if (
format?.encoding !== "pcm_s16le" ||
format.channels !== 1 ||
!Number.isInteger(format.sample_rate) ||
format.sample_rate < 8000 ||
format.sample_rate > 96000
) {
throw new Error("Formato de áudio de saída incompatível.");
}
if (this.sources.size > 0) {
throw new Error("Não é possível trocar o formato durante a reprodução.");
}
this.sampleRate = format.sample_rate;
}
decodePCM(buffer) {
if (!(buffer instanceof ArrayBuffer)) {
throw new TypeError("PCM chunk must be an ArrayBuffer.");