pplugins/ducker/ducker.c

106 lines
2.5 KiB
C

/*
Copyright 2013 Peter Nelson
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <lv2.h>
struct ducker
{
double sample_rate;
float on_factor;
float off_factor;
float *in_main_l;
float *in_main_r;
float *in_aux_l;
float *in_aux_r;
float *out_l;
float *out_r;
};
static LV2_Handle ducker_instantiate(
const LV2_Descriptor *descriptor,
double sample_rate,
const char *bundle_path,
const LV2_Feature *const *host_features)
{
/* Allocate local data */
struct ducker *d = malloc(sizeof *d);
if (d == NULL) {
return NULL;
}
memset(d, 0, sizeof *d);
d->sample_rate = sample_rate;
d->on_factor = 0.0006f * 44100.0f / sample_rate;
d->off_factor = 0.00028f * 44100.0f / sample_rate;
return (LV2_Handle)d;
}
static void ducker_connect_port(LV2_Handle lv2instance, uint32_t port, void *data)
{
struct ducker *d = (struct ducker *)lv2instance;
/* Audio ports */
switch (port) {
case 0: d->in_main_l = data; break;
case 1: d->in_main_r = data; break;
case 2: d->in_aux_l = data; break;
case 3: d->in_aux_r = data; break;
case 4: d->out_l = data; break;
case 5: d->out_r = data; break;
}
}
static void ducker_run(LV2_Handle lv2instance, uint32_t sample_count)
{
struct ducker *d = (struct ducker *)lv2instance;
while (sample_count--) {
}
}
static void ducker_cleanup(LV2_Handle lv2instance)
{
struct ducker *d = (struct ducker *)lv2instance;
free(d);
}
static const LV2_Descriptor s_lv2descriptor =
{
.URI = "http://fuzzle.org/~petern/ducker/1",
.instantiate = &ducker_instantiate,
.connect_port = &ducker_connect_port,
.run = &ducker_run,
.cleanup = &ducker_cleanup,
};
const LV2_Descriptor *lv2_descriptor(uint32_t index)
{
if (index == 0) {
return &s_lv2descriptor;
}
return NULL;
}