refactor: formaliza formatos de áudio e alinhamento PCM
This commit is contained in:
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user