-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathacrusher.js
219 lines (202 loc) · 3.98 KB
/
acrusher.js
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
const addFilter = require('./utils').addFilter;
const registerFilter = require('./utils').registerFilter;
/**
* Augment FfmpegCommand with the acrusher function.
*
*
* @example
* ffmpeg().acrusher()
* ... // call filter configuration functions
* .build() // end filter configuration
* ...
* .applyFilters() // called once all filters have been configured
*
* @param {FfmpegCommand} ffmpegCommand The fluent-ffmpeg constructor.
* @return {FfmpegCommand} The ffmpegCommand augmented with the acrusher function.
*/
function acrusher(ffmpegCommand) {
registerFilter(ffmpegCommand, 'acrusher', function() {
return new AcrusherFilter(this);
});
return ffmpegCommand;
}
/**
* Class exposing methods to configure the vstack filter in a builder pattern way.
*
* See {@link http://ffmpeg.org/ffmpeg-filters.html#vstack} for a description
* of each configuration option.
*/
class AcrusherFilter {
/**
* @param {FfmpegCommand} ffmpegCommand The fluent-ffmpeg constructor.
*/
constructor (ffmpeg) {
this.ffmpeg = ffmpeg;
AcrusherFilter.prototype.withLevel_in = this.level_in;
AcrusherFilter.prototype.withLevel_out = this.level_out;
AcrusherFilter.prototype.withBits = this.bits;
AcrusherFilter.prototype.withMix = this.mix;
AcrusherFilter.prototype.withMode = this.mode;
AcrusherFilter.prototype.withDc = this.dc;
AcrusherFilter.prototype.withAa = this.aa;
AcrusherFilter.prototype.withSamples = this.samples;
AcrusherFilter.prototype.withLfo = this.lfo;
AcrusherFilter.prototype.withLforange = this.lforange;
AcrusherFilter.prototype.withLforate = this.lforate;
}
/**
* Set level in.
*
*
* @param val
*/
level_in(val) {
this._level_in = val;
return this;
}
/**
* Set level out.
*
*
* @param val
*/
level_out(val) {
this._level_out = val;
return this;
}
/**
* Set bit reduction.
*
*
* @param val
*/
bits(val) {
this._bits = val;
return this;
}
/**
* Set mixing amount.
*
*
* @param val
*/
mix(val) {
this._mix = val;
return this;
}
/**
* Can be linear: lin or logarithmic: log.
*
*
* @param val
*/
mode(val) {
this._mode = val;
return this;
}
/**
* Set DC.
*
*
* @param val
*/
dc(val) {
this._dc = val;
return this;
}
/**
* Set anti-aliasing.
*
*
* @param val
*/
aa(val) {
this._aa = val;
return this;
}
/**
* Set sample reduction.
*
*
* @param val
*/
samples(val) {
this._samples = val;
return this;
}
/**
* Enable LFO. By default disabled.
*
*
* @param val
*/
lfo(val) {
this._lfo = val;
return this;
}
/**
* Set LFO range.
*
*
* @param val
*/
lforange(val) {
this._lforange = val;
return this;
}
/**
* Set LFO rate.
*
* @param val
*/
lforate(val) {
this._lforate = val;
return this;
}
/**
* Creates this filter configuration and registers it in the ffmpeg instance.
* @return {ffmpegCommand} The ffmpeg instance.
*/
build() {
let opt = {};
if (this._level_in) {
opt['level_in'] = this._level_in;
}
if (this._level_out) {
opt['level_out'] = this._level_out;
}
if (this._bits) {
opt['bits'] = this._bits;
}
if (this._mix) {
opt['mix'] = this._mix;
}
if (this._mode) {
opt['mode'] = this._mode;
}
if (this._dc) {
opt['dc'] = this._dc;
}
if (this._aa) {
opt['aa'] = this._aa;
}
if (this._samples) {
opt['samples'] = this._samples;
}
if (this._lfo) {
opt['lfo'] = this._lfo;
}
if (this._lforange) {
opt['lforange'] = this._lforange;
}
if (this._lforate) {
opt['lforate'] = this._lforate;
}
addFilter(this.ffmpeg, {
filter: 'acrusher',
options: opt
});
return this.ffmpeg;
}
}
module.exports.acrusher = acrusher;