Skip to content

Commit 053a26c

Browse files
authored
fix: audioparam scheduling methods (#979)
1 parent 96ad409 commit 053a26c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ void AudioParam::exponentialRampToValueAtTime(float value, double endTime) {
115115
// Exponential curve function using power law
116116
auto calculateValue =
117117
[](double startTime, double endTime, float startValue, float endValue, double time) {
118+
if (startValue * endValue < 0 || startValue == 0) {
119+
return startValue;
120+
}
121+
118122
if (time < startTime) {
119123
return startValue;
120124
}
@@ -143,6 +147,10 @@ void AudioParam::setTargetAtTime(float target, double startTime, double timeCons
143147
// Exponential decay function towards target value
144148
auto calculateValue = [timeConstant, target](
145149
double startTime, double, float startValue, float, double time) {
150+
if (timeConstant == 0) {
151+
return target;
152+
}
153+
146154
if (time < startTime) {
147155
return startValue;
148156
}

packages/react-native-audio-api/src/core/AudioParam.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ export default class AudioParam {
5656
value: number,
5757
endTime: number
5858
): AudioParam {
59+
if (value === 0) {
60+
throw new RangeError(`value must be a non-zero number: ${value}`);
61+
}
62+
5963
if (endTime <= 0) {
6064
throw new RangeError(
6165
`endTime must be a finite non-negative number: ${endTime}`

0 commit comments

Comments
 (0)