fix some sample count issues
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15395 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
a05556e7ba
commit
940ba327e7
|
@ -1158,7 +1158,7 @@ static switch_status_t create_file(switch_core_session_t *session, vm_profile_t
|
|||
got_file = 1;
|
||||
}
|
||||
|
||||
if (limit && (*message_len = fh.sample_count / read_impl.actual_samples_per_second) < profile->min_record_len) {
|
||||
if (limit && (*message_len = fh.samples_out / fh.samplerate) < profile->min_record_len) {
|
||||
if (unlink(file_path) != 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Failed to delete file [%s]\n", file_path);
|
||||
}
|
||||
|
|
|
@ -323,6 +323,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
|
|||
return status;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh, void *data, switch_size_t *len)
|
||||
{
|
||||
switch_size_t orig_len = *len;
|
||||
|
@ -374,7 +375,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
|||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
if (fh->pre_buffer) {
|
||||
switch_size_t rlen, blen;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
@ -383,6 +383,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
|||
switch_buffer_write(fh->pre_buffer, data, (asis ? *len : *len * 2) * fh->channels);
|
||||
|
||||
rlen = switch_buffer_inuse(fh->pre_buffer);
|
||||
|
||||
if (rlen >= fh->pre_buffer_datalen) {
|
||||
if ((blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen))) {
|
||||
if (!asis) blen /= 2;
|
||||
|
@ -398,7 +399,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
|||
} else {
|
||||
switch_status_t status;
|
||||
if ((status = fh->file_interface->file_write(fh, data, len)) == SWITCH_STATUS_SUCCESS) {
|
||||
fh->samples_out += *len;
|
||||
fh->samples_out += orig_len;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -474,7 +474,7 @@ static switch_bool_t record_callback(switch_media_bug_t *bug, void *user_data, s
|
|||
|
||||
|
||||
switch_core_file_close(rh->fh);
|
||||
if (rh->fh->samples_out < read_impl.samples_per_second * rh->min_sec) {
|
||||
if (rh->fh->samples_out < rh->fh->samplerate * rh->min_sec) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Discarding short file %s\n", rh->file);
|
||||
switch_file_remove(rh->file, switch_core_session_get_pool(session));
|
||||
}
|
||||
|
|
|
@ -397,9 +397,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
|
|||
switch_frame_t write_frame = { 0 };
|
||||
unsigned char write_buf[SWITCH_RECOMMENDED_BUFFER_SIZE] = { 0 };
|
||||
switch_event_t *event;
|
||||
int divisor = 0;
|
||||
|
||||
switch_core_session_get_read_impl(session, &read_impl);
|
||||
|
||||
if (!(divisor = read_impl.actual_samples_per_second / 8000)) {
|
||||
divisor = 1;
|
||||
}
|
||||
|
||||
|
||||
if (!switch_channel_ready(channel)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
@ -663,18 +669,15 @@ 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_impl.number_of_channels;
|
||||
}
|
||||
|
||||
if (!(divisor = read_impl.actual_samples_per_second / 8000)) {
|
||||
divisor = 1;
|
||||
}
|
||||
|
||||
score = (uint32_t) (energy / (samples / divisor));
|
||||
|
||||
if (score < fh->thresh) {
|
||||
if (!--fh->silence_hits) {
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue