mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
LibWeb: Begin implementing the interface for AudioBuffer
Implement the constructor and getChannelData function, working towards the functionality that we need in order to implement OfflineAudioContext.
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 10:05:47 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/0c8a98ac94 Pull-request: https://github.com/SerenityOS/serenity/pull/24108 Reviewed-by: https://github.com/trflynn89
48
Tests/LibWeb/Text/input/WebAudio/AudioBuffer.html
Normal file
48
Tests/LibWeb/Text/input/WebAudio/AudioBuffer.html
Normal file
@@ -0,0 +1,48 @@
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
// Invalid constructors
|
||||
const invalidOptions = [
|
||||
{ numberOfChannels: 0, length: 17, sampleRate: 10_002 }, // 0 channels (below min)
|
||||
{ numberOfChannels: 33, length: 17, sampleRate: 10_002 }, // 33 channels (above max)
|
||||
{ numberOfChannels: 3, length: 0, sampleRate: 10_002 }, // 0 length
|
||||
{ numberOfChannels: 3, length: 17, sampleRate: 7999 }, // 7999 sample rate (below min)
|
||||
{ numberOfChannels: 3, length: 17, sampleRate: 192001 }, // 192001 sample rate (above max)
|
||||
];
|
||||
|
||||
for (let invalidOption of invalidOptions) {
|
||||
try {
|
||||
const buffer = new AudioBuffer(invalidOption);
|
||||
println(`FAIL: created buffer ${buffer}`);
|
||||
} catch (e) {
|
||||
println(`Error creating AudioBuffer: '${e}'`);
|
||||
}
|
||||
}
|
||||
|
||||
// Valid Constructor
|
||||
const options = { numberOfChannels: 3, length: 17, sampleRate: 10_002 };
|
||||
const buffer = new AudioBuffer(options);
|
||||
|
||||
println(buffer.numberOfChannels);
|
||||
println(buffer.length);
|
||||
println(buffer.sampleRate);
|
||||
|
||||
// Check each of the channels
|
||||
for (let k = 0; k < options.numberOfChannels; ++k) {
|
||||
const data = buffer.getChannelData(k);
|
||||
println(`Got ${data.constructor.name}, length = ${data.length}`);
|
||||
println(data.length);
|
||||
|
||||
const dataAgain = buffer.getChannelData(k);
|
||||
println(`Data equals itself: ${data === dataAgain}`);
|
||||
}
|
||||
|
||||
// Out of range channel
|
||||
try {
|
||||
buffer.getChannelData(options.numberOfChannels);
|
||||
println("FAIL: No exception thrown");
|
||||
} catch (e) {
|
||||
println(`Error getting channel data: '${e}'`);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user