whitespace

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10631 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-12-05 20:43:17 +00:00
parent 8f152febe6
commit 6d0e598ee8
1 changed files with 125 additions and 158 deletions

View File

@ -40,7 +40,6 @@
#define ISNAN(x) ((x)== NAN)
#endif
/* Number of points for beep detection */
#define POINTS 32
@ -102,7 +101,6 @@
/* Prototypes */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_vmd_shutdown);
/* SWITCH_MODULE_RUNTIME_FUNCTION(mod_vmd_runtime); */
SWITCH_STANDARD_API(vmd_api_main);
SWITCH_MODULE_LOAD_FUNCTION(mod_vmd_load);
@ -143,16 +141,10 @@ typedef struct vmd_session_info{
/* A count of how long a distinct beep was detected by
* by the discreet energy separation algorithm */
switch_size_t timestamp;
/*
int16_t *data;
ssize_t data_len;
*/
} vmd_session_info_t;
static switch_bool_t process_data(vmd_session_info_t *vmd_info,
switch_frame_t *frame);
static switch_bool_t vmd_callback(switch_media_bug_t *bug,
void *user_data, switch_abc_type_t type);
static switch_bool_t process_data(vmd_session_info_t *vmd_info, switch_frame_t *frame);
static switch_bool_t vmd_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type);
static double freq_estimator(double *x);
static double ampl_estimator(double *x);
static void convert_pts(int16_t *i_pts, double *d_pts, int16_t max);
@ -165,24 +157,24 @@ static double median(double *m, int n);
*/
static switch_bool_t vmd_callback(switch_media_bug_t *bug,
void *user_data, switch_abc_type_t type)
void *user_data,
switch_abc_type_t type)
{
vmd_session_info_t *vmd_info;
switch_codec_t *read_codec;
switch_frame_t *frame;
vmd_info = (vmd_session_info_t *)user_data;
if(vmd_info == NULL) return SWITCH_FALSE;
if(vmd_info == NULL) {
return SWITCH_FALSE;
}
switch(type){
case SWITCH_ABC_TYPE_INIT:
read_codec =
switch_core_session_get_read_codec(vmd_info->session);
vmd_info->vmd_codec.rate =
read_codec->implementation->samples_per_second;
vmd_info->vmd_codec.channels =
read_codec->implementation->number_of_channels;
read_codec = switch_core_session_get_read_codec(vmd_info->session);
vmd_info->vmd_codec.rate = read_codec->implementation->samples_per_second;
vmd_info->vmd_codec.channels = read_codec->implementation->number_of_channels;
break;
case SWITCH_ABC_TYPE_CLOSE:
@ -215,7 +207,9 @@ static switch_bool_t process_data(vmd_session_info_t *vmd_info,
data = (int16_t *)frame->data;
for(max = (int16_t)abs(data[0]), i = 1; i < frame->samples; i++) {
if((int16_t)abs(data[i]) > max) max = (int16_t)abs(data[i]);
if ((int16_t)abs(data[i]) > max) {
max = (int16_t)abs(data[i]);
}
}
/*
@ -259,8 +253,8 @@ static void find_beep(vmd_session_info_t *vmd_info, switch_frame_t *frame)
double med;
unsigned int j = (vmd_info->pos + 1) % POINTS;
unsigned int k = j;
switch_status_t status;
switch_event_t *event;
switch_status_t status;
switch_event_t *event_copy;
switch(vmd_info->state){
@ -276,49 +270,25 @@ static void find_beep(vmd_session_info_t *vmd_info, switch_frame_t *frame)
if (c < (POINTS - MAX_CHIRP)) {
vmd_info->state = BEEP_NOT_DETECTED;
if(vmd_info->timestamp < MIN_TIME) break;
if (vmd_info->timestamp < MIN_TIME) {
break;
}
status = switch_event_create_subclass(&event,
SWITCH_EVENT_CUSTOM, VMD_EVENT_BEEP);
if(status != SWITCH_STATUS_SUCCESS) return;
status = switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, VMD_EVENT_BEEP);
if (status != SWITCH_STATUS_SUCCESS) {
return;
}
switch_event_add_header_string(
event,
SWITCH_STACK_BOTTOM,
"Beep-Status",
"stop"
);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Beep-Status", "stop");
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Beep-Time", "%d", vmd_info->timestamp / POINTS);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID",
"%s", switch_core_session_get_uuid(vmd_info->session));
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Frequency", "%6.4lf", vmd_info->beep_freq);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "vmd");
switch_event_add_header(
event,
SWITCH_STACK_BOTTOM,
"Beep-Time",
"%d", vmd_info->timestamp / POINTS
);
switch_event_add_header(
event,
SWITCH_STACK_BOTTOM,
"Unique-ID",
"%s", switch_core_session_get_uuid(vmd_info->session)
);
switch_event_add_header(
event,
SWITCH_STACK_BOTTOM,
"Frequency",
"%6.4lf", vmd_info->beep_freq
);
switch_event_add_header_string(
event,
SWITCH_STACK_BOTTOM,
"call-command",
"vmd"
);
status = switch_event_dup(&event_copy, event);
if(status != SWITCH_STATUS_SUCCESS) return;
if ((switch_event_dup(&event_copy, event)) != SWITCH_STATUS_SUCCESS) {
return;
}
switch_core_session_queue_event(vmd_info->session, &event);
switch_event_fire(&event_copy);
@ -332,7 +302,9 @@ static void find_beep(vmd_session_info_t *vmd_info, switch_frame_t *frame)
for(i = 0; i < POINTS; k++, k %= POINTS, i++){
m[i] = vmd_info->points[k].freq;
if(ISNAN(m[i])) m[i] = 0.0;
if (ISNAN(m[i])) {
m[i] = 0.0;
}
}
med = median(m, POINTS);
@ -397,20 +369,33 @@ static double median(double *m, int n)
for(i = 0; i < n; i++) {
if (m[i] < guess) {
less++;
if(m[i] > maxltguess) maxltguess = m[i];
if(m[i] > maxltguess) {
maxltguess = m[i];
}
} else if (m[i] > guess) {
greater++;
if(m[i] < mingtguess) mingtguess = m[i];
}else equal++;
if(m[i] < mingtguess) {
mingtguess = m[i];
}
} else {
equal++;
}
}
if (less <= ( n + 1 ) / 2 && greater <= ( n + 1 ) / 2) break;
else if (less > greater) max = maxltguess;
else min = mingtguess;
if (less <= ( n + 1 ) / 2 && greater <= ( n + 1 ) / 2) {
break;
} else if (less > greater) {
max = maxltguess;
} else {
min = mingtguess;
}
}
if(less >= ( n + 1 ) / 2) return maxltguess;
else if(less + equal >= ( n + 1 ) / 2) return guess;
if (less >= ( n + 1 ) / 2) {
return maxltguess;
} else if (less + equal >= ( n + 1 ) / 2) {
return guess;
}
return mingtguess;
}
@ -567,7 +552,6 @@ SWITCH_STANDARD_API(vmd_api_main)
switch_media_bug_t *bug;
vmd_session_info_t *vmd_info;
switch_channel_t *channel;
// switch_event_t *event;
switch_status_t status;
int argc;
char *argv[VMD_PARAMS];
@ -697,23 +681,6 @@ SWITCH_STANDARD_API(vmd_api_main)
return SWITCH_STATUS_SUCCESS;
}
/*
If it exists, this is called in it's own thread
when the module-load completes. If it returns anything
but SWITCH_STATUS_TERM it will be called again automatically
*/
/*
SWITCH_MODULE_RUNTIME_FUNCTION(mod_vmd_runtime)
{
while(looping){
switch_yield(1000);
}
return SWITCH_STATUS_TERM;
}
*/
/* For Emacs:
* Local Variables: