Skip to content

Commit

Permalink
Support fvad mode (the default produces a lot of noise in my testing) (
Browse files Browse the repository at this point in the history
  • Loading branch information
larsimmisch authored Nov 21, 2023
1 parent 5e0420b commit 37a8227
Showing 1 changed file with 59 additions and 40 deletions.
99 changes: 59 additions & 40 deletions modules/fvad/fvad.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,11 @@ static bool find_call(const struct call *call, void *arg)
return call_audio(call) == fa->audio;
}


static int encode_update(struct aufilt_enc_st **stp, void **ctx,
const struct aufilt *af, struct aufilt_prm *prm,
const struct audio *au)
static int check_fvad_params(const struct aufilt_prm *prm)
{
struct vad_enc *st;
(void)ctx;

if (!stp || !af || !prm)
if (!prm)
return EINVAL;

if (*stp)
return 0;

if (prm->ch != 1) {
warning("fvad: only mono is supported\n");
return EINVAL;
Expand All @@ -106,24 +97,67 @@ static int encode_update(struct aufilt_enc_st **stp, void **ctx,
return EINVAL;
}

st = mem_zalloc(sizeof(*st), enc_destructor);
if (!st)
return ENOMEM;
return 0;
}

st->fvad = fvad_new();
if (!st->fvad) {
mem_deref(st);
static int init_fvad(Fvad **fvad, const struct aufilt_prm *prm)
{
struct conf *conf = conf_cur();

if (!fvad || !prm)
return EINVAL;

*fvad = fvad_new();
if (!*fvad) {
return ENOMEM;
}

int err = fvad_set_sample_rate(st->fvad, prm->srate);
int err = fvad_set_sample_rate(*fvad, prm->srate);
if (err < 0) {
warning("fvad: sample rate %d is not supported\n",
prm->srate);
mem_deref(st);
return EINVAL;
}

uint32_t mode = 0;
conf_get_u32(conf, "fvad_mode", &mode);
err = fvad_set_mode(*fvad, mode);
if (err < 0) {
warning("fvad: mode %d is not supported\n",
mode);
return EINVAL;
}

return 0;
}

static int encode_update(struct aufilt_enc_st **stp, void **ctx,
const struct aufilt *af, struct aufilt_prm *prm,
const struct audio *au)
{
struct vad_enc *st;
(void)ctx;

if (!stp || !af || !prm)
return EINVAL;

if (*stp)
return 0;

int err = check_fvad_params(prm);
if (err)
return err;

st = mem_zalloc(sizeof(*st), enc_destructor);
if (!st)
return ENOMEM;

err = init_fvad(&st->fvad, prm);
if (err) {
mem_deref(st);
return err;
}

if (!st->call) {
struct filter_arg fa = { au, NULL };

Expand All @@ -149,33 +183,18 @@ static int decode_update(struct aufilt_dec_st **stp, void **ctx,
if (*stp)
return 0;

if (prm->ch != 1) {
warning("fvad: only mono is supported\n");
return EINVAL;
}

if (prm->fmt != AUFMT_S16LE) {
warning("fvad: only AUFMT_S16LE is supported. "
"Use the auconv module to fix this\n");
return EINVAL;
}
int err = check_fvad_params(prm);
if (err)
return err;

st = mem_zalloc(sizeof(*st), dec_destructor);
if (!st)
return ENOMEM;

st->fvad = fvad_new();
if (!st->fvad) {
err = init_fvad(&st->fvad, prm);
if (err) {
mem_deref(st);
return ENOMEM;
}

int err = fvad_set_sample_rate(st->fvad, prm->srate);
if (err < 0) {
warning("fvad: sample rate %d is not supported\n",
prm->srate);
mem_deref(st);
return EINVAL;
return err;
}

if (!st->call) {
Expand Down

0 comments on commit 37a8227

Please sign in to comment.