Revert previous commit, was incorrect
[amarok.git] / src / engine / helix / helix-sp / hsphook.h
blob6983124f8ffe373fee1f553d44a9d97d88bca719
1 /* **********
3 * This software is released under the provisions of the GPL version 2.
4 * see file "COPYING". If that file is not available, the full statement
5 * of the license can be found at
7 * http://www.fsf.org/licensing/licenses/gpl.txt
9 * Copyright (c) Paul Cifarelli 2005
10 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
11 * PCM time-domain equalizer:
12 * (c) 2002 Felipe Rivera <liebremx at users sourceforge net>
13 * (c) 2004 Mark Kretschmann <markey@web.de>
15 * ********** */
16 #ifndef _HSPHOOK_H_INCLUDED_
17 #define _HSPHOOK_H_INCLUDED_
19 struct GAIN_STATE;
21 #define FADE_MIN_dB -120
23 class HSPPreMixAudioHook : public IHXAudioHook
25 public:
26 HSPPreMixAudioHook(HelixSimplePlayer *player, int playerIndex, IHXAudioStream *pAudioStream,
27 bool fadein = false, unsigned long fadelength = 0);
28 virtual ~HSPPreMixAudioHook();
30 * IUnknown methods
32 STDMETHOD(QueryInterface) (THIS_
33 REFIID riid,
34 void** ppvObj);
35 STDMETHOD_(ULONG32,AddRef) (THIS);
36 STDMETHOD_(ULONG32,Release) (THIS);
38 * IHXAudioHook methods
40 STDMETHOD(OnBuffer) (THIS_
41 HXAudioData *pAudioInData,
42 HXAudioData *pAudioOutData);
43 STDMETHOD(OnInit) (THIS_
44 HXAudioFormat *pFormat);
46 void setFadeout(bool fadeout);
47 void setFadelength(unsigned long fadelength) { m_fadelength = fadelength; }
49 private:
50 HSPPreMixAudioHook();
52 HelixSimplePlayer *m_Player;
53 LONG32 m_lRefCount;
54 int m_index;
55 IHXAudioStream *m_stream;
56 HXAudioFormat m_format;
57 int m_count;
59 GAIN_STATE *m_gaintool;
60 float m_gaindb;
61 bool m_fadein;
62 bool m_fadeout;
63 unsigned long m_fadelength;
65 int volumeize(unsigned char *data, unsigned char *outbuf, size_t len);
70 #define BAND_NUM 10
71 #define EQ_MAX_BANDS 10
72 #define EQ_CHANNELS 2 // Helix DNA currently only supports stereo
74 // Floating point
75 typedef struct
77 float beta;
78 float alpha;
79 float gamma;
80 } sIIRCoefficients;
82 /* Coefficient history for the IIR filter */
83 typedef struct
85 float x[3]; /* x[n], x[n-1], x[n-2] */
86 float y[3]; /* y[n], y[n-1], y[n-2] */
87 } sXYData;
90 struct DelayQueue;
92 class HSPPostProcessor : public IHXAudioHook
94 public:
95 HSPPostProcessor(HelixSimplePlayer *player, int playerIndex);
96 virtual ~HSPPostProcessor();
98 * IUnknown methods
100 STDMETHOD(QueryInterface) (THIS_
101 REFIID riid,
102 void** ppvObj);
103 STDMETHOD_(ULONG32,AddRef) (THIS);
104 STDMETHOD_(ULONG32,Release) (THIS);
106 * IHXAudioHook methods
108 STDMETHOD(OnBuffer) (THIS_
109 HXAudioData *pAudioInData,
110 HXAudioData *pAudioOutData);
111 STDMETHOD(OnInit) (THIS_
112 HXAudioFormat *pFormat);
114 void updateEQgains(int preamp, vector<int> &equalizerGains);
116 void scopeify(unsigned long time, unsigned char *data, size_t len);
118 #ifndef HELIX_SW_VOLUME_INTERFACE
119 void setGain(int volume);
120 #endif
122 void setIndex(int playerIndex) { m_index = playerIndex; }
124 private:
125 HSPPostProcessor();
127 void equalize(unsigned char *datain, unsigned char *dataout, size_t len);
128 #ifndef HELIX_SW_VOLUME_INTERFACE
129 int volumeize(unsigned char *data, size_t len);
130 int volumeize(unsigned char *data, unsigned char *outbuf, size_t len);
131 // returns samples (not bytes)
132 int unpack(unsigned char *data, size_t len, /*out*/ INT32 *signal);
133 // returns bytes (siglen is in samples)
134 int pack(INT32 *signal, size_t siglen, /*out*/ unsigned char *data);
135 #endif
137 HelixSimplePlayer *m_Player;
138 LONG32 m_lRefCount;
139 int m_index;
140 HXAudioFormat m_format;
141 int m_count;
143 // scope
144 struct DelayQueue *m_item;
145 int m_current;
146 unsigned long m_prevtime;
148 // equalizer
150 // Gain for each band
151 // values should be between -0.2 and 1.0
152 float gain[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned));
153 // Volume gain
154 // values should be between 0.0 and 1.0
155 float preamp[EQ_CHANNELS] __attribute__((aligned));
156 // Coefficients
157 sIIRCoefficients* iir_cf;
158 sXYData data_history[EQ_MAX_BANDS][EQ_CHANNELS] __attribute__((aligned));
159 // history indices
160 int m_i;
161 int m_j;
162 int m_k;
164 #ifndef HELIX_SW_VOLUME_INTERFACE
165 // volume stuff
166 GAIN_STATE *m_gaintool;
167 float m_gaindB;
168 #endif
172 class HSPPostMixAudioHook : public IHXAudioHook
174 public:
175 HSPPostMixAudioHook(HelixSimplePlayer *player, int playerIndex);
176 virtual ~HSPPostMixAudioHook();
178 * IUnknown methods
180 STDMETHOD(QueryInterface) (THIS_
181 REFIID riid,
182 void** ppvObj);
183 STDMETHOD_(ULONG32,AddRef) (THIS);
184 STDMETHOD_(ULONG32,Release) (THIS);
186 * IHXAudioHook methods
188 STDMETHOD(OnBuffer) (THIS_
189 HXAudioData *pAudioInData,
190 HXAudioData *pAudioOutData);
191 STDMETHOD(OnInit) (THIS_
192 HXAudioFormat *pFormat);
194 void updateEQgains(int preamp, vector<int> &equalizerGains);
196 #ifndef HELIX_SW_VOLUME_INTERFACE
197 void setGain(int volume);
198 #endif
200 private:
201 HSPPostMixAudioHook();
203 HelixSimplePlayer *m_Player;
204 int m_index;
205 LONG32 m_lRefCount;
207 HSPPostProcessor *m_processor;
211 class HSPFinalAudioHook : public IHXAudioHook
213 public:
214 HSPFinalAudioHook(HelixSimplePlayer *player);
215 virtual ~HSPFinalAudioHook();
217 * IUnknown methods
219 STDMETHOD(QueryInterface) (THIS_
220 REFIID riid,
221 void** ppvObj);
222 STDMETHOD_(ULONG32,AddRef) (THIS);
223 STDMETHOD_(ULONG32,Release) (THIS);
225 * IHXAudioHook methods
227 STDMETHOD(OnBuffer) (THIS_
228 HXAudioData *pAudioInData,
229 HXAudioData *pAudioOutData);
230 STDMETHOD(OnInit) (THIS_
231 HXAudioFormat *pFormat);
234 void updateEQgains(int preamp, vector<int> &equalizerGains);
236 #ifndef HELIX_SW_VOLUME_INTERFACE
237 void setGain(int volume);
238 #endif
240 private:
241 HSPFinalAudioHook();
243 HelixSimplePlayer *m_Player;
244 LONG32 m_lRefCount;
246 HSPPostProcessor *m_processor;
250 #endif