mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 11:42:27 +00:00
ensure that SLINEAR volume adjustments don't wrap around short integer maximums
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6882 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
4
frame.c
4
frame.c
@@ -1263,9 +1263,9 @@ int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
|
|||||||
|
|
||||||
for (count = 0; count < f->samples; count++) {
|
for (count = 0; count < f->samples; count++) {
|
||||||
if (adjustment > 0) {
|
if (adjustment > 0) {
|
||||||
fdata[count] *= abs(adjustment);
|
ast_slinear_saturated_multiply(&fdata[count], abs(adjustment));
|
||||||
} else if (adjustment < 0) {
|
} else if (adjustment < 0) {
|
||||||
fdata[count] /= abs(adjustment);
|
ast_slinear_saturated_divide(&fdata[count], abs(adjustment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -169,6 +169,36 @@ char *ast_uri_encode(char *string, char *outbuf, int buflen, int doreserved);
|
|||||||
*/
|
*/
|
||||||
void ast_uri_decode(char *s);
|
void ast_uri_decode(char *s);
|
||||||
|
|
||||||
|
static inline void ast_slinear_saturated_add(short *input, short value)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = *input + value;
|
||||||
|
if (res > 32767)
|
||||||
|
*input = 32767;
|
||||||
|
else if (res < -32767)
|
||||||
|
*input = -32767;
|
||||||
|
else
|
||||||
|
*input = (short) res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void ast_slinear_saturated_multiply(short *input, short value)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = *input * value;
|
||||||
|
if (res > 32767)
|
||||||
|
*input = 32767;
|
||||||
|
else if (res < -32767)
|
||||||
|
*input = -32767;
|
||||||
|
else
|
||||||
|
*input = (short) res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void ast_slinear_saturated_divide(short *input, short value)
|
||||||
|
{
|
||||||
|
*input /= value;
|
||||||
|
}
|
||||||
|
|
||||||
extern int test_for_thread_safety(void);
|
extern int test_for_thread_safety(void);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user