diff options
author | Patrick McHardy <kaber@trash.net> | 2011-07-06 04:52:35 +0200 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2011-07-06 04:52:35 +0200 |
commit | 916e420bf0c8db7a8cb1f60557cd2807652142cf (patch) | |
tree | ece8aaf3f22e6e1cc545a858cad9e05c34713426 /main/dsp.c | |
parent | 9364aaccb699c6d19ac2cbe760c208b34ba7838a (diff) | |
parent | 357b97fb29d196a5f336d6a2879278ea135ab08c (diff) |
Merge branch 'master' of 192.168.0.100:/repos/git/asterisk
Diffstat (limited to 'main/dsp.c')
-rw-r--r-- | main/dsp.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/main/dsp.c b/main/dsp.c index 9e3e2e724..ee1891823 100644 --- a/main/dsp.c +++ b/main/dsp.c @@ -1103,7 +1103,7 @@ int ast_dsp_call_progress(struct ast_dsp *dsp, struct ast_frame *inf) return __ast_dsp_call_progress(dsp, inf->data.ptr, inf->datalen / 2); } -static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise) +static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int *totalsilence, int *totalnoise, int *frames_energy) { int accum; int x; @@ -1163,6 +1163,9 @@ static int __ast_dsp_silence_noise(struct ast_dsp *dsp, short *s, int len, int * if (totalnoise) { *totalnoise = dsp->totalnoise; } + if (frames_energy) { + *frames_energy = accum; + } return res; } @@ -1318,7 +1321,25 @@ int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence) } s = f->data.ptr; len = f->datalen/2; - return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL); + return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL, NULL); +} + +int ast_dsp_silence_with_energy(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence, int *frames_energy) +{ + short *s; + int len; + + if (f->frametype != AST_FRAME_VOICE) { + ast_log(LOG_WARNING, "Can't calculate silence on a non-voice frame\n"); + return 0; + } + if (!ast_format_is_slinear(&f->subclass.format)) { + ast_log(LOG_WARNING, "Can only calculate silence on signed-linear frames :(\n"); + return 0; + } + s = f->data.ptr; + len = f->datalen/2; + return __ast_dsp_silence_noise(dsp, s, len, totalsilence, NULL, frames_energy); } int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise) @@ -1336,7 +1357,7 @@ int ast_dsp_noise(struct ast_dsp *dsp, struct ast_frame *f, int *totalnoise) } s = f->data.ptr; len = f->datalen/2; - return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise); + return __ast_dsp_silence_noise(dsp, s, len, NULL, totalnoise, NULL); } @@ -1393,7 +1414,7 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp, /* Need to run the silence detection stuff for silence suppression and busy detection */ if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) || (dsp->features & DSP_FEATURE_BUSY_DETECT)) { - res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL); + res = __ast_dsp_silence_noise(dsp, shortdata, len, &silence, NULL, NULL); } if ((dsp->features & DSP_FEATURE_SILENCE_SUPPRESS) && silence) { |