mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
func_volume: Accept decimal number as argument
Allow voice volume to be multiplied or divided by a floating point number. ASTERISK-28813 Change-Id: I5b42b890ec4e1f6b0b3400cb44ff16522b021c8c
This commit is contained in:
committed by
Friendly Automation
parent
2b80e5f5da
commit
de66713fd5
27
main/frame.c
27
main/frame.c
@@ -43,6 +43,8 @@
|
||||
#include "asterisk/dsp.h"
|
||||
#include "asterisk/file.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if (defined(LOW_MEMORY) || defined(MALLOC_DEBUG)) && !defined(NO_FRAME_CACHE)
|
||||
#define NO_FRAME_CACHE
|
||||
#endif
|
||||
@@ -706,6 +708,31 @@ int ast_frame_adjust_volume(struct ast_frame *f, int adjustment)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_frame_adjust_volume_float(struct ast_frame *f, float adjustment)
|
||||
{
|
||||
int count;
|
||||
short *fdata = f->data.ptr;
|
||||
float adjust_value = fabs(adjustment);
|
||||
|
||||
if ((f->frametype != AST_FRAME_VOICE) || !(ast_format_cache_is_slinear(f->subclass.format))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!adjustment) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (count = 0; count < f->samples; count++) {
|
||||
if (adjustment > 0) {
|
||||
ast_slinear_saturated_multiply_float(&fdata[count], &adjust_value);
|
||||
} else if (adjustment < 0) {
|
||||
ast_slinear_saturated_divide_float(&fdata[count], &adjust_value);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2)
|
||||
{
|
||||
int count;
|
||||
|
Reference in New Issue
Block a user