fix energy stuff to work better on 16khz calls
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6395 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
9cbb6a56a6
commit
7d9e3c577a
|
@ -1382,17 +1382,23 @@ static void *SWITCH_THREAD_FUNC conference_loop_input(switch_thread_t * thread,
|
|||
if (switch_test_flag(member, MFLAG_CAN_SPEAK) && energy_level) {
|
||||
uint32_t energy = 0, i = 0, samples = 0, j = 0, score = 0;
|
||||
int16_t *data;
|
||||
int divisor = 0;
|
||||
|
||||
data = read_frame->data;
|
||||
|
||||
if (!(divisor = read_codec->implementation->actual_samples_per_second / 8000)) {
|
||||
divisor = 1;
|
||||
}
|
||||
|
||||
if ((samples = read_frame->datalen / sizeof(*data))) {
|
||||
|
||||
for (i = 0; i < samples; i++) {
|
||||
energy += abs(data[j]);
|
||||
j += read_codec->implementation->number_of_channels;
|
||||
}
|
||||
score = energy / samples;
|
||||
score = energy / (samples / divisor);
|
||||
}
|
||||
|
||||
|
||||
if (score > energy_level) {
|
||||
uint32_t diff = score - energy_level;
|
||||
if (hangover_hits) {
|
||||
|
|
|
@ -516,13 +516,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||
uint32_t samples = read_frame->datalen / sizeof(*fdata);
|
||||
uint32_t score, count = 0, j = 0;
|
||||
double energy = 0;
|
||||
|
||||
int divisor = 0;
|
||||
|
||||
for (count = 0; count < samples; count++) {
|
||||
energy += abs(fdata[j]);
|
||||
j += read_codec->implementation->number_of_channels;
|
||||
}
|
||||
|
||||
score = (uint32_t) (energy / samples);
|
||||
if (!(divisor = read_codec->implementation->actual_samples_per_second / 8000)) {
|
||||
divisor = 1;
|
||||
}
|
||||
|
||||
score = (uint32_t) (energy / (samples / divisor));
|
||||
if (score < fh->thresh) {
|
||||
if (!--fh->silence_hits) {
|
||||
break;
|
||||
|
|
|
@ -1375,8 +1375,13 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
|
|||
uint32_t energy = 0;
|
||||
uint32_t x, y = 0, z = len / sizeof(int16_t);
|
||||
uint32_t score = 0;
|
||||
|
||||
int divisor = 0;
|
||||
if (z) {
|
||||
|
||||
if (!(divisor = rtp_session->vad_data.read_codec->implementation->actual_samples_per_second / 8000)) {
|
||||
divisor = 1;
|
||||
}
|
||||
|
||||
for (x = 0; x < z; x++) {
|
||||
energy += abs(decoded[y]);
|
||||
y += rtp_session->vad_data.read_codec->implementation->number_of_channels;
|
||||
|
@ -1385,7 +1390,7 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
|
|||
if (++rtp_session->vad_data.start_count < rtp_session->vad_data.start) {
|
||||
send = 1;
|
||||
} else {
|
||||
score = energy / z;
|
||||
score = (energy / (z / divisor));
|
||||
if (score && (rtp_session->vad_data.bg_count < rtp_session->vad_data.bg_len)) {
|
||||
rtp_session->vad_data.bg_level += score;
|
||||
if (++rtp_session->vad_data.bg_count == rtp_session->vad_data.bg_len) {
|
||||
|
|
Loading…
Reference in New Issue