diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/acquire-the-content.html | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/acquire-the-content.html')
-rw-r--r-- | testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/acquire-the-content.html | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/acquire-the-content.html b/testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/acquire-the-content.html new file mode 100644 index 0000000000..659a69c866 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audiobuffer-interface/acquire-the-content.html @@ -0,0 +1,85 @@ +<!doctype html> +<meta charset="utf-8"> +<title>Test for AudioBuffer's "acquire the content" operation</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +const SAMPLERATE = 8000; +const LENGTH = 128; + +var tests = { + "AudioBufferSourceNode setter set with non-null buffer": function(oac) { + var buf = oac.createBuffer(1, LENGTH, SAMPLERATE) + var bs = new AudioBufferSourceNode(oac); + var channelData = buf.getChannelData(0); + for (var i = 0; i < channelData.length; i++) { + channelData[i] = 1.0; + } + bs.buffer = buf; + bs.start(); // This acquires the content since buf is not null + for (var i = 0; i < channelData.length; i++) { + channelData[i] = 0.5; + } + allSamplesAtOne(buf, "reading back"); + bs.connect(oac.destination); + return oac.startRendering(); + }, + "AudioBufferSourceNode buffer setter set with null" : (oac) => { + var buf = oac.createBuffer(1, LENGTH, SAMPLERATE) + var bs = new AudioBufferSourceNode(oac); + var channelData = buf.getChannelData(0); + for (var i = 0; i < channelData.length; i++) { + channelData[i] = 1.0; + } + bs.buffer = null; + bs.start(); // This does not acquire the content + bs.buffer = buf; // This does + for (var i = 0; i < channelData.length; i++) { + channelData[i] = 0.5; + } + allSamplesAtOne(buf, "reading back"); + bs.connect(oac.destination); + return oac.startRendering(); + }, + "ConvolverNode": (oac) => { + var buf = oac.createBuffer(1, LENGTH, SAMPLERATE) + var impulse = oac.createBuffer(1, 1, SAMPLERATE) + var bs = new AudioBufferSourceNode(oac); + var convolver = new ConvolverNode(oac, {disableNormalization: true}); + + impulse.getChannelData(0)[0] = 1.0; // unit impulse function + convolver.buffer = impulse; // This does acquire the content + impulse.getChannelData(0)[0] = 0.5; + + var channelData = buf.getChannelData(0); + for (var i = 0; i < channelData.length; i++) { + channelData[i] = 1.0; + } + bs.buffer = buf; + bs.start(); + + bs.connect(convolver).connect(oac.destination); + return oac.startRendering(); + } +}; + +function allSamplesAtOne(audiobuffer, location) { + var buf = audiobuffer.getChannelData(0); + for (var i = 0; i < buf.length; i++) { + // The convolver can introduce a slight numerical error. + if (Math.abs(buf[i] - 1.0) > 0.0001) { + assert_true(false, `Invalid value at index ${i}, expecte close to 1.0, found ${buf[i]} when ${location}`) + return Promise.reject(); + } + } + assert_true(true, `Buffer unmodified when ${location}.`); + return Promise.resolve(); +} + +for (const test of Object.keys(tests)) { + promise_test(async function(t) { + var buf = await tests[test](new OfflineAudioContext(1, LENGTH, SAMPLERATE)); + return allSamplesAtOne(buf, "rendering"); + }, test); +}; +</script> |