-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheq.c
147 lines (115 loc) · 3.46 KB
/
eq.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
*
* postfish
*
* Copyright (C) 2002-2005 Monty and Xiph.Org
*
* Postfish 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, or (at your option)
* any later version.
*
* Postfish 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 Postfish; see the file COPYING. If not, write to the
* Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
*/
#include <sys/types.h>
#include "postfish.h"
#include "feedback.h"
#include "freq.h"
#include "eq.h"
typedef struct{
freq_state eq;
int ch;
} eq_state;
eq_settings eq_master_set;
eq_settings *eq_channel_set;
static freq_class_setup fc;
static eq_state master_state;
static eq_state channel_state;
/* accessed only in playback thread/setup */
int pull_eq_feedback_master(float **peak,float **rms){
return pull_freq_feedback(&master_state.eq,peak,rms);
}
int pull_eq_feedback_channel(float **peak,float **rms){
return pull_freq_feedback(&channel_state.eq,peak,rms);
}
/* called only by initial setup */
int eq_load(int outch){
int i;
eq_channel_set=calloc(input_ch,sizeof(*eq_channel_set));
freq_class_load(&fc,eq_freq_list,eq_freqs);
freq_load(&master_state.eq,&fc,outch);
master_state.ch=outch;
freq_load(&channel_state.eq,&fc,input_ch);
channel_state.ch=input_ch;
eq_master_set.curve_dirty=1;
for(i=0;i<input_ch;i++)
eq_channel_set[i].curve_dirty=1;
return 0;
}
/* called only in playback thread */
int eq_reset(){
freq_reset(&master_state.eq);
freq_reset(&channel_state.eq);
return 0;
}
void eq_set(eq_settings *set, int freq, float value){
set->settings[freq]=rint(value*10.);
set->curve_dirty=1;
}
static void workfunc(float *data, eq_settings *set){
int i,j;
if(set->curve_dirty || !set->curve_cache){
set->curve_dirty=0;
if(!set->curve_cache)
set->curve_cache=malloc((fc.qblocksize*2+1)*sizeof(*set->curve_cache));
memset(set->curve_cache,0,(fc.qblocksize*2+1)*sizeof(*set->curve_cache));
for(i=0;i<eq_freqs;i++){
float v=fromdB_a(set->settings[i]*.1);
for(j=0;j<fc.qblocksize*2+1;j++)
set->curve_cache[j]+=fc.ho_window[i][j]*v;
}
}
for(i=0;i<fc.qblocksize*2+1;i++){
data[i*2]*=set->curve_cache[i];
data[i*2+1]*=set->curve_cache[i];
}
return;
}
static void workfunc_ch(float *data, int ch){
workfunc(data,eq_channel_set+ch);
}
static void workfunc_m(float *data, int ch){
workfunc(data,&eq_master_set);
}
/* called only by playback thread */
time_linkage *eq_read_master(time_linkage *in){
eq_state *eq=&master_state;
int active[eq->ch];
int visible[eq->ch];
int i;
for(i=0;i<eq->ch;i++){
active[i]=eq_master_set.panel_active;
visible[i]=eq_master_set.panel_visible;
}
return freq_read(in,&master_state.eq,visible,active,workfunc_m);
}
time_linkage *eq_read_channel(time_linkage *in){
eq_state *eq=&channel_state;
int active[eq->ch];
int visible[eq->ch];
int i;
for(i=0;i<eq->ch;i++){
active[i]=eq_channel_set[i].panel_active;
visible[i]=eq_channel_set[i].panel_visible;
}
return freq_read(in,&channel_state.eq,visible,active,workfunc_ch);
}