-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathport.c
64 lines (53 loc) · 1.14 KB
/
port.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Port
*
* This code has been extracted from the Csound opcode "portk".
* It has been modified to work as a Soundpipe module.
*
* Original Author(s): Robbin Whittle, John ffitch
* Year: 1995, 1998
* Location: Opcodes/biquad.c
*
*/
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#define ROOT2 (1.4142135623730950488)
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "soundpipe.h"
int sp_port_create(sp_port **p)
{
*p = malloc(sizeof(sp_port));
return SP_OK;
}
int sp_port_destroy(sp_port **p)
{
free(*p);
return SP_OK;
}
int sp_port_init(sp_data *sp, sp_port *p, SPFLOAT htime)
{
p->yt1 = 0;
p->prvhtim = -100.0;
p->htime = htime;
p->sr = sp->sr;
p->onedsr = 1.0/p->sr;
return SP_OK;
}
int sp_port_compute(sp_data *sp, sp_port *p, SPFLOAT *in, SPFLOAT *out)
{
if(p->prvhtim != p->htime){
p->c2 = pow(0.5, p->onedsr / p->htime);
p->c1 = 1.0 - p->c2;
p->prvhtim = p->htime;
}
*out = p->yt1 = p->c1 * *in + p->c2 * p->yt1;
return SP_OK;
}
int sp_port_reset(sp_data *sp, sp_port *p, SPFLOAT *in)
{
p->yt1 = *in;
return SP_OK;
}