summaryrefslogtreecommitdiffstats
path: root/dom/media/webaudio/test/test_audioContextParams_sampleRate.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/media/webaudio/test/test_audioContextParams_sampleRate.html
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webaudio/test/test_audioContextParams_sampleRate.html')
-rw-r--r--dom/media/webaudio/test/test_audioContextParams_sampleRate.html82
1 files changed, 82 insertions, 0 deletions
diff --git a/dom/media/webaudio/test/test_audioContextParams_sampleRate.html b/dom/media/webaudio/test/test_audioContextParams_sampleRate.html
new file mode 100644
index 0000000000..65cee61243
--- /dev/null
+++ b/dom/media/webaudio/test/test_audioContextParams_sampleRate.html
@@ -0,0 +1,82 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <script type="application/javascript" src="mediaStreamPlayback.js"></script>
+</head>
+<body>
+<pre id="test">
+
+<script>
+/* import-globals-from ../../webrtc/tests/mochitests/mediaStreamPlayback.js */
+createHTML({
+ title: "Parallel MTG by setting AudioContextParam sample rate",
+ bug: "1387454",
+ visible: true
+});
+
+runTest(async () => {
+ // Test an AudioContext of specific sample rate.
+ // Verify that the oscillator produces a tone.
+ const rate1 = 500;
+ const ac1 = new AudioContext({sampleRate: 44100});
+ const dest_ac1 = ac1.createMediaStreamDestination();
+ const osc_ac1 = ac1.createOscillator();
+ osc_ac1.frequency.value = rate1;
+ osc_ac1.connect(dest_ac1);
+ osc_ac1.start(0);
+
+ const analyser = new AudioStreamAnalyser(ac1, dest_ac1.stream);
+ analyser.enableDebugCanvas();
+ await analyser.waitForAnalysisSuccess( array => {
+ const freg_50Hz = array[analyser.binIndexForFrequency(50)];
+ const freq_rate1 = array[analyser.binIndexForFrequency(rate1)];
+ const freq_4000Hz = array[analyser.binIndexForFrequency(4000)];
+
+ info("Analysing audio frequency - low:target1:high = "
+ + freg_50Hz + ':' + freq_rate1 + ':' + freq_4000Hz);
+ return freg_50Hz < 50 && freq_rate1 > 200 && freq_4000Hz < 50;
+ })
+ osc_ac1.stop();
+
+ // Same test using a new AudioContext of different sample rate.
+ const rate2 = 1500;
+ const ac2 = new AudioContext({sampleRate: 48000});
+ const dest_ac2 = ac2.createMediaStreamDestination();
+ const osc_ac2 = ac2.createOscillator();
+ osc_ac2.frequency.value = rate2;
+ osc_ac2.connect(dest_ac2);
+ osc_ac2.start(0);
+
+ const analyser2 = new AudioStreamAnalyser(ac2, dest_ac2.stream);
+ analyser2.enableDebugCanvas();
+ await analyser2.waitForAnalysisSuccess( array => {
+ const freg_50Hz = array[analyser2.binIndexForFrequency(50)];
+ const freq_rate2 = array[analyser2.binIndexForFrequency(rate2)];
+ const freq_4000Hz = array[analyser2.binIndexForFrequency(4000)];
+
+ info("Analysing audio frequency - low:target2:high = "
+ + freg_50Hz + ':' + freq_rate2 + ':' + freq_4000Hz);
+ return freg_50Hz < 50 && freq_rate2 > 200 && freq_4000Hz < 50;
+ })
+ osc_ac2.stop();
+
+ // Two AudioContexts with different sample rate cannot communicate.
+ mustThrowWith("Connect nodes with different sample rate", "NotSupportedError",
+ () => ac2.createMediaStreamSource(dest_ac1.stream));
+
+ // Two AudioContext with the same sample rate can communicate.
+ const ac3 = new AudioContext({sampleRate: 48000});
+ const dest_ac3 = ac3.createMediaStreamDestination();
+ ac2.createMediaStreamSource(dest_ac3.stream);
+ ok(true, "Connect nodes with the same sample rate is ok");
+
+ mustThrowWith("Invalid zero samplerate", "NotSupportedError",
+ () => new AudioContext({sampleRate: 0}));
+
+ mustThrowWith("Invalid negative samplerate", "NotSupportedError",
+ () => new AudioContext({sampleRate: -1}));
+});
+</script>
+</pre>
+</body>
+</html>