Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub-sample accurate start for ABSN #13061

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions webaudio/resources/biquad-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ let signal;
let renderedBuffer;
let renderedData;

let sampleRate = 44100.0;
// Use a power of two to eliminate round-off in converting frame to time
let sampleRate = 32768;
let pulseLengthFrames = .1 * sampleRate;

// Maximum allowed error for the test to succeed. Experimentally determined.
let maxAllowedError = 5.9e-8;

// This must be large enough so that the filtered result is
// essentially zero. See comments for createTestAndRun.
let timeStep = .1;
// This must be large enough so that the filtered result is essentially zero.
// See comments for createTestAndRun. This must be a whole number of frames.
let timeStep = Math.ceil(.1 * sampleRate) / sampleRate;

// Maximum number of filters we can process (mostly for setting the
// render length correctly.)
Expand Down
11 changes: 7 additions & 4 deletions webaudio/resources/distance-model-testing.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
let sampleRate = 44100.0;
// Use a power of two to eliminate round-off when converting frames to time and
// vice versa.
let sampleRate = 32768;

// How many panner nodes to create for the test.
let nodesToCreate = 100;

// Time step when each panner node starts.
let timeStep = 0.001;
// Time step when each panner node starts. Make sure it starts on a frame
// boundary.
let timeStep = Math.floor(0.001 * sampleRate) / sampleRate;

// Make sure we render long enough to get all of our nodes.
let renderLengthSeconds = timeStep * (nodesToCreate + 1);
Expand Down Expand Up @@ -134,7 +137,7 @@ function checkDistanceResult(renderedBuffer, model, should) {
// The max allowed error between the actual gain and the expected
// value. This is determined experimentally. Set to 0 to see
// what the actual errors are.
let maxAllowedError = 3.3e-6;
let maxAllowedError = 2.2720e-6;

let success = true;

Expand Down
18 changes: 12 additions & 6 deletions webaudio/resources/note-grain-on-testing.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
let sampleRate = 44100.0;
// Use a power of two to eliminate round-off converting from frames to time.
let sampleRate = 32768;

// How many grains to play.
let numberOfTests = 100;

// Duration of each grain to be played
let duration = 0.01;
// Duration of each grain to be played. Make a whole number of frames
let duration = Math.floor(0.01 * sampleRate) / sampleRate;

// A little extra bit of silence between grain boundaries. Must be a whole
// number of frames.
let grainGap = Math.floor(0.005 * sampleRate) / sampleRate;

// Time step between the start of each grain. We need to add a little
// bit of silence so we can detect grain boundaries
let timeStep = duration + .005;
let timeStep = duration + grainGap;

// Time step between the start for each grain.
let grainOffsetStep = 0.001;
// Time step between the start for each grain. Must be a whole number of
// frames.
let grainOffsetStep = Math.floor(0.001 * sampleRate) / sampleRate;

// How long to render to cover all of the grains.
let renderTime = (numberOfTests + 1) * timeStep;
Expand Down
11 changes: 7 additions & 4 deletions webaudio/resources/panner-model-testing.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
let sampleRate = 44100.0;
// Use a power of two to eliminate round-off when converting frames to time and
// vice versa.
let sampleRate = 32768;

let numberOfChannels = 1;

// Time step when each panner node starts.
let timeStep = 0.001;
// Time step when each panner node starts. Make sure it starts on a frame
// boundary.
let timeStep = Math.floor(0.001 * sampleRate) / sampleRate;

// Length of the impulse signal.
let pulseLengthFrames = Math.round(timeStep * sampleRate);
Expand Down Expand Up @@ -114,7 +117,7 @@ function checkResult(renderedBuffer, should) {
// The max error we allow between the rendered impulse and the
// expected value. This value is experimentally determined. Set
// to 0 to make the test fail to see what the actual error is.
let maxAllowedError = 1.3e-6;
let maxAllowedError = 1.1597e-6;

let success = true;

Expand Down
10 changes: 6 additions & 4 deletions webaudio/resources/stereopanner-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ let StereoPannerTest = (function() {
// Constants
let PI_OVER_TWO = Math.PI * 0.5;

let gSampleRate = 44100;
// Use a power of two to eliminate any round-off when converting frames to
// time.
let gSampleRate = 32768;

// Time step when each panner node starts.
let gTimeStep = 0.001;
// Time step when each panner node starts. Make sure this is on a frame boundary.
let gTimeStep = Math.floor(0.001 * gSampleRate) / gSampleRate;

// How many panner nodes to create for the test
let gNodesToCreate = 100;
Expand Down Expand Up @@ -77,7 +79,7 @@ let StereoPannerTest = (function() {
// The max error we allow between the rendered impulse and the
// expected value. This value is experimentally determined. Set
// to 0 to make the test fail to see what the actual error is.
this.maxAllowedError = 1.3e-6;
this.maxAllowedError = 9.8015e-8;

// Max (absolute) error and the index of the maxima for the left
// and right channels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,42 @@
.then(() => task.done());
});

audit.define('subsample start with playback rate 0', (task, should) => {
let context = new OfflineAudioContext(1, renderLength, sampleRate);
let rampBuffer = new AudioBuffer(
{length: renderLength, sampleRate: context.sampleRate});
let data = new Float32Array(renderLength);
let startValue = 5;
for (let k = 0; k < data.length; ++k) {
data[k] = k + startValue;
}
rampBuffer.copyToChannel(data, 0);

let src = new AudioBufferSourceNode(
context, {buffer: rampBuffer, playbackRate: 0});

src.connect(context.destination);

// Purposely start the source between frame boundaries
let startFrame = 27.3;
src.start(startFrame / context.sampleRate);

context.startRendering()
.then(audioBuffer => {
let actualStartFrame = Math.ceil(startFrame);
let audio = audioBuffer.getChannelData(0);

should(
audio.slice(0, actualStartFrame),
`output[0:${actualStartFrame - 1}]`)
.beConstantValueOf(0);
should(
audio.slice(actualStartFrame), `output[${actualStartFrame}:]`)
.beConstantValueOf(startValue);
})
.then(() => task.done());
});

audit.run();
</script>
</body>
Expand Down
Loading