mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 864605 - Take the input chunk's volume into account in the nodes that buffer their input; r=padenot
--HG-- extra : rebase_source : 7590e20cbb1ac347f3988aaa5dbc586012747221
This commit is contained in:
parent
0e84496a1d
commit
372be8564a
@ -56,9 +56,9 @@ AudioBlockAddChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
|
||||
}
|
||||
|
||||
void
|
||||
AudioBlockCopyChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
|
||||
AudioBlockCopyChannelWithScale(const float* aInput,
|
||||
float aScale,
|
||||
float aOutput[WEBAUDIO_BLOCK_SIZE])
|
||||
float* aOutput)
|
||||
{
|
||||
if (aScale == 1.0f) {
|
||||
memcpy(aOutput, aInput, WEBAUDIO_BLOCK_SIZE*sizeof(float));
|
||||
|
@ -100,10 +100,12 @@ void AudioBlockAddChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
|
||||
|
||||
/**
|
||||
* Pointwise copy-scaled operation. aScale == 1.0f should be optimized.
|
||||
*
|
||||
* Buffer size is implicitly assumed to be WEBAUDIO_BLOCK_SIZE.
|
||||
*/
|
||||
void AudioBlockCopyChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
|
||||
void AudioBlockCopyChannelWithScale(const float* aInput,
|
||||
float aScale,
|
||||
float aOutput[WEBAUDIO_BLOCK_SIZE]);
|
||||
float* aOutput);
|
||||
|
||||
/**
|
||||
* Vector copy-scaled operation.
|
||||
|
@ -200,7 +200,7 @@ public:
|
||||
|
||||
// Write the input sample to the correct location in our buffer
|
||||
if (input) {
|
||||
buffer[writeIndex] = input[i];
|
||||
buffer[writeIndex] = input[i] * aInput.mVolume;
|
||||
}
|
||||
|
||||
// Now, determine the correct read position. We adjust the read position to be
|
||||
|
@ -201,9 +201,10 @@ public:
|
||||
aInput.GetDuration());
|
||||
} else {
|
||||
mSeenNonSilenceInput = true;
|
||||
PodCopy(mInputChannels[i] + mInputWriteIndex,
|
||||
static_cast<const float*>(aInput.mChannelData[i]),
|
||||
aInput.GetDuration());
|
||||
MOZ_ASSERT(aInput.GetDuration() == WEBAUDIO_BLOCK_SIZE, "sanity check");
|
||||
AudioBlockCopyChannelWithScale(static_cast<const float*>(aInput.mChannelData[i]),
|
||||
aInput.mVolume,
|
||||
mInputChannels[i] + mInputWriteIndex);
|
||||
}
|
||||
}
|
||||
mInputWriteIndex += aInput.GetDuration();
|
||||
|
@ -29,6 +29,7 @@ MOCHITEST_FILES := \
|
||||
test_biquadFilterNode.html \
|
||||
test_currentTime.html \
|
||||
test_delayNode.html \
|
||||
test_delayNodeWithGain.html \
|
||||
test_decodeAudioData.html \
|
||||
test_dynamicsCompressorNode.html \
|
||||
test_gainNode.html \
|
||||
|
@ -19,6 +19,10 @@ addLoadEvent(function() {
|
||||
for (var i = 0; i < 2048; ++i) {
|
||||
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
|
||||
}
|
||||
var expectedBuffer = context.createBuffer(1, 2048 * 2, context.sampleRate);
|
||||
for (var i = 2048; i < 2048 * 2; ++i) {
|
||||
expectedBuffer.getChannelData(0)[i] = buffer.getChannelData(0)[i - 2048];
|
||||
}
|
||||
|
||||
var destination = context.destination;
|
||||
|
||||
@ -32,7 +36,9 @@ addLoadEvent(function() {
|
||||
source.buffer = buffer;
|
||||
|
||||
source.connect(delay);
|
||||
delay.connect(destination);
|
||||
var sp = context.createScriptProcessor(2048 * 2, 1);
|
||||
delay.connect(sp);
|
||||
sp.connect(destination);
|
||||
|
||||
ok(delay.delayTime, "The audioparam member must exist");
|
||||
is(delay.delayTime.value, 0, "Correct initial value");
|
||||
@ -62,15 +68,19 @@ addLoadEvent(function() {
|
||||
}, DOMException.NOT_SUPPORTED_ERR);
|
||||
context.createDelay(1); // should not throw
|
||||
|
||||
// Delay the source stream by 2048 frames
|
||||
delay.delayTime.value = 2048 / context.sampleRate;
|
||||
|
||||
source.start(0);
|
||||
SimpleTest.executeSoon(function() {
|
||||
source.stop(0);
|
||||
source.disconnect();
|
||||
delay.disconnect();
|
||||
sp.onaudioprocess = function(e) {
|
||||
is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
|
||||
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
|
||||
|
||||
sp.onaudioprocess = null;
|
||||
|
||||
SpecialPowers.clearUserPref("media.webaudio.enabled");
|
||||
SimpleTest.finish();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
</script>
|
||||
|
62
content/media/webaudio/test/test_delayNodeWithGain.html
Normal file
62
content/media/webaudio/test/test_delayNodeWithGain.html
Normal file
@ -0,0 +1,62 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test DelayNode with a GainNode</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<pre id="test">
|
||||
<script src="webaudio.js" type="text/javascript"></script>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
addLoadEvent(function() {
|
||||
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
|
||||
|
||||
var context = new AudioContext();
|
||||
var buffer = context.createBuffer(1, 2048, context.sampleRate);
|
||||
for (var i = 0; i < 2048; ++i) {
|
||||
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
|
||||
}
|
||||
var expectedBuffer = context.createBuffer(1, 2048 * 2, context.sampleRate);
|
||||
for (var i = 2048; i < 2048 * 2; ++i) {
|
||||
expectedBuffer.getChannelData(0)[i] = buffer.getChannelData(0)[i - 2048] / 2;
|
||||
}
|
||||
|
||||
var destination = context.destination;
|
||||
|
||||
var source = context.createBufferSource();
|
||||
|
||||
var delay = context.createDelay();
|
||||
|
||||
source.buffer = buffer;
|
||||
|
||||
var gain = context.createGain();
|
||||
gain.gain.value = 0.5;
|
||||
|
||||
source.connect(gain);
|
||||
gain.connect(delay);
|
||||
var sp = context.createScriptProcessor(2048 * 2, 1);
|
||||
delay.connect(sp);
|
||||
sp.connect(destination);
|
||||
|
||||
// Delay the source stream by 2048 frames
|
||||
delay.delayTime.value = 2048 / context.sampleRate;
|
||||
|
||||
source.start(0);
|
||||
sp.onaudioprocess = function(e) {
|
||||
is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
|
||||
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
|
||||
|
||||
sp.onaudioprocess = null;
|
||||
|
||||
SpecialPowers.clearUserPref("media.webaudio.enabled");
|
||||
SimpleTest.finish();
|
||||
};
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<title>Test GainNode</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="webaudio.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
@ -18,6 +19,10 @@ addLoadEvent(function() {
|
||||
for (var i = 0; i < 2048; ++i) {
|
||||
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
|
||||
}
|
||||
var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
|
||||
for (var i = 0; i < 2048; ++i) {
|
||||
expectedBuffer.getChannelData(0)[i] = buffer.getChannelData(0)[i] / 2;
|
||||
}
|
||||
|
||||
var destination = context.destination;
|
||||
|
||||
@ -31,7 +36,9 @@ addLoadEvent(function() {
|
||||
source.buffer = buffer;
|
||||
|
||||
source.connect(gain);
|
||||
gain.connect(destination);
|
||||
var sp = context.createScriptProcessor(2048, 1);
|
||||
gain.connect(sp);
|
||||
sp.connect(destination);
|
||||
|
||||
ok(gain.gain, "The audioparam member must exist");
|
||||
is(gain.gain.value, 1.0, "Correct initial value");
|
||||
@ -41,14 +48,15 @@ addLoadEvent(function() {
|
||||
is(gain.gain.defaultValue, 1.0, "Correct default value");
|
||||
|
||||
source.start(0);
|
||||
SimpleTest.executeSoon(function() {
|
||||
source.stop(0);
|
||||
source.disconnect();
|
||||
gain.disconnect();
|
||||
sp.onaudioprocess = function(e) {
|
||||
is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
|
||||
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
|
||||
|
||||
sp.onaudioprocess = null;
|
||||
|
||||
SpecialPowers.clearUserPref("media.webaudio.enabled");
|
||||
SimpleTest.finish();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
</script>
|
||||
|
@ -24,7 +24,7 @@ function expectTypeError(func) {
|
||||
}
|
||||
|
||||
function fuzzyCompare(a, b) {
|
||||
return Math.abs(a - b) < 1e-5;
|
||||
return Math.abs(a - b) < 5e-5;
|
||||
}
|
||||
|
||||
function compareBuffers(buf1, buf2,
|
||||
|
Loading…
Reference in New Issue
Block a user