GCC Code Coverage Report


Directory: avs_core/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 60.0% 18 / 0 / 30
Functions: 75.0% 6 / 0 / 8
Branches: 58.3% 14 / 0 / 24

core/audio.h
Line Branch Exec Source
1 // Avisynth v2.5. Copyright 2002 Ben Rudiak-Gould et al.
2 // http://avisynth.nl
3
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA, or visit
17 // http://www.gnu.org/copyleft/gpl.html .
18 //
19 // Linking Avisynth statically or dynamically with other modules is making a
20 // combined work based on Avisynth. Thus, the terms and conditions of the GNU
21 // General Public License cover the whole combination.
22 //
23 // As a special exception, the copyright holders of Avisynth give you
24 // permission to link Avisynth with independent modules that communicate with
25 // Avisynth solely through the interfaces defined in avisynth.h, regardless of the license
26 // terms of these independent modules, and to copy and distribute the
27 // resulting combined work under terms of your choice, provided that
28 // every copy of the combined work is accompanied by a complete copy of
29 // the source code of Avisynth (the version of Avisynth used to produce the
30 // combined work), being distributed under the terms of the GNU General
31 // Public License plus this exception. An independent module is a module
32 // which is not derived from or based on Avisynth, such as 3rd-party filters,
33 // import and export plugins, or graphical user interfaces.
34 #ifndef __Audio_H__
35 #define __Audio_H__
36
37 #include <avisynth.h>
38 #include <cmath>
39
40 // ------- Channels, only 0..17, SPEAKER_ALL not handled here
41 enum AVSChannel {
42 AVS_CHAN_IDX_NONE = -1, // Invalid channel index
43 AVS_CHAN_IDX_FRONT_LEFT,
44 AVS_CHAN_IDX_FRONT_RIGHT,
45 AVS_CHAN_IDX_FRONT_CENTER,
46 AVS_CHAN_IDX_LOW_FREQUENCY,
47 AVS_CHAN_IDX_BACK_LEFT,
48 AVS_CHAN_IDX_BACK_RIGHT,
49 AVS_CHAN_IDX_FRONT_LEFT_OF_CENTER,
50 AVS_CHAN_IDX_FRONT_RIGHT_OF_CENTER,
51 AVS_CHAN_IDX_BACK_CENTER,
52 AVS_CHAN_IDX_SIDE_LEFT,
53 AVS_CHAN_IDX_SIDE_RIGHT,
54 AVS_CHAN_IDX_TOP_CENTER,
55 AVS_CHAN_IDX_TOP_FRONT_LEFT,
56 AVS_CHAN_IDX_TOP_FRONT_CENTER,
57 AVS_CHAN_IDX_TOP_FRONT_RIGHT,
58 AVS_CHAN_IDX_TOP_BACK_LEFT,
59 AVS_CHAN_IDX_TOP_BACK_CENTER,
60 AVS_CHAN_IDX_TOP_BACK_RIGHT
61 };
62
63 // similarly to ffmpeg
64 #define AVS_CHANNEL_LAYOUT_MONO (AvsChannelMask::MASK_SPEAKER_FRONT_CENTER)
65 #define AVS_CHANNEL_LAYOUT_STEREO (AvsChannelMask::MASK_SPEAKER_FRONT_LEFT|AvsChannelMask::MASK_SPEAKER_FRONT_RIGHT)
66 #define AVS_CHANNEL_LAYOUT_2POINT1 (AVS_CHANNEL_LAYOUT_STEREO|AvsChannelMask::MASK_SPEAKER_LOW_FREQUENCY)
67 #define AVS_CHANNEL_LAYOUT_2_1 (AVS_CHANNEL_LAYOUT_STEREO|AvsChannelMask::MASK_SPEAKER_BACK_CENTER)
68 #define AVS_CHANNEL_LAYOUT_SURROUND (AVS_CHANNEL_LAYOUT_STEREO|AvsChannelMask::MASK_SPEAKER_FRONT_CENTER)
69 #define AVS_CHANNEL_LAYOUT_3POINT1 (AVS_CHANNEL_LAYOUT_SURROUND|AvsChannelMask::MASK_SPEAKER_LOW_FREQUENCY)
70 #define AVS_CHANNEL_LAYOUT_4POINT0 (AVS_CHANNEL_LAYOUT_SURROUND|AvsChannelMask::MASK_SPEAKER_BACK_CENTER)
71 #define AVS_CHANNEL_LAYOUT_4POINT1 (AVS_CHANNEL_LAYOUT_4POINT0|AvsChannelMask::MASK_SPEAKER_LOW_FREQUENCY)
72 #define AVS_CHANNEL_LAYOUT_2_2 (AVS_CHANNEL_LAYOUT_STEREO|AvsChannelMask::MASK_SPEAKER_SIDE_LEFT|AvsChannelMask::MASK_SPEAKER_SIDE_RIGHT)
73 #define AVS_CHANNEL_LAYOUT_QUAD (AVS_CHANNEL_LAYOUT_STEREO|AvsChannelMask::MASK_SPEAKER_BACK_LEFT|AvsChannelMask::MASK_SPEAKER_BACK_RIGHT)
74 #define AVS_CHANNEL_LAYOUT_5POINT0 (AVS_CHANNEL_LAYOUT_SURROUND|AvsChannelMask::MASK_SPEAKER_SIDE_LEFT|AvsChannelMask::MASK_SPEAKER_SIDE_RIGHT)
75 #define AVS_CHANNEL_LAYOUT_5POINT1 (AVS_CHANNEL_LAYOUT_5POINT0|AvsChannelMask::MASK_SPEAKER_LOW_FREQUENCY)
76 #define AVS_CHANNEL_LAYOUT_5POINT0_BACK (AVS_CHANNEL_LAYOUT_SURROUND|AvsChannelMask::MASK_SPEAKER_BACK_LEFT|AvsChannelMask::MASK_SPEAKER_BACK_RIGHT)
77 #define AVS_CHANNEL_LAYOUT_5POINT1_BACK (AVS_CHANNEL_LAYOUT_5POINT0_BACK|AvsChannelMask::MASK_SPEAKER_LOW_FREQUENCY)
78 #define AVS_CHANNEL_LAYOUT_6POINT0 (AVS_CHANNEL_LAYOUT_5POINT0|AvsChannelMask::MASK_SPEAKER_BACK_CENTER)
79 #define AVS_CHANNEL_LAYOUT_6POINT0_FRONT (AVS_CHANNEL_LAYOUT_2_2|AvsChannelMask::MASK_SPEAKER_FRONT_LEFT_OF_CENTER|AvsChannelMask::MASK_SPEAKER_FRONT_RIGHT_OF_CENTER)
80 #define AVS_CHANNEL_LAYOUT_HEXAGONAL (AVS_CHANNEL_LAYOUT_5POINT0_BACK|AvsChannelMask::MASK_SPEAKER_BACK_CENTER)
81 #define AVS_CHANNEL_LAYOUT_6POINT1 (AVS_CHANNEL_LAYOUT_5POINT1|AvsChannelMask::MASK_SPEAKER_BACK_CENTER)
82 #define AVS_CHANNEL_LAYOUT_6POINT1_BACK (AVS_CHANNEL_LAYOUT_5POINT1_BACK|AvsChannelMask::MASK_SPEAKER_BACK_CENTER)
83 #define AVS_CHANNEL_LAYOUT_6POINT1_FRONT (AVS_CHANNEL_LAYOUT_6POINT0_FRONT|AvsChannelMask::MASK_SPEAKER_LOW_FREQUENCY)
84 #define AVS_CHANNEL_LAYOUT_7POINT0 (AVS_CHANNEL_LAYOUT_5POINT0|AvsChannelMask::MASK_SPEAKER_BACK_LEFT|AvsChannelMask::MASK_SPEAKER_BACK_RIGHT)
85 #define AVS_CHANNEL_LAYOUT_7POINT0_FRONT (AVS_CHANNEL_LAYOUT_5POINT0|AvsChannelMask::MASK_SPEAKER_FRONT_LEFT_OF_CENTER|AvsChannelMask::MASK_SPEAKER_FRONT_RIGHT_OF_CENTER)
86 #define AVS_CHANNEL_LAYOUT_7POINT1 (AVS_CHANNEL_LAYOUT_5POINT1|AvsChannelMask::MASK_SPEAKER_BACK_LEFT|AvsChannelMask::MASK_SPEAKER_BACK_RIGHT)
87 #define AVS_CHANNEL_LAYOUT_7POINT1_WIDE (AVS_CHANNEL_LAYOUT_5POINT1|AvsChannelMask::MASK_SPEAKER_FRONT_LEFT_OF_CENTER|AvsChannelMask::MASK_SPEAKER_FRONT_RIGHT_OF_CENTER)
88 #define AVS_CHANNEL_LAYOUT_7POINT1_WIDE_BACK (AVS_CHANNEL_LAYOUT_5POINT1_BACK|AvsChannelMask::MASK_SPEAKER_FRONT_LEFT_OF_CENTER|AvsChannelMask::MASK_SPEAKER_FRONT_RIGHT_OF_CENTER)
89 #define AVS_CHANNEL_LAYOUT_7POINT1_TOP_BACK (AVS_CHANNEL_LAYOUT_5POINT1_BACK|AvsChannelMask::MASK_SPEAKER_TOP_FRONT_LEFT|AvsChannelMask::MASK_SPEAKER_TOP_FRONT_RIGHT)
90 #define AVS_CHANNEL_LAYOUT_OCTAGONAL (AVS_CHANNEL_LAYOUT_5POINT0|AvsChannelMask::MASK_SPEAKER_BACK_LEFT|AvsChannelMask::MASK_SPEAKER_BACK_CENTER|AvsChannelMask::MASK_SPEAKER_BACK_RIGHT)
91 #define AVS_CHANNEL_LAYOUT_CUBE (AVS_CHANNEL_LAYOUT_QUAD|AvsChannelMask::MASK_SPEAKER_TOP_FRONT_LEFT|AvsChannelMask::MASK_SPEAKER_TOP_FRONT_RIGHT|AvsChannelMask::MASK_SPEAKER_TOP_BACK_LEFT|AvsChannelMask::MASK_SPEAKER_TOP_BACK_RIGHT)
92 //#define AVS_CHANNEL_LAYOUT_HEXADECAGONAL (AVS_CHANNEL_LAYOUT_OCTAGONAL|AvsChannelMask::MASK_SPEAKER_WIDE_LEFT|AvsChannelMask::MASK_SPEAKER_WIDE_RIGHT|AvsChannelMask::MASK_SPEAKER_TOP_BACK_LEFT|AvsChannelMask::MASK_SPEAKER_TOP_BACK_RIGHT|AvsChannelMask::MASK_SPEAKER_TOP_BACK_CENTER|AvsChannelMask::MASK_SPEAKER_TOP_FRONT_CENTER|AvsChannelMask::MASK_SPEAKER_TOP_FRONT_LEFT|AvsChannelMask::MASK_SPEAKER_TOP_FRONT_RIGHT)
93 //#define AVS_CHANNEL_LAYOUT_STEREO_DOWNMIX (AvsChannelMask::MASK_SPEAKER_STEREO_LEFT|AvsChannelMask::MASK_SPEAKER_STEREO_RIGHT)
94
95 typedef struct ChannelLayoutDescriptor_t {
96 int nb_channels;
97 unsigned int mask;
98 } ChannelLayoutDescriptor_t;
99
100 #define AVS_CHANNEL_LAYOUT_MASK(nb, m) \
101 { (nb), (m) }
102
103 // Common pre-defined channel layouts
104 #define AVS_CHANNEL_LAYOUT_MASK_MONO AVS_CHANNEL_LAYOUT_MASK(1, AVS_CHANNEL_LAYOUT_MONO)
105 #define AVS_CHANNEL_LAYOUT_MASK_STEREO AVS_CHANNEL_LAYOUT_MASK(2, AVS_CHANNEL_LAYOUT_STEREO)
106 #define AVS_CHANNEL_LAYOUT_MASK_2POINT1 AVS_CHANNEL_LAYOUT_MASK(3, AVS_CHANNEL_LAYOUT_2POINT1)
107 #define AVS_CHANNEL_LAYOUT_MASK_2_1 AVS_CHANNEL_LAYOUT_MASK(3, AVS_CHANNEL_LAYOUT_2_1)
108 #define AVS_CHANNEL_LAYOUT_MASK_SURROUND AVS_CHANNEL_LAYOUT_MASK(3, AVS_CHANNEL_LAYOUT_SURROUND)
109 #define AVS_CHANNEL_LAYOUT_MASK_3POINT1 AVS_CHANNEL_LAYOUT_MASK(4, AVS_CHANNEL_LAYOUT_3POINT1)
110 #define AVS_CHANNEL_LAYOUT_MASK_4POINT0 AVS_CHANNEL_LAYOUT_MASK(4, AVS_CHANNEL_LAYOUT_4POINT0)
111 #define AVS_CHANNEL_LAYOUT_MASK_4POINT1 AVS_CHANNEL_LAYOUT_MASK(5, AVS_CHANNEL_LAYOUT_4POINT1)
112 #define AVS_CHANNEL_LAYOUT_MASK_2_2 AVS_CHANNEL_LAYOUT_MASK(4, AVS_CHANNEL_LAYOUT_2_2)
113 #define AVS_CHANNEL_LAYOUT_MASK_QUAD AVS_CHANNEL_LAYOUT_MASK(4, AVS_CHANNEL_LAYOUT_QUAD)
114 #define AVS_CHANNEL_LAYOUT_MASK_5POINT0 AVS_CHANNEL_LAYOUT_MASK(5, AVS_CHANNEL_LAYOUT_5POINT0)
115 #define AVS_CHANNEL_LAYOUT_MASK_5POINT1 AVS_CHANNEL_LAYOUT_MASK(6, AVS_CHANNEL_LAYOUT_5POINT1)
116 #define AVS_CHANNEL_LAYOUT_MASK_5POINT0_BACK AVS_CHANNEL_LAYOUT_MASK(5, AVS_CHANNEL_LAYOUT_5POINT0_BACK)
117 #define AVS_CHANNEL_LAYOUT_MASK_5POINT1_BACK AVS_CHANNEL_LAYOUT_MASK(6, AVS_CHANNEL_LAYOUT_5POINT1_BACK)
118 #define AVS_CHANNEL_LAYOUT_MASK_6POINT0 AVS_CHANNEL_LAYOUT_MASK(6, AVS_CHANNEL_LAYOUT_6POINT0)
119 #define AVS_CHANNEL_LAYOUT_MASK_6POINT0_FRONT AVS_CHANNEL_LAYOUT_MASK(6, AVS_CHANNEL_LAYOUT_6POINT0_FRONT)
120 #define AVS_CHANNEL_LAYOUT_MASK_HEXAGONAL AVS_CHANNEL_LAYOUT_MASK(6, AVS_CHANNEL_LAYOUT_HEXAGONAL)
121 #define AVS_CHANNEL_LAYOUT_MASK_6POINT1 AVS_CHANNEL_LAYOUT_MASK(7, AVS_CHANNEL_LAYOUT_6POINT1)
122 #define AVS_CHANNEL_LAYOUT_MASK_6POINT1_BACK AVS_CHANNEL_LAYOUT_MASK(7, AVS_CHANNEL_LAYOUT_6POINT1_BACK)
123 #define AVS_CHANNEL_LAYOUT_MASK_6POINT1_FRONT AVS_CHANNEL_LAYOUT_MASK(7, AVS_CHANNEL_LAYOUT_6POINT1_FRONT)
124 #define AVS_CHANNEL_LAYOUT_MASK_7POINT0 AVS_CHANNEL_LAYOUT_MASK(7, AVS_CHANNEL_LAYOUT_7POINT0)
125 #define AVS_CHANNEL_LAYOUT_MASK_7POINT0_FRONT AVS_CHANNEL_LAYOUT_MASK(7, AVS_CHANNEL_LAYOUT_7POINT0_FRONT)
126 #define AVS_CHANNEL_LAYOUT_MASK_7POINT1 AVS_CHANNEL_LAYOUT_MASK(8, AVS_CHANNEL_LAYOUT_7POINT1)
127 #define AVS_CHANNEL_LAYOUT_MASK_7POINT1_WIDE AVS_CHANNEL_LAYOUT_MASK(8, AVS_CHANNEL_LAYOUT_7POINT1_WIDE)
128 #define AVS_CHANNEL_LAYOUT_MASK_7POINT1_WIDE_BACK AVS_CHANNEL_LAYOUT_MASK(8, AVS_CHANNEL_LAYOUT_7POINT1_WIDE_BACK)
129 #define AVS_CHANNEL_LAYOUT_MASK_7POINT1_TOP_BACK AVS_CHANNEL_LAYOUT_MASK(8, AVS_CHANNEL_LAYOUT_7POINT1_TOP_BACK)
130 #define AVS_CHANNEL_LAYOUT_MASK_OCTAGONAL AVS_CHANNEL_LAYOUT_MASK(8, AVS_CHANNEL_LAYOUT_OCTAGONAL)
131 #define AVS_CHANNEL_LAYOUT_MASK_CUBE AVS_CHANNEL_LAYOUT_MASK(8, AVS_CHANNEL_LAYOUT_CUBE)
132 //#define AVS_CHANNEL_LAYOUT_MASK_HEXADECAGONAL AVS_CHANNEL_LAYOUT_MASK(16, AVS_CHANNEL_LAYOUT_HEXADECAGONAL)
133
134 unsigned int av_get_channel_layout(const char* name);
135 unsigned int GetDefaultChannelLayout(int nChannels);
136 std::string channel_layout_to_str(const unsigned int channel_layout_mask);
137
138 /******* Helper stuff *******/
139
140 #define MAX_SHORT (32767)
141 #define MIN_SHORT (-32768)
142
143
144 /* Conversion constants */ // We are using fixed point binary arithmetic here
145 #define Nhc 8 // Number of bits for filter points
146 #define Na 7 // Number of bits for interpolating between filter points
147 #define Np (Nhc+Na) // Total number of bits to represent fractional phase
148 #define Npc (1<<Nhc) // Sampling period binary point scaling factor
149 #define Amask ((1<<Na)-1) // Interpolation mask
150 #define Pmask ((1<<Np)-1) // Phase mask
151 #define Nh 16 // Number of bits to represent coefficients
152 #define Nb 16 // Unused
153 #define Nhxn 14 // Number of non-guard bits
154 #define Nhg (Nh-Nhxn) // Number of guard bits
155 #define NLpScl 13 // Number of overflow bits
156
157
158 #define IzeroEPSILON 1E-21 /* Max error acceptable in Izero */
159
160 static constexpr double PI = 3.14159265358979323846;
161
162 24 static __inline short IntToShort(int v, const int scl)
163 {
164 24 v += (1<<(scl-1)); /* round */
165 24 v >>= scl;
166
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 24 times.
24 if (v>MAX_SHORT)
167 return MAX_SHORT;
168
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 24 times.
24 else if (v < MIN_SHORT)
169 return MIN_SHORT;
170 else
171 24 return (short)v;
172 }
173
174 static double Izero(double x);
175 static void LpFilter(double c[], int N, double frq, double Beta, int Num);
176 static int makeFilter(short Imp[], double &dLpScl, unsigned short Nwing, double Froll, double Beta);
177 static int makeFilter(SFLOAT fImp[], double dLpScl, unsigned short Nwing, double Froll, double Beta);
178
179
180 /********************************************************************
181 ********************************************************************/
182
183 class AssumeRate : public NonCachedGenericVideoFilter
184 /**
185 * Changes the sample rate of a clip
186 **/
187 {
188 public:
189 AssumeRate(PClip _clip, int _rate);
190 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment*);
191 };
192
193
194
195 class ConvertToMono : public GenericVideoFilter
196 /**
197 * Class to convert audio to mono
198 **/
199 {
200 public:
201 ConvertToMono(PClip _clip);
202 1 virtual ~ConvertToMono()
203
2/4
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 5 not taken.
1 {if (tempbuffer_size) {delete[] tempbuffer;tempbuffer_size=0;}}
204
205 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
206 int __stdcall SetCacheHints(int cachehints, int frame_range);
207 static PClip Create(PClip clip);
208 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment*);
209
210 private:
211 char *tempbuffer;
212 int tempbuffer_size;
213 int channels;
214 };
215
216 class EnsureVBRMP3Sync : public GenericVideoFilter
217 /**
218 * Ensure VBR mp3 sync, by always reading audio sequencially.
219 **/
220 {
221 public:
222 EnsureVBRMP3Sync(PClip _clip);
223
224 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
225 int __stdcall SetCacheHints(int cachehints, int frame_range);
226 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
227
228 private:
229 int64_t last_end;
230 };
231
232 class MergeChannels : public GenericVideoFilter
233 /**
234 * Class to convert two mono sources to stereo
235 **/
236 {
237 public:
238 MergeChannels(PClip _clip, int _num_children, PClip* _child_array, IScriptEnvironment* env);
239 ~MergeChannels();
240
241 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
242 int __stdcall SetCacheHints(int cachehints, int frame_range);
243 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment*);
244
245 private:
246 int* clip_channels;
247 signed char** clip_offset;
248 signed char *tempbuffer;
249 PClip* child_array;
250 const int num_children;
251 int tempbuffer_size;
252 };
253
254
255 class GetChannel : public GenericVideoFilter
256 /**
257 * Class to get left or right channel from stereo source
258 **/
259 {
260 public:
261 GetChannel(PClip _clip, int* _channel, int numchannels);
262 1 virtual ~GetChannel()
263 1 {
264
2/4
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 6 not taken.
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 5 not taken.
1 if (tempbuffer_size) {delete[] tempbuffer;tempbuffer_size=0;}
265
2/4
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 10 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 9 not taken.
1 if (channel) {delete[] channel; channel=0; }
266 1 }
267
268 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
269 int __stdcall SetCacheHints(int cachehints, int frame_range);
270 static PClip Create_left(PClip clip);
271 static PClip Create_right(PClip clip);
272 static PClip Create_n(PClip clip, int* n, int numchannels);
273 static AVSValue __cdecl Create_left(AVSValue args, void*, IScriptEnvironment*);
274 static AVSValue __cdecl Create_right(AVSValue args, void*, IScriptEnvironment*);
275 static AVSValue __cdecl Create_n(AVSValue args, void*, IScriptEnvironment* env);
276
277 private:
278 char *tempbuffer;
279 int* channel;
280 int tempbuffer_size;
281 int numchannels;
282 int cbps;
283 int src_bps;
284 int dst_bps;
285 };
286
287 class KillVideo : public GenericVideoFilter
288 /**
289 * Removes audio from clip
290 **/
291 {
292 public:
293 KillVideo(PClip _clip);
294 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment*) { AVS_UNUSED(n); return NULL; };
295 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment*);
296 };
297
298
299 class KillAudio : public NonCachedGenericVideoFilter
300 /**
301 * Removes audio from clip
302 **/
303 {
304 public:
305 KillAudio(PClip _clip);
306 1 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env) { AVS_UNUSED(buf); AVS_UNUSED(start); AVS_UNUSED(count); AVS_UNUSED(env); };
307 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment*);
308 };
309
310 class SetChannelMask : public NonCachedGenericVideoFilter
311 /**
312 * Sets/remove Audio Channel Mask from VideoInfo
313 **/
314 {
315 public:
316 SetChannelMask(PClip _clip, bool IsChannelMaskKnown, unsigned int dwChannelMask);
317 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment*);
318 };
319
320 class DelayAudio : public GenericVideoFilter
321 /**
322 * Class to delay audio stream
323 **/
324 {
325 public:
326 DelayAudio(double delay, PClip _child);
327 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
328
329 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
330
331 private:
332 const int64_t delay_samples;
333 };
334
335
336
337 class Amplify : public GenericVideoFilter
338 /**
339 * Amplify a clip's audio track
340 **/
341 {
342 public:
343 Amplify(PClip _child, float* _volumes, int* _i_v);
344 ~Amplify();
345 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
346
347 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
348 static AVSValue __cdecl Create_dB(AVSValue args, void*, IScriptEnvironment* env);
349
350
351 private:
352 const float* volumes;
353 const int* i_v;
354
355 static __inline float dBtoScaleFactorf(float dB)
356 { return powf(10.0f, dB/20.0f);};
357 };
358
359
360
361
362
363 class Normalize : public GenericVideoFilter
364 /**
365 * Normalize a clip's audio track
366 **/
367 {
368 public:
369 Normalize(PClip _child, float _max_factor, bool _showvalues);
370 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
371 int __stdcall SetCacheHints(int cachehints, int frame_range);
372 PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
373
374 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
375
376
377 private:
378 float max_factor;
379 float max_volume;
380 int frameno;
381 bool showvalues;
382 };
383
384 class MixAudio : public GenericVideoFilter
385 /**
386 * Mix audio from one clip into another.
387 **/
388 {
389 public:
390 MixAudio(PClip _child, PClip _clip, double _track1_factor, double _track2_factor, IScriptEnvironment* env);
391 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
392 int __stdcall SetCacheHints(int cachehints, int frame_range);
393 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
394
2/4
✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 5 not taken.
✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 5 not taken.
2 virtual ~MixAudio() {if (tempbuffer_size) delete[] tempbuffer;tempbuffer_size=0;}
395
396
397 private:
398 PClip clip;
399 signed char *tempbuffer;
400 const int track1_factor, track2_factor;
401 const float t1factor, t2factor;
402 int tempbuffer_size;
403 };
404
405
406 class ResampleAudio : public GenericVideoFilter
407 /**
408 * Class to resample the audio stream
409 **/
410 {
411 public:
412 ResampleAudio(PClip _child, int _target_rate_n, int _target_rate_d, IScriptEnvironment* env);
413 4 virtual ~ResampleAudio()
414
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 2 times.
4 { delete[] srcbuffer;
415
2/2
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 2 times.
4 delete[] fsrcbuffer; }
416 void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env);
417 int __stdcall SetCacheHints(int cachehints, int frame_range);
418 static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);
419
420 enum { Nwing = 8192, Nmult = 65 }; // Number of filter points, (Nwing>>Nhc)*2+1
421
422 private:
423 int64_t FilterUD(short *Xp, short Ph, short Inc);
424 SFLOAT FilterUD(SFLOAT *Xp, short Ph, short Inc);
425
426 const double factor;
427 int Xoff, dtb, dhb;
428 unsigned dtbe;
429
430 int LpScl, mLpScl, mNhg;
431
432 short* srcbuffer;
433 SFLOAT* fsrcbuffer;
434
435 int srcbuffer_size;
436 bool skip_conversion;
437
438 int64_t last_start, last_samples;
439
440 union { // Share storage
441 SFLOAT fImp[Nwing+1];
442 short Imp[Nwing+1];
443 };
444 };
445
446
447 #endif // __Audio_H__
448