Recognizes if input is ogg or not.
[xiph.git] / postfish / eq.c
blobe812243f685b4b4d6ef09f95eea828c9bf1f4b92
1 /*
3 * postfish
4 *
5 * Copyright (C) 2002-2005 Monty and Xiph.Org
7 * Postfish is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * Postfish is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Postfish; see the file COPYING. If not, write to the
19 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <sys/types.h>
25 #include "postfish.h"
26 #include "feedback.h"
27 #include "freq.h"
28 #include "eq.h"
30 typedef struct{
32 freq_state eq;
33 int ch;
35 } eq_state;
37 eq_settings eq_master_set;
38 eq_settings *eq_channel_set;
40 static freq_class_setup fc;
41 static eq_state master_state;
42 static eq_state channel_state;
44 /* accessed only in playback thread/setup */
45 int pull_eq_feedback_master(float **peak,float **rms){
46 return pull_freq_feedback(&master_state.eq,peak,rms);
49 int pull_eq_feedback_channel(float **peak,float **rms){
50 return pull_freq_feedback(&channel_state.eq,peak,rms);
53 /* called only by initial setup */
54 int eq_load(int outch){
55 int i;
57 eq_channel_set=calloc(input_ch,sizeof(*eq_channel_set));
59 freq_class_load(&fc,eq_freq_list,eq_freqs);
61 freq_load(&master_state.eq,&fc,outch);
62 master_state.ch=outch;
63 freq_load(&channel_state.eq,&fc,input_ch);
64 channel_state.ch=input_ch;
66 eq_master_set.curve_dirty=1;
68 for(i=0;i<input_ch;i++)
69 eq_channel_set[i].curve_dirty=1;
71 return 0;
74 /* called only in playback thread */
75 int eq_reset(){
76 freq_reset(&master_state.eq);
77 freq_reset(&channel_state.eq);
78 return 0;
81 void eq_set(eq_settings *set, int freq, float value){
82 set->settings[freq]=rint(value*10.);
83 set->curve_dirty=1;
86 static void workfunc(float *data, eq_settings *set){
87 int i,j;
89 if(set->curve_dirty || !set->curve_cache){
90 set->curve_dirty=0;
92 if(!set->curve_cache)
93 set->curve_cache=malloc((fc.qblocksize*2+1)*sizeof(*set->curve_cache));
94 memset(set->curve_cache,0,(fc.qblocksize*2+1)*sizeof(*set->curve_cache));
96 for(i=0;i<eq_freqs;i++){
97 float v=fromdB_a(set->settings[i]*.1);
98 for(j=0;j<fc.qblocksize*2+1;j++)
99 set->curve_cache[j]+=fc.ho_window[i][j]*v;
103 for(i=0;i<fc.qblocksize*2+1;i++){
104 data[i*2]*=set->curve_cache[i];
105 data[i*2+1]*=set->curve_cache[i];
108 return;
111 static void workfunc_ch(float *data, int ch){
112 workfunc(data,eq_channel_set+ch);
115 static void workfunc_m(float *data, int ch){
116 workfunc(data,&eq_master_set);
119 /* called only by playback thread */
120 time_linkage *eq_read_master(time_linkage *in){
121 eq_state *eq=&master_state;
122 int active[eq->ch];
123 int visible[eq->ch];
124 int i;
126 for(i=0;i<eq->ch;i++){
127 active[i]=eq_master_set.panel_active;
128 visible[i]=eq_master_set.panel_visible;
131 return freq_read(in,&master_state.eq,visible,active,workfunc_m);
134 time_linkage *eq_read_channel(time_linkage *in){
135 eq_state *eq=&channel_state;
136 int active[eq->ch];
137 int visible[eq->ch];
138 int i;
140 for(i=0;i<eq->ch;i++){
141 active[i]=eq_channel_set[i].panel_active;
142 visible[i]=eq_channel_set[i].panel_visible;
145 return freq_read(in,&channel_state.eq,visible,active,workfunc_ch);