-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvdc.h
167 lines (153 loc) · 4.66 KB
/
vdc.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef GST_PLUGIN_VIPERDDC_VDC_H
#define GST_PLUGIN_VIPERDDC_VDC_H
/**
The contents of this file are based on James34602's open-source version of JamesDSP
This code is also used in JDSP4Linux.
https://github.com/james34602/JamesDSPManager/blob/master/Open_source_edition/Audio_Engine/eclipse_libjamesdsp_free_bp/jni/vdc.h
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
**/
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
typedef struct
{
double b0, b1, b2, a1, a2;
double v1L, v2L, v1R, v2R; // State
} DirectForm2;
void SOS_DF2_Float_StereoProcess(DirectForm2 *df2, double x1, double x2, float *Out_y1, float *Out_y2)
{
double w1 = x1 - df2->a1*df2->v1L - df2->a2*df2->v2L;
double y1 = df2->b0*w1 + df2->b1*df2->v1L + df2->b2*df2->v2L;
df2->v2L = df2->v1L;
df2->v1L = w1;
*Out_y1 = y1;
double w2 = x2 - df2->a1*df2->v1R - df2->a2*df2->v2R;
double y2 = df2->b0*w2 + df2->b1*df2->v1R + df2->b2*df2->v2R;
df2->v2R = df2->v1R;
df2->v1R = w2;
*Out_y2 = y2;
}
int countChars(char* s, char c)
{
int res = 0;
if(s == NULL){
return 0;
}
for (int i=0;i<strlen(s);i++)
if (s[i] == c)
res++;
return res;
}
int get_doubleVDC(char *val, double *F)
{
char *eptr;
errno = 0;
char *data = strdup(val);
double f = strtod(data, &eptr);
if (eptr != data && errno != ERANGE)
{
*F = f;
if(data != NULL) {
free(data);
}
return 1;
}
if(data != NULL) {
free(data);
}
return 0;
}
int DDCParser(char *DDCString, DirectForm2 ***ptrdf441, DirectForm2 ***ptrdf48)
{
char *fs44_1 = strstr(DDCString, "SR_44100");
char *fs48 = strstr(DDCString, "SR_48000");
int numberCount = (countChars(fs48, ',') + 1);
int sosCount = numberCount / 5;
DirectForm2 **df441 = (DirectForm2**)malloc(sosCount * sizeof(DirectForm2*));
DirectForm2 **df48 = (DirectForm2**)malloc(sosCount * sizeof(DirectForm2*));
int i;
for (i = 0; i < sosCount; i++)
{
df441[i] = (DirectForm2*)malloc(sizeof(DirectForm2));
memset(df441[i], 0, sizeof(DirectForm2));
df48[i] = (DirectForm2*)malloc(sizeof(DirectForm2));
memset(df48[i], 0, sizeof(DirectForm2));
}
double number;
i = 0;
int counter = 0;
int b0b1b2a1a2 = 0;
char *startingPoint = fs44_1 + 9;
while (counter < numberCount)
{
if (get_doubleVDC(startingPoint, &number))
{
double val = strtod(startingPoint, &startingPoint);
counter++;
if (!b0b1b2a1a2)
df441[i]->b0 = val;
else if (b0b1b2a1a2 == 1)
df441[i]->b1 = val;
else if (b0b1b2a1a2 == 2)
df441[i]->b2 = val;
else if (b0b1b2a1a2 == 3)
df441[i]->a1 = -val;
else if (b0b1b2a1a2 == 4)
{
df441[i]->a2 = -val;
i++;
}
b0b1b2a1a2++;
if (b0b1b2a1a2 == 5)
b0b1b2a1a2 = 0;
}
else
startingPoint++;
}
i = 0;
counter = 0;
b0b1b2a1a2 = 0;
startingPoint = fs48 + 9;
while (counter < numberCount)
{
if (get_doubleVDC(startingPoint, &number))
{
double val = strtod(startingPoint, &startingPoint);
counter++;
if (!b0b1b2a1a2)
df48[i]->b0 = val;
else if (b0b1b2a1a2 == 1)
df48[i]->b1 = val;
else if (b0b1b2a1a2 == 2)
df48[i]->b2 = val;
else if (b0b1b2a1a2 == 3)
df48[i]->a1 = -val;
else if (b0b1b2a1a2 == 4)
{
df48[i]->a2 = -val;
i++;
}
b0b1b2a1a2++;
if (b0b1b2a1a2 == 5)
b0b1b2a1a2 = 0;
}
else
startingPoint++;
}
*ptrdf441 = df441;
*ptrdf48 = df48;
return sosCount;
}
#endif //GST_PLUGIN_VIPERDDC_VDC_H