forked from pingdynasty/MyPatches
/
gverbdsp.c
126 lines (101 loc) · 2.59 KB
/
gverbdsp.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
Copyright (C) 1999 Juhana Sadeharju
kouhia at nic.funet.fi
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "gverbdsp.h"
#include <string.h>
#define TRUE 1
#define FALSE 0
ty_diffuser *diffuser_make(int size, float coeff)
{
ty_diffuser *p;
int i;
p = (ty_diffuser *)malloc(sizeof(ty_diffuser));
p->size = size;
p->coeff = coeff;
p->idx = 0;
p->buf = (float *)malloc(size*sizeof(float));
for (i = 0; i < size; i++) p->buf[i] = 0.0;
return(p);
}
void diffuser_free(ty_diffuser *p)
{
free(p->buf);
free(p);
}
void diffuser_flush(ty_diffuser *p)
{
memset(p->buf, 0, p->size * sizeof(float));
}
ty_damper *damper_make(float damping)
{
ty_damper *p;
p = (ty_damper *)malloc(sizeof(ty_damper));
p->damping = damping;
p->delay = 0.0f;
return(p);
}
void damper_free(ty_damper *p)
{
free(p);
}
void damper_flush(ty_damper *p)
{
p->delay = 0.0f;
}
ty_fixeddelay *fixeddelay_make(int size)
{
ty_fixeddelay *p;
int i;
p = (ty_fixeddelay *)malloc(sizeof(ty_fixeddelay));
p->size = size;
p->idx = 0;
p->buf = (float *)malloc(size*sizeof(float));
for (i = 0; i < size; i++) p->buf[i] = 0.0;
return(p);
}
void fixeddelay_free(ty_fixeddelay *p)
{
free(p->buf);
free(p);
}
void fixeddelay_flush(ty_fixeddelay *p)
{
memset(p->buf, 0, p->size * sizeof(float));
}
int isprime(int n)
{
unsigned int i;
const unsigned int lim = (int)sqrtf((float)n);
if (n == 2) return(TRUE);
if ((n & 1) == 0) return(FALSE);
for(i = 3; i <= lim; i += 2)
if ((n % i) == 0) return(FALSE);
return(TRUE);
}
int nearest_prime(int n, float rerror)
/* relative error; new prime will be in range
* [n-n*rerror, n+n*rerror];
*/
{
int bound,k;
if (isprime(n)) return(n);
/* assume n is large enough and n*rerror enough smaller than n */
bound = n*rerror;
for(k = 1; k <= bound; k++) {
if (isprime(n+k)) return(n+k);
if (isprime(n-k)) return(n-k);
}
return(-1);
}