Revision
15395
Author
anthm
Date
2009-11-06 17:29:36 -0600 (Fri, 06 Nov 2009)

Log Message

fix some sample count issues

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c (15394 => 15395)


--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	2009-11-06 23:19:15 UTC (rev 15394)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	2009-11-06 23:29:36 UTC (rev 15395)
@@ -1158,7 +1158,7 @@
 			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);
 			}

Modified: freeswitch/trunk/src/switch_core_file.c (15394 => 15395)


--- freeswitch/trunk/src/switch_core_file.c	2009-11-06 23:19:15 UTC (rev 15394)
+++ freeswitch/trunk/src/switch_core_file.c	2009-11-06 23:29:36 UTC (rev 15395)
@@ -323,6 +323,7 @@
 	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 @@
 		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_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 @@
 	} 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;
 	}

Modified: freeswitch/trunk/src/switch_ivr_async.c (15394 => 15395)


--- freeswitch/trunk/src/switch_ivr_async.c	2009-11-06 23:19:15 UTC (rev 15394)
+++ freeswitch/trunk/src/switch_ivr_async.c	2009-11-06 23:29:36 UTC (rev 15395)
@@ -474,7 +474,7 @@
 				
 
 				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));
 				}

Modified: freeswitch/trunk/src/switch_ivr_play_say.c (15394 => 15395)


--- freeswitch/trunk/src/switch_ivr_play_say.c	2009-11-06 23:19:15 UTC (rev 15394)
+++ freeswitch/trunk/src/switch_ivr_play_say.c	2009-11-06 23:29:36 UTC (rev 15395)
@@ -397,9 +397,15 @@
 	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 @@
 			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));
 
-			score = (uint32_t) (energy / (samples / divisor));
 			if (score < fh->thresh) {
 				if (!--fh->silence_hits) {
 					break;