1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 12:25:12 +03:00

Fixes #3462: PlayTone check for min/max frequency added. Fixes Lua playTone() crash when called with abnormal parameter values. (#3468) (ported from master)

This commit is contained in:
Damjan Adamic 2016-05-06 22:44:43 +02:00
parent 8cd677d697
commit 6349ff9496
3 changed files with 437 additions and 424 deletions

View file

@ -657,12 +657,26 @@ int ToneContext::mixBuffer(AudioBuffer * buffer, int volume, unsigned int fade)
if (fragment.tone.freq != state.freq) {
state.freq = fragment.tone.freq;
state.step = double(DIM(sineValues)*fragment.tone.freq) / AUDIO_SAMPLE_RATE;
state.step = limit<double>(1, double(DIM(sineValues)*fragment.tone.freq) / AUDIO_SAMPLE_RATE, 512);
state.volume = evalVolumeRatio(fragment.tone.freq, volume);
}
if (fragment.tone.freqIncr) {
fragment.tone.freq += AUDIO_BUFFER_DURATION * fragment.tone.freqIncr;
int freqChange = AUDIO_BUFFER_DURATION * fragment.tone.freqIncr;
if (freqChange > 0) {
fragment.tone.freq += freqChange;
if (fragment.tone.freq > BEEP_MAX_FREQ) {
fragment.tone.freq = BEEP_MAX_FREQ;
}
}
else {
if (fragment.tone.freq > BEEP_MIN_FREQ - freqChange) {
fragment.tone.freq += freqChange;
}
else {
fragment.tone.freq = BEEP_MIN_FREQ;
}
}
}
if (remainingDuration > AUDIO_BUFFER_DURATION) {

View file

@ -40,6 +40,7 @@
#endif
#define BEEP_MIN_FREQ (150)
#define BEEP_MAX_FREQ (15000)
#define BEEP_DEFAULT_FREQ (2250)
#define BEEP_KEY_UP_FREQ (BEEP_DEFAULT_FREQ+150)
#define BEEP_KEY_DOWN_FREQ (BEEP_DEFAULT_FREQ-150)

View file

@ -604,22 +604,20 @@ static int luaPlayDuration(lua_State *L)
Play a tone
@param frequency (number) tone frequency in Hz
@param frequency (number) tone frequency in Hz (from 150 to 15000)
@param duration (number) length of the tone in (TODO units)
@param duration (number) length of the tone in milliseconds
@param pause (number) length of the pause in (TODO units)
@param pause (number) length of the silence after the tone in milliseconds
@param flags (number):
* `0 or not present` play with normal priority.
* `PLAY_BACKGROUND` play in background (built in vario function used this context)
* `PLAY_BACKGROUND` play in background (built in vario function uses this context)
* `PLAY_NOW` play immediately
@param freqIncr (number) positive number increases the tone pitch (frequency with time),
negative number decreases it. Bigger number has more effect
@notice Minimum played frequency is 150Hz even if a lower value is specified.
@status current Introduced in 2.1.0
*/
static int luaPlayTone(lua_State *L)