#define switch_resample_calc_buffer_size(_to, _from, _srclen) ((uint32_t)(((float)_to / (float)_from) * (float)_srclen) * 2)
-SWITCH_DECLARE(switch_status_t) switch_agc_create(switch_agc_t **agcP, uint32_t energy_avg, uint32_t margin, uint32_t change_factor, uint32_t period_len);
+SWITCH_DECLARE(switch_status_t) switch_agc_create(switch_agc_t **agcP, uint32_t energy_avg,
+ uint32_t low_energy_point, uint32_t margin, uint32_t change_factor, uint32_t period_len);
SWITCH_DECLARE(void) switch_agc_destroy(switch_agc_t **agcP);
SWITCH_DECLARE(switch_status_t) switch_agc_feed(switch_agc_t *agc, int16_t *data, uint32_t samples, uint32_t channels);
SWITCH_DECLARE(void) switch_agc_set_energy_avg(switch_agc_t *agc, uint32_t energy_avg);
+SWITCH_DECLARE(void) switch_agc_set_energy_low(switch_agc_t *agc, uint32_t low_energy_point);
SWITCH_END_EXTERN_C
#endif
/* For Emacs:
int vol;
switch_agc_t *agc;
int energy_avg;
+ int energy_low;
int first;
switch_dir_t *dir_handle;
switch_mutex_t *mutex;
if (!(source->energy_avg > -1 && source->energy_avg <= 20000)) {
source->energy_avg = 0;
}
+ } else if (!strcasecmp(var, "auto-volume-low-point")) {
+ source->energy_low = atoi(val);
+
+ if (!(source->energy_low > -1 && source->energy_avg <= 20000)) {
+ source->energy_low = 0;
+ }
}
if (source->chime_max) {
source->chime_max *= source->rate;
if (!(source->energy_avg > -1 && source->energy_avg <= 20000)) {
source->energy_avg = 0;
}
-
+ } else if (!strcasecmp(var, "auto-volume-low-point")) {
+ source->energy_low = atoi(val);
+
+ if (!(source->energy_low > -1 && source->energy_avg <= 20000)) {
+ source->energy_low = 0;
+ }
}
}
if ((source = get_source(local_stream_name))) {
if (argv[2]) {
if (!strncasecmp(argv[2], "auto:", 5)) {
+ char *p;
source->energy_avg = atoi(argv[2] + 5);
+
+ if ((p = strchr(argv[2] + 5, ':'))) {
+ int tmp = 0;
+ p++;
+ tmp = atoi(p);
+
+ if ((tmp > -1 && tmp <= 20000)) {
+ source->energy_low = tmp;
+ } else {
+ stream->write_function(stream, "-ERR invalid auto-volume low-energy level for stream: %s\n", source->name);
+ }
+ }
+
if (!(source->energy_avg > -1 && source->energy_avg <= 20000)) {
source->energy_avg = 0;
- stream->write_function(stream, "-ERR invalid auto-volume level for stream: %s\n", source->name);
+ stream->write_function(stream, "-ERR invalid auto-volume level for stream: %s\n", source->name);
} else {
if (!source->agc) {
- switch_agc_create(&source->agc, source->energy_avg, 500, 3, (1000 / source->interval) * 2);
+ switch_agc_create(&source->agc, source->energy_avg, source->energy_low, 500, 3, (1000 / source->interval) * 2);
} else {
switch_agc_set_energy_avg(source->agc, source->energy_avg);
+ switch_agc_set_energy_low(source->agc, source->energy_low);
}
}
} else {
}
if (source->energy_avg) {
- stream->write_function(stream, "+OK Auto-Volume stream: %s is %d", source->name, source->energy_avg);
+ stream->write_function(stream, "+OK Auto-Volume stream: %s is %d/%d", source->name, source->energy_avg, source->energy_low);
} else {
stream->write_function(stream, "+OK vol stream: %s is %d", source->name, source->vol);
}
uint32_t score_over;
uint32_t score_under;
uint32_t period_len;
+ uint32_t low_energy_point;
};
-SWITCH_DECLARE(switch_status_t) switch_agc_create(switch_agc_t **agcP, uint32_t energy_avg, uint32_t margin, uint32_t change_factor, uint32_t period_len)
+SWITCH_DECLARE(switch_status_t) switch_agc_create(switch_agc_t **agcP, uint32_t energy_avg,
+ uint32_t low_energy_point, uint32_t margin, uint32_t change_factor, uint32_t period_len)
{
switch_agc_t *agc;
switch_memory_pool_t *pool;
agc->margin = margin;
agc->change_factor = change_factor;
agc->period_len = period_len;
+ agc->low_energy_point = low_energy_point;
*agcP = agc;
agc->energy_avg = energy_avg;
}
+SWITCH_DECLARE(void) switch_agc_set_energy_low(switch_agc_t *agc, uint32_t low_energy_point)
+{
+ switch_assert(agc);
+
+ agc->low_energy_point = low_energy_point;
+}
+
SWITCH_DECLARE(switch_status_t) switch_agc_feed(switch_agc_t *agc, int16_t *data, uint32_t samples, uint32_t channels)
{
agc->score_over = 0;
}
- if (agc->score_avg < agc->energy_avg - agc->margin) {
+ if (agc->score_avg < agc->energy_avg - agc->margin && agc->score_avg > agc->low_energy_point) {
agc->score_under++;
} else {
agc->score_under = 0;