Move extremum.c to oRTP

parent 2c877a1b
......@@ -76,7 +76,6 @@ LOCAL_SRC_FILES = \
utils/g722_encode.c \
utils/audiodiff.c \
utils/stream_regulator.c \
utils/extremum.c \
otherfilters/msrtp.c \
otherfilters/tee.c \
otherfilters/join.c \
......
......@@ -31,26 +31,6 @@ typedef void (*MSAudioDiffProgressNotify)(void* user_data, int percentage);
/*utility function to check similarity between two audio wav files*/
MS2_PUBLIC int ms_audio_diff(const char *file1, const char *file2, double *ret, MSAudioDiffProgressNotify func, void *user_data);
/*Utility object to determine a maximum or minimum (but not both at the same time), of a signal during a sliding period of time.
**/
typedef struct _MSExtremum{
float current_extremum;
uint64_t extremum_time;
float last_stable;
int period;
}MSExtremum;
MS2_PUBLIC void ms_extremum_reset(MSExtremum *obj);
MS2_PUBLIC void ms_extremum_init(MSExtremum *obj, int period);
MS2_PUBLIC void ms_extremum_record_min(MSExtremum *obj, uint64_t curtime, float value);
MS2_PUBLIC void ms_extremum_record_max(MSExtremum *obj, uint64_t curtime, float value);
MS2_PUBLIC float ms_extremum_get_current(MSExtremum *obj);
#ifdef __cplusplus
}
#endif
......
......@@ -139,7 +139,6 @@ set(VOIP_SOURCE_FILES
utils/kiss_fftr.c
utils/kiss_fftr.h
utils/stream_regulator.c
utils/extremum.c
voip/audioconference.c
voip/audiostream.c
voip/bitratecontrol.c
......
......@@ -128,7 +128,6 @@ libmediastreamer_voip_la_SOURCES+= audiofilters/alaw.c \
utils/kiss_fftr.c \
utils/kiss_fftr.h \
utils/audiodiff.c \
utils/extremum.c \
audiofilters/equalizer.c \
audiofilters/chanadapt.c \
audiofilters/audiomixer.c \
......
/*
msvaddtx.c - Generic VAD/DTX (voice activity detector, discontinuous transmission)
msvaddtx.c - Generic VAD/DTX (voice activity detector, discontinuous transmission)
for CN payload type (RFC3389)
mediastreamer2 library - modular sound and video processing and streaming
......@@ -36,7 +36,7 @@ typedef struct _VadDtxContext{
int silence_mode;/*set to 1 if a silence period is running*/
#ifndef HAVE_G729B
float energy;
MSExtremum max;
ortp_extremum max;
#else
#endif
}VadDtxContext;
......@@ -45,37 +45,37 @@ typedef struct _VadDtxContext{
static void vad_dtx_init(MSFilter *f){
VadDtxContext *ctx=ms_new0(VadDtxContext,1);
f->data=ctx;
ms_extremum_init(&ctx->max,2000);
ortp_extremum_init(&ctx->max,2000);
}
static void vad_dtx_preprocess(MSFilter *f){
VadDtxContext *ctx=(VadDtxContext*)f->data;
ms_extremum_reset(&ctx->max);
ortp_extremum_reset(&ctx->max);
}
static void update_energy(VadDtxContext *v, int16_t *signal, int numsamples, uint64_t curtime) {
int i;
float acc = 0;
float en;
for (i=0;i<numsamples;++i){
int s=signal[i];
acc += s * s;
}
en = (sqrt(acc / numsamples)+1) / max_e;
v->energy = (en * coef) + v->energy * (1.0 - coef);
ms_extremum_record_max(&v->max,curtime,v->energy);
ortp_extremum_record_max(&v->max,curtime,v->energy);
}
static void vad_dtx_process(MSFilter *f){
VadDtxContext *ctx=(VadDtxContext*)f->data;
mblk_t *m;
while((m=ms_queue_get(f->inputs[0]))!=NULL){
update_energy(ctx,(int16_t*)m->b_rptr, (m->b_wptr - m->b_rptr) / 2, f->ticker->time);
if (ms_extremum_get_current(&ctx->max)<silence_threshold){
if (ortp_extremum_get_current(&ctx->max)<silence_threshold){
if (!ctx->silence_mode){
MSCngData cngdata={0};
cngdata.datasize=1; /*only noise level*/
......@@ -92,12 +92,12 @@ static void vad_dtx_process(MSFilter *f){
}
if (!ctx->silence_mode) ms_queue_put(f->outputs[0],m);
}
}
static void vad_dtx_postprocess(MSFilter *f){
//VadDtxContext *ctx=(VadDtxContext*)f->data;
}
static void vad_dtx_uninit(MSFilter *f){
......
......@@ -72,8 +72,8 @@ typedef struct Volume{
float ng_floorgain;
float ng_gain;
MSBufferizer *buffer;
MSExtremum min;
MSExtremum max;
ortp_extremum min;
ortp_extremum max;
bool_t agc_enabled;
bool_t noise_gate_enabled;
bool_t remove_dc;
......@@ -109,8 +109,8 @@ static void volume_init(MSFilter *f){
#ifdef HAVE_SPEEXDSP
v->speex_pp=NULL;
#endif
ms_extremum_init(&v->max,1000);
ms_extremum_init(&v->min,30000);
ortp_extremum_init(&v->max,1000);
ortp_extremum_init(&v->min,30000);
f->data=v;
}
......@@ -139,14 +139,14 @@ static int volume_get(MSFilter *f, void *arg){
static int volume_get_min(MSFilter *f, void *arg){
float *farg=(float*)arg;
Volume *v=(Volume*)f->data;
*farg=linear_to_db(ms_extremum_get_current(&v->min));
*farg=linear_to_db(ortp_extremum_get_current(&v->min));
return 0;
}
static int volume_get_max(MSFilter *f, void *arg){
float *farg=(float*)arg;
Volume *v=(Volume*)f->data;
*farg=linear_to_db(ms_extremum_get_current(&v->max));
*farg=linear_to_db(ortp_extremum_get_current(&v->max));
return 0;
}
......@@ -203,12 +203,12 @@ static float volume_echo_avoider_process(Volume *v, mblk_t *om) {
float mic_spk_ratio;
peer_e = ((Volume *)(v->peer->data))->energy;
peer_pk=((Volume *)(v->peer->data))->energy;
if (peer_pk>v->lt_speaker_en)
v->lt_speaker_en=peer_pk;
else v->lt_speaker_en=(0.005*peer_pk)+(0.995*v->lt_speaker_en);
mic_spk_ratio=(v->energy/(v->lt_speaker_en+v->ea_thres));
/* where v->target_gain is not set, it is kept steady - not to modify elsewhere! */
if (peer_e > v->ea_thres) {
if (mic_spk_ratio>v->ea_transmit_thres){
......@@ -389,7 +389,7 @@ static void update_energy(Volume *v, int16_t *signal, int numsamples, uint64_t c
float acc = 0;
float en;
int lp = 0, pk = 0;
for (i=0;i<numsamples;++i){
int s=signal[i];
acc += s * s;
......@@ -402,8 +402,8 @@ static void update_energy(Volume *v, int16_t *signal, int numsamples, uint64_t c
v->energy = (en * coef) + v->energy * (1.0 - coef);
v->level_pk = (float)pk / max_e;
v->instant_energy = en;// currently non-averaged energy seems better (short artefacts)
ms_extremum_record_max(&v->max,curtime,v->energy);
ms_extremum_record_min(&v->min,curtime,v->energy);
ortp_extremum_record_max(&v->max,curtime,v->energy);
ortp_extremum_record_min(&v->min,curtime,v->energy);
}
static void apply_gain(Volume *v, mblk_t *m, float tgain) {
......@@ -413,7 +413,7 @@ static void apply_gain(Volume *v, mblk_t *m, float tgain) {
float gain;
/* ramps with factors means linear ramps in logarithmic domain */
if (v->gain < tgain) {
if (v->gain<v->ng_floorgain)
v->gain=v->ng_floorgain;
......@@ -431,7 +431,7 @@ static void apply_gain(Volume *v, mblk_t *m, float tgain) {
intgain = gain* 4096;
//if (v->peer) ms_message("MSVolume:%p Applying gain %5f, v->gain=%5f, tgain=%5f, ng_gain=%5f",v,gain,v->gain,tgain,v->ng_gain);
//if (v->peer) ms_message("MSVolume:%p Applying gain %5f, v->gain=%5f, tgain=%5f, ng_gain=%5f",v,gain,v->gain,tgain,v->ng_gain);
if (v->remove_dc){
for ( sample=(int16_t*)m->b_rptr;
......@@ -471,8 +471,8 @@ static void volume_preprocess(MSFilter *f){
}
#endif
}
ms_extremum_reset(&v->min);
ms_extremum_reset(&v->max);
ortp_extremum_reset(&v->min);
ortp_extremum_reset(&v->max);
}
static void volume_process(MSFilter *f){
......
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2014 Belledonne Communications SARL
Author: Simon MORLAT (simon.morlat@linphone.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mediastreamer2/msutils.h"
void ms_extremum_reset(MSExtremum *obj){
obj->current_extremum=0;
obj->extremum_time=(uint64_t)-1;
obj->last_stable=0;
}
void ms_extremum_init(MSExtremum *obj, int period){
ms_extremum_reset(obj);
obj->period=period;
}
static void extremum_set_new(MSExtremum *obj, const char* kind){
obj->last_stable=obj->current_extremum;
/*ms_message("New %s value : %f",kind,obj->last_stable);*/
}
static void extremum_check_init(MSExtremum *obj, uint64_t curtime, float value, const char *kind){
if (obj->extremum_time!=(uint64_t)-1){
if (curtime-obj->extremum_time>obj->period){
/*last extremum is too old, drop it*/
extremum_set_new(obj,kind);
obj->extremum_time=(uint64_t)-1;
}
}
if (obj->extremum_time==(uint64_t)-1){
obj->current_extremum=value;
obj->extremum_time=curtime;
}
}
void ms_extremum_record_min(MSExtremum *obj, uint64_t curtime, float value){
extremum_check_init(obj,curtime,value,"min");
if (value<obj->current_extremum){
obj->current_extremum=value;
obj->extremum_time=curtime;
if (value<obj->last_stable){
extremum_set_new(obj,"min");
}
}
}
void ms_extremum_record_max(MSExtremum *obj, uint64_t curtime, float value){
extremum_check_init(obj,curtime,value,"max");
if (value>obj->current_extremum){
obj->current_extremum=value;
obj->extremum_time=curtime;
if (value>obj->last_stable){
extremum_set_new(obj,"max");
}
}
}
float ms_extremum_get_current(MSExtremum *obj){
return obj->last_stable;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment