mix output with input
This commit is contained in:
parent
e59ac18e96
commit
40c2cf5152
93
ladex.c
93
ladex.c
|
@ -3,35 +3,41 @@
|
|||
#include<stdint.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include"ladex.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
# if __GNUC__
|
||||
# define ON_LOAD_ROUTINE static void __attribute__ ((constructor)) init()
|
||||
# define ON_UNLOAD_ROUTINE static void __attribute__ ((destructor)) fini()
|
||||
# else
|
||||
# define ON_LOAD_ROUTINE void init()
|
||||
# define ON_UNLOAD_ROUTINE void fini()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Port numbers for the plugin
|
||||
#define LADEX_PORT_COUNT 3
|
||||
#define LADEX_PORT_AMPLITUDE 0x0
|
||||
#define LADEX_PORT_OUTPUT 0x1
|
||||
#define LADEX_PORT_INPUT 0x2
|
||||
|
||||
// Port connection information and state
|
||||
typedef struct Ladex
|
||||
{
|
||||
LADSPA_Data*amp;
|
||||
LADSPA_Data*output;
|
||||
LADSPA_Data*input;
|
||||
} Ladex;
|
||||
|
||||
// Descriptor for plugin
|
||||
static LADSPA_Descriptor*ladspa_desc;
|
||||
|
||||
static inline void ladex_run_base(LADSPA_Handle handle,uint32_t nsamples,LADSPA_Data amp)
|
||||
{
|
||||
Ladex*ladex=(Ladex*)handle;
|
||||
LADSPA_Data*out=ladex->output;
|
||||
LADSPA_Data*in=ladex->input;
|
||||
|
||||
for(uint32_t i=0;i<nsamples;i++)
|
||||
*out++=((*in)+((i%500>250)?(INT_MAX):(-INT_MAX))*amp)/2.0;
|
||||
}
|
||||
|
||||
// Run a delay line instance for a block of SampleCount samples
|
||||
// Run plugin over block
|
||||
static void ladex_run(LADSPA_Handle handle,unsigned long samplecount)
|
||||
{
|
||||
Ladex*ladex=(Ladex*)handle;
|
||||
LADSPA_Data amp=*(ladex->amp)*(LADSPA_Data)(2.0/INT_MAX);
|
||||
ladex_run_base(ladex,samplecount,amp);
|
||||
}
|
||||
|
||||
// Run a delay line instance for a block of SampleCount samples. *ADD*
|
||||
// the output to the output buffer
|
||||
static void ladex_run_adding(LADSPA_Handle handle,unsigned long samplecount)
|
||||
{
|
||||
Ladex*ladex=(Ladex*)handle;
|
||||
LADSPA_Data amp=*(ladex->amp)*ladex->runaddinggain*(LADSPA_Data)(2.0/INT_MAX);
|
||||
ladex_run_base(ladex,samplecount,amp);
|
||||
for(uint32_t i=0;i<samplecount;i++)
|
||||
ladex->output[i]=(ladex->input[i]+((i%500>250)?(INT_MAX):(-INT_MAX))*amp)/2.0f;
|
||||
}
|
||||
|
||||
// Construct a new plugin instance
|
||||
|
@ -39,7 +45,7 @@ static LADSPA_Handle ladex_instantiate(const LADSPA_Descriptor*desc,unsigned lon
|
|||
{
|
||||
desc=desc;
|
||||
samplerate=samplerate;
|
||||
return malloc(sizeof(Ladex));
|
||||
return calloc(1,sizeof(Ladex));
|
||||
}
|
||||
|
||||
// Connect a port to a data location
|
||||
|
@ -49,24 +55,19 @@ static void ladex_connect_port(LADSPA_Handle handle,unsigned long port,LADSPA_Da
|
|||
|
||||
switch(port)
|
||||
{
|
||||
case PORT_AMPLITUDE:
|
||||
case LADEX_PORT_AMPLITUDE:
|
||||
ladex->amp=dataloc;
|
||||
break;
|
||||
case PORT_OUTPUT:
|
||||
case LADEX_PORT_OUTPUT:
|
||||
ladex->output=dataloc;
|
||||
break;
|
||||
case PORT_INPUT:
|
||||
case LADEX_PORT_INPUT:
|
||||
ladex->input=dataloc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ladex_set_adding_gain(LADSPA_Handle handle,LADSPA_Data gain)
|
||||
{
|
||||
((Ladex*)handle)->runaddinggain=gain;
|
||||
}
|
||||
|
||||
// Throw away a simple delay line
|
||||
// Free memory
|
||||
static void ladex_cleanup(LADSPA_Handle handle)
|
||||
{
|
||||
free(handle);
|
||||
|
@ -89,27 +90,27 @@ ON_LOAD_ROUTINE
|
|||
ladspa_desc->Name="LADSPA example";
|
||||
ladspa_desc->Maker="LADSPA example";
|
||||
ladspa_desc->Copyright="Corey Dunn";
|
||||
ladspa_desc->PortCount=2;
|
||||
portdesc=(LADSPA_PortDescriptor*)calloc(2,sizeof(LADSPA_PortDescriptor));
|
||||
ladspa_desc->PortCount=LADEX_PORT_COUNT;
|
||||
portdesc=(LADSPA_PortDescriptor*)calloc(LADEX_PORT_COUNT,sizeof(LADSPA_PortDescriptor));
|
||||
ladspa_desc->PortDescriptors=(const LADSPA_PortDescriptor*)portdesc;
|
||||
portdesc[PORT_AMPLITUDE]=(LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL);
|
||||
portdesc[PORT_OUTPUT]=LADSPA_PORT_OUTPUT|LADSPA_PORT_AUDIO;
|
||||
portdesc[PORT_INPUT]=LADSPA_PORT_INPUT|LADSPA_PORT_AUDIO;
|
||||
portnames=(char**)calloc(2,sizeof(char*));
|
||||
portdesc[LADEX_PORT_AMPLITUDE]=(LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL);
|
||||
portdesc[LADEX_PORT_OUTPUT]=LADSPA_PORT_OUTPUT|LADSPA_PORT_AUDIO;
|
||||
portdesc[LADEX_PORT_INPUT]=LADSPA_PORT_INPUT|LADSPA_PORT_AUDIO;
|
||||
portnames=(char**)calloc(LADEX_PORT_COUNT,sizeof(char*));
|
||||
ladspa_desc->PortNames=(const char**)portnames;
|
||||
portnames[PORT_AMPLITUDE]="Amplitude";
|
||||
portnames[PORT_OUTPUT]="Output";
|
||||
hints=((LADSPA_PortRangeHint*)calloc(2,sizeof(LADSPA_PortRangeHint)));
|
||||
portnames[LADEX_PORT_AMPLITUDE]="Amplitude";
|
||||
portnames[LADEX_PORT_OUTPUT]="Output";
|
||||
hints=((LADSPA_PortRangeHint*)calloc(LADEX_PORT_COUNT,sizeof(LADSPA_PortRangeHint)));
|
||||
ladspa_desc->PortRangeHints=(const LADSPA_PortRangeHint*)hints;
|
||||
hints[PORT_AMPLITUDE].HintDescriptor=(LADSPA_HINT_BOUNDED_BELOW|LADSPA_HINT_LOGARITHMIC|LADSPA_HINT_DEFAULT_LOW);
|
||||
hints[PORT_AMPLITUDE].LowerBound=0;
|
||||
hints[PORT_OUTPUT].HintDescriptor=0;
|
||||
hints[LADEX_PORT_AMPLITUDE].HintDescriptor=(LADSPA_HINT_BOUNDED_BELOW|LADSPA_HINT_LOGARITHMIC|LADSPA_HINT_DEFAULT_LOW);
|
||||
hints[LADEX_PORT_AMPLITUDE].LowerBound=0;
|
||||
hints[LADEX_PORT_OUTPUT].HintDescriptor=0;
|
||||
ladspa_desc->instantiate=ladex_instantiate;
|
||||
ladspa_desc->connect_port=ladex_connect_port;
|
||||
ladspa_desc->activate=NULL;
|
||||
ladspa_desc->run=ladex_run;
|
||||
ladspa_desc->run_adding=ladex_run_adding;
|
||||
ladspa_desc->set_run_adding_gain=ladex_set_adding_gain;
|
||||
ladspa_desc->run_adding=NULL;
|
||||
ladspa_desc->set_run_adding_gain=NULL;
|
||||
ladspa_desc->deactivate=NULL;
|
||||
ladspa_desc->cleanup=ladex_cleanup;
|
||||
}
|
||||
|
|
33
ladex.h
33
ladex.h
|
@ -1,33 +0,0 @@
|
|||
#include<ladspa.h>
|
||||
#include<limits.h>
|
||||
#include<stdint.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
#ifndef __cplusplus
|
||||
# if __GNUC__
|
||||
# define ON_LOAD_ROUTINE static void __attribute__ ((constructor)) init()
|
||||
# define ON_UNLOAD_ROUTINE static void __attribute__ ((destructor)) fini()
|
||||
# else
|
||||
# define ON_LOAD_ROUTINE void init()
|
||||
# define ON_UNLOAD_ROUTINE void fini()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// The port numbers for the plugin:
|
||||
#define PORT_AMPLITUDE 0x0
|
||||
#define PORT_OUTPUT 0x1
|
||||
#define PORT_INPUT 0x2
|
||||
|
||||
// The structure used to hold port connection information (and gain if
|
||||
// runAdding() is in use) and state (actually there's no further state
|
||||
// to store here)
|
||||
typedef struct Ladex
|
||||
{
|
||||
LADSPA_Data*amp;
|
||||
LADSPA_Data*output;
|
||||
LADSPA_Data*input;
|
||||
LADSPA_Data runaddinggain;
|
||||
} Ladex;
|
||||
|
||||
const LADSPA_Descriptor*ladspa_descriptor(unsigned long index);
|
Loading…
Reference in New Issue
Block a user