diff --git a/frame.c b/frame.c index 39bed2e01d513ef186a769e09591c2bb77615c5b..5952b1d747f704f4599da74ee6681e08fc9b8c88 100755 --- a/frame.c +++ b/frame.c @@ -1271,3 +1271,25 @@ int ast_frame_adjust_volume(struct ast_frame *f, int adjustment) return 0; } + +int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2) +{ + int count; + short *data1, *data2; + + if ((f1->frametype != AST_FRAME_VOICE) || (f1->subclass != AST_FORMAT_SLINEAR)) + return -1; + + if ((f2->frametype != AST_FRAME_VOICE) || (f2->subclass != AST_FORMAT_SLINEAR)) + return -1; + + if (f1->samples != f2->samples) + return -1; + + for (count = 0, data1 = f1->data, data2 = f2->data; + count < f1->samples; + count++, data1++, data2++) + ast_slinear_saturated_add(data1, *data2); + + return 0; +} diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h index c17e2eecbebe2a0dd33e1019e89f642b6d4745c1..551138005af1a77798cf6f945c1685d06ed00fb9 100755 --- a/include/asterisk/frame.h +++ b/include/asterisk/frame.h @@ -427,6 +427,17 @@ static inline int ast_codec_interp_len(int format) */ int ast_frame_adjust_volume(struct ast_frame *f, int adjustment); +/*! + \brief Sums two frames of audio samples. + \param f1 The first frame (which will contain the result) + \param f2 The second frame + \return 0 for success, non-zero for an error + + The frames must be AST_FRAME_VOICE and must contain AST_FORMAT_SLINEAR samples, + and must contain the same number of samples. + */ +int ast_frame_slinear_sum(struct ast_frame *f1, struct ast_frame *f2); + #if defined(__cplusplus) || defined(c_plusplus) } #endif