Skip to content

Commit bc8c7f7

Browse files
author
bors-servo
authored
Auto merge of #331 - khodzha:issue_300_2, r=Manishearth
linear extrapolation of endpoint samples in AudioBufferSourceNode issue #300 running test https://github.com/servo/servo/blob/master/tests/wpt/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling.html after this patch results in: ![test results](https://user-images.githubusercontent.com/1618874/73188805-79746f00-4134-11ea-9fca-47b0c5868685.png)
2 parents 2ea0e52 + b5f1516 commit bc8c7f7

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

audio/buffer_source_node.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,18 @@ impl AudioBuffer {
394394

395395
let prev = pos.floor() as usize;
396396
let offset = pos - pos.floor();
397-
let next_sample = *self.buffers[chan as usize].get(prev + 1).unwrap_or(&0.0);
398-
399-
((1. - offset) * (self.buffers[chan as usize][prev] as f64) + offset * (next_sample as f64))
400-
as f32
397+
match self.buffers[chan as usize].get(prev + 1) {
398+
Some(next_sample) => {
399+
((1. - offset) * (self.buffers[chan as usize][prev] as f64)
400+
+ offset * (*next_sample as f64)) as f32
401+
}
402+
_ => {
403+
// linear extrapolation of two prev samples
404+
((1. + offset) * (self.buffers[chan as usize][prev] as f64)
405+
- offset * (self.buffers[chan as usize][prev - 1] as f64))
406+
as f32
407+
}
408+
}
401409
}
402410

403411
pub fn data_chan_mut(&mut self, chan: u8) -> &mut [f32] {

audio/panner_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl AudioNodeEngine for PannerNode {
333333
let x = if mono {
334334
(azimuth + 90.) / 180.
335335
} else if azimuth <= 0. {
336-
(azimuth + 90. / 90.)
336+
(azimuth + 90.) / 90.
337337
} else {
338338
azimuth / 90.
339339
};

0 commit comments

Comments
 (0)