FS-9036: [avmd] Cast to unsigned

Should fix warnings on Windoze.
This commit is contained in:
Piotr Gregor 2016-04-07 15:56:49 +01:00
parent 8baf10d266
commit c442be0f40
2 changed files with 33 additions and 39 deletions

View File

@ -2,7 +2,11 @@
* @brief Options controlling avmd module.
*
* @author Eric des Courtis
* @par Modifications: Piotr Gregor < piotrek.gregor gmail.com >
*
* Contributor(s):
*
* Piotr Gregor <piotrek.gregor gmail.com>:
* Eric des Courtis <eric.des.courtis@benbria.com>
*/
@ -30,7 +34,7 @@
#define AVMD_REQUIRE_CONTINUOUS_STREAK
/* define number of samples to skip starting from the beginning
* of frame and after reset */
* of the frame and after reset */
#define AVMD_SAMLPE_TO_SKIP_N 6
/* define/undefine this to enable/disable simplified estimation

View File

@ -83,7 +83,8 @@
* for 8kHz audio. All the frequencies above 0.25 sampling rate
* will be aliased to some frequency below that threshold.
* This is not a problem here as we are interested in detection
* of any sine wave instead of detection of particular frequency.
* of any constant amplitude anf frequency sine wave instead
* of detection of particular frequency.
*/
#define MAX_FREQUENCY (2500.0)
/*! Maximum frequency as digital normalized frequency */
@ -105,7 +106,7 @@
/*! FreeSWITCH CUSTOM event type. */
#define AVMD_EVENT_BEEP "avmd::beep"
#define AVMD_CHAR_BUF_LEN 10
#define AVMD_CHAR_BUF_LEN 20
#define AVMD_BUF_LINEAR_LEN 160
@ -184,7 +185,7 @@ static int init_avmd_session_data(avmd_session_t *avmd_session,
#endif
avmd_session->sample_count = 0;
buf_sz = BEEP_LEN(avmd_session->rate) / SINE_LEN(avmd_session->rate);
buf_sz = BEEP_LEN((uint32_t)avmd_session->rate) / (uint32_t)SINE_LEN(avmd_session->rate);
if (buf_sz < 1) {
return -2;
}
@ -338,25 +339,21 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_avmd_load)
"Can't access file [%s], error [%s]\n",
ACOS_TABLE_FILENAME, err);
break;
case -2:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Error creating file [%s], error [%s]\n",
ACOS_TABLE_FILENAME, err);
break;
case -3:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Access rights are OK but can't open file [%s], error [%s]\n",
ACOS_TABLE_FILENAME, err);
break;
case -4:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"Access rights are OK but can't mmap file [%s], error [%s]\n",
ACOS_TABLE_FILENAME, err);
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR,
"Unknown error [%d] while initializing fast cos table [%s], "
@ -604,19 +601,22 @@ SWITCH_STANDARD_API(avmd_api_main)
switch_channel_set_private(channel, "_avmd_", NULL);
switch_core_media_bug_remove(fs_session, &bug);
switch_safe_free(ccmd);
#ifdef AVMD_REPORT_STATUS
stream->write_function(stream, "+OK\n [%s] [%s] stopped.\n\n",
uuid_dup, switch_channel_get_name(channel));
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO,
"Avmd on channel [%s] stopped!\n", switch_channel_get_name(channel));
#endif
goto end;
}
#ifdef AVMD_REPORT_STATUS
/* We have already started */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),
SWITCH_LOG_ERROR, "Avmd already started!\n");
stream->write_function(stream, "-ERR, avmd for FreeSWITCH session [%s]"
"\n already started\n\n", uuid);
#endif
goto end;
}
@ -656,13 +656,8 @@ SWITCH_STANDARD_API(avmd_api_main)
"\n has no read codec assigned yet. Please try again.\n\n",
switch_channel_get_name(channel), uuid);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR,
<<<<<<< HEAD
"Failed to start session. Channel [%s] has no codec assigned yet."
" Please try again\n", switch_channel_get_name(channel));
=======
"Failed to start session. Channel [%s] has no codec assigned yet.\n",
switch_channel_get_name(channel));
>>>>>>> FS-9031: [avmd] Check session initialization
goto end;
}
#endif
@ -685,35 +680,24 @@ SWITCH_STANDARD_API(avmd_api_main)
" for FreeSWITCH session [%s]\n", uuid);
switch (res) {
case -1:
<<<<<<< HEAD
stream->write_function(stream, "-ERR, buffer error\n\n");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),
SWITCH_LOG_ERROR, "Failed to init avmd session."
" Buffer error!\n");
break;
case -2:
=======
>>>>>>> FS-9031: [avmd] Check session initialization
stream->write_function(stream, "-ERR, SMA buffer size is 0\n\n");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),
SWITCH_LOG_ERROR, "Failed to init avmd session."
" SMA buffer size is 0!\n");
break;
<<<<<<< HEAD
case -3:
=======
case -2:
>>>>>>> FS-9031: [avmd] Check session initialization
stream->write_function(stream, "-ERR, SMA buffer error\n\n");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),
SWITCH_LOG_ERROR, "Failed to init avmd session."
" SMA buffer error\n");
break;
<<<<<<< HEAD
case -4:
=======
case -3:
>>>>>>> FS-9031: [avmd] Check session initialization
stream->write_function(stream, "-ERR, SMA sqa buffer error\n\n");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),
SWITCH_LOG_ERROR, "Failed to init avmd session."
@ -754,20 +738,13 @@ SWITCH_STANDARD_API(avmd_api_main)
/* Set the vmd tag to detect an existing vmd media bug */
switch_channel_set_private(channel, "_avmd_", bug);
<<<<<<< HEAD
/* OK */
=======
/* Everything went according to plan! Notify the user */
>>>>>>> FS-9031: [avmd] Check session initialization
#ifdef AVMD_REPORT_STATUS
stream->write_function(stream, "+OK\n [%s] [%s] started!\n\n",
uuid, switch_channel_get_name(channel));
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO,
"Avmd on channel [%s] started!\n", switch_channel_get_name(channel));
<<<<<<< HEAD
=======
>>>>>>> FS-9031: [avmd] Check session initialization
#endif
end:
if (fs_session) {
@ -787,6 +764,7 @@ end:
*/
static void avmd_process(avmd_session_t *session, switch_frame_t *frame)
{
int res;
switch_event_t *event;
switch_status_t status;
switch_event_t *event_copy;
@ -811,7 +789,7 @@ static void avmd_process(avmd_session_t *session, switch_frame_t *frame)
if (session->state.beep_state == BEEP_DETECTED) return;
/* Precompute values used heavily in the inner loop */
sine_len_i = SINE_LEN(session->rate);
sine_len_i = (uint32_t) SINE_LEN(session->rate);
//sine_len = (double)sine_len_i;
//beep_len_i = BEEP_LEN(session->rate);
@ -921,7 +899,6 @@ static void avmd_process(avmd_session_t *session, switch_frame_t *frame)
#else
sma_digital_freq = 0.5 * acos(session->sma_b.sma);
#endif /* AVMD_FAST_MATH */
snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", TO_HZ(session->rate, sma_digital_freq));
switch_channel_set_variable_printf(channel, "avmd_total_time",
"[%d]", (int)(switch_micro_time_now() - session->start_time) / 1000);
switch_channel_execute_on(channel, "execute_on_avmd_beep");
@ -934,8 +911,21 @@ static void avmd_process(avmd_session_t *session, switch_frame_t *frame)
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID",
switch_core_session_get_uuid(session->session));
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "avmd");
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "frequency", buf);
snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", v);
res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f",
TO_HZ(session->rate, sma_digital_freq));
if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session->session), SWITCH_LOG_ERROR,
"Frequency truncated [%s], [%d] attempted!\n", buf, res);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "frequency", "ERROR (TRUNCATED)");
}
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "frequency", buf);
res = snprintf(buf, AVMD_CHAR_BUF_LEN, "%f", v);
if (res < 0 || res > AVMD_CHAR_BUF_LEN - 1) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session->session), SWITCH_LOG_ERROR,
"Error, truncated [%s], [%d] attempeted!\n", buf, res);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variance", "ERROR (TRUNCATED)");
}
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variance", buf);
if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS) return;