refactor: formaliza formatos de áudio e alinhamento PCM
This commit is contained in:
@@ -223,3 +223,35 @@ test("late PCM after stop is ignored", async () => {
|
||||
assert.equal(player.playing, false);
|
||||
assert.equal(player.sources.size, 0);
|
||||
});
|
||||
|
||||
|
||||
test("uses the output sample rate declared by the server", async () => {
|
||||
const context = new FakeAudioContext();
|
||||
const player = new PCMPlayer({ audioContext: context });
|
||||
player.configure({ encoding: "pcm_s16le", sample_rate: 24000, channels: 1 });
|
||||
await player.enqueue(pcm([100, 200, 300, 400]));
|
||||
assert.equal(player.sampleRate, 24000);
|
||||
assert.equal(context.sources[0].buffer.duration, 4 / 24000);
|
||||
});
|
||||
|
||||
for (const format of [
|
||||
undefined,
|
||||
{ encoding: "wav", sample_rate: 48000, channels: 1 },
|
||||
{ encoding: "pcm_s16le", sample_rate: 48000, channels: 2 },
|
||||
{ encoding: "pcm_s16le", sample_rate: "48000", channels: 1 },
|
||||
{ encoding: "pcm_s16le", sample_rate: 0, channels: 1 },
|
||||
{ encoding: "pcm_s16le", sample_rate: 192000, channels: 1 },
|
||||
]) {
|
||||
test(`rejects unsupported playback metadata: ${JSON.stringify(format)}`, () => {
|
||||
const player = new PCMPlayer({ audioContext: new FakeAudioContext() });
|
||||
assert.throws(() => player.configure(format), /Formato de áudio/);
|
||||
});
|
||||
}
|
||||
|
||||
test("rejects format changes while audio is scheduled", async () => {
|
||||
const player = new PCMPlayer({ audioContext: new FakeAudioContext() });
|
||||
await player.enqueue(pcm([100, 200]));
|
||||
assert.throws(() => player.configure({
|
||||
encoding: "pcm_s16le", sample_rate: 24000, channels: 1,
|
||||
}), /durante a reprodução/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user