Skip to content

Commit 46a788f

Browse files
committed
AudioParam end time calculation, use round instead of ceil
1 parent 18b3137 commit 46a788f

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/param.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,9 @@ impl AudioParamProcessor {
11101110

11111111
if infos.is_a_rate {
11121112
let start_index = self.buffer.len();
1113-
// we need to `ceil()` because if `end_time` is between two samples
1113+
// we need to `round()` because if `end_time` is between two samples
11141114
// we actually want the sample before `end_time` to be computed
1115-
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).ceil() as usize;
1115+
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).round() as usize;
11161116
let end_index_clipped = end_index.min(infos.count);
11171117

11181118
// compute "real" value according to `t` then clamp it
@@ -1212,10 +1212,9 @@ impl AudioParamProcessor {
12121212

12131213
if infos.is_a_rate {
12141214
let start_index = self.buffer.len();
1215-
// we need to `ceil()` because if `end_time` is between two samples
1215+
// we need to `round()` because if `end_time` is between two samples
12161216
// we actually want the sample before `end_time` to be computed
1217-
// @todo - more tests
1218-
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).ceil() as usize;
1217+
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).round() as usize;
12191218
let end_index_clipped = end_index.min(infos.count);
12201219

12211220
if end_index_clipped > start_index {
@@ -1338,10 +1337,9 @@ impl AudioParamProcessor {
13381337

13391338
if infos.is_a_rate {
13401339
let start_index = self.buffer.len();
1341-
// we need to `ceil()` because if `end_time` is between two samples
1340+
// we need to `round()` because if `end_time` is between two samples
13421341
// we actually want the sample before `end_time` to be computed
1343-
// @todo - more tests
1344-
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).ceil() as usize;
1342+
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).round() as usize;
13451343
let end_index_clipped = end_index.min(infos.count);
13461344

13471345
if end_index_clipped > start_index {
@@ -1439,10 +1437,9 @@ impl AudioParamProcessor {
14391437

14401438
if infos.is_a_rate {
14411439
let start_index = self.buffer.len();
1442-
// we need to `ceil()` because if `end_time` is between two samples
1440+
// we need to `round()` because if `end_time` is between two samples
14431441
// we actually want the sample before `end_time` to be computed
1444-
// @todo - more tests
1445-
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).ceil() as usize;
1442+
let end_index = ((end_time - infos.block_time).max(0.) / infos.dt).round() as usize;
14461443
let end_index_clipped = end_index.min(infos.count);
14471444

14481445
if end_index_clipped > start_index {

0 commit comments

Comments
 (0)