* 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 */
/*! 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
#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;
}
"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], "
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;
}
"\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
" 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."
/* 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) {
*/
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;
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);
#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");
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;