WaveSwissKnife 0.0.1.20101110-x86-cygwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +1 -0
- data/ChangeLog +5 -0
- data/Credits +3 -0
- data/LICENSE +31 -0
- data/README +18 -0
- data/ReleaseInfo +8 -0
- data/TODO +2 -0
- data/bin/WSK.rb +14 -0
- data/ext/WSK/AnalyzeUtils/AnalyzeUtils.c +272 -0
- data/ext/WSK/AnalyzeUtils/AnalyzeUtils.o +0 -0
- data/ext/WSK/AnalyzeUtils/AnalyzeUtils.so +0 -0
- data/ext/WSK/AnalyzeUtils/Makefile +149 -0
- data/ext/WSK/AnalyzeUtils/build.rb +18 -0
- data/ext/WSK/ArithmUtils/ArithmUtils.c +862 -0
- data/ext/WSK/ArithmUtils/ArithmUtils.o +0 -0
- data/ext/WSK/ArithmUtils/ArithmUtils.so +0 -0
- data/ext/WSK/ArithmUtils/Makefile +149 -0
- data/ext/WSK/ArithmUtils/build.rb +20 -0
- data/ext/WSK/FFTUtils/FFTUtils.c +662 -0
- data/ext/WSK/FFTUtils/FFTUtils.o +0 -0
- data/ext/WSK/FFTUtils/FFTUtils.so +0 -0
- data/ext/WSK/FFTUtils/Makefile +149 -0
- data/ext/WSK/FFTUtils/build.rb +20 -0
- data/ext/WSK/FunctionUtils/FunctionUtils.c +182 -0
- data/ext/WSK/FunctionUtils/FunctionUtils.o +0 -0
- data/ext/WSK/FunctionUtils/FunctionUtils.so +0 -0
- data/ext/WSK/FunctionUtils/Makefile +149 -0
- data/ext/WSK/FunctionUtils/build.rb +20 -0
- data/ext/WSK/SilentUtils/Makefile +149 -0
- data/ext/WSK/SilentUtils/SilentUtils.c +431 -0
- data/ext/WSK/SilentUtils/SilentUtils.o +0 -0
- data/ext/WSK/SilentUtils/SilentUtils.so +0 -0
- data/ext/WSK/SilentUtils/build.rb +18 -0
- data/ext/WSK/VolumeUtils/Makefile +149 -0
- data/ext/WSK/VolumeUtils/VolumeUtils.c +494 -0
- data/ext/WSK/VolumeUtils/VolumeUtils.o +0 -0
- data/ext/WSK/VolumeUtils/VolumeUtils.so +0 -0
- data/ext/WSK/VolumeUtils/build.rb +20 -0
- data/lib/WSK/Actions/Analyze.rb +176 -0
- data/lib/WSK/Actions/ApplyMap.desc.rb +15 -0
- data/lib/WSK/Actions/ApplyMap.rb +57 -0
- data/lib/WSK/Actions/ApplyVolumeFct.desc.rb +30 -0
- data/lib/WSK/Actions/ApplyVolumeFct.rb +72 -0
- data/lib/WSK/Actions/Compare.desc.rb +25 -0
- data/lib/WSK/Actions/Compare.rb +238 -0
- data/lib/WSK/Actions/ConstantCompare.desc.rb +20 -0
- data/lib/WSK/Actions/ConstantCompare.rb +61 -0
- data/lib/WSK/Actions/Cut.desc.rb +20 -0
- data/lib/WSK/Actions/Cut.rb +60 -0
- data/lib/WSK/Actions/CutFirstSignal.desc.rb +25 -0
- data/lib/WSK/Actions/CutFirstSignal.rb +72 -0
- data/lib/WSK/Actions/DCShifter.desc.rb +15 -0
- data/lib/WSK/Actions/DCShifter.rb +67 -0
- data/lib/WSK/Actions/DrawFct.desc.rb +20 -0
- data/lib/WSK/Actions/DrawFct.rb +59 -0
- data/lib/WSK/Actions/FFT.rb +104 -0
- data/lib/WSK/Actions/GenAllValues.rb +67 -0
- data/lib/WSK/Actions/GenConstant.desc.rb +20 -0
- data/lib/WSK/Actions/GenConstant.rb +56 -0
- data/lib/WSK/Actions/GenSawtooth.rb +57 -0
- data/lib/WSK/Actions/GenSine.desc.rb +20 -0
- data/lib/WSK/Actions/GenSine.rb +73 -0
- data/lib/WSK/Actions/Identity.rb +43 -0
- data/lib/WSK/Actions/Mix.desc.rb +15 -0
- data/lib/WSK/Actions/Mix.rb +149 -0
- data/lib/WSK/Actions/Multiply.desc.rb +15 -0
- data/lib/WSK/Actions/Multiply.rb +73 -0
- data/lib/WSK/Actions/NoiseGate.desc.rb +35 -0
- data/lib/WSK/Actions/NoiseGate.rb +129 -0
- data/lib/WSK/Actions/SilenceInserter.desc.rb +20 -0
- data/lib/WSK/Actions/SilenceInserter.rb +87 -0
- data/lib/WSK/Actions/SilenceRemover.desc.rb +30 -0
- data/lib/WSK/Actions/SilenceRemover.rb +74 -0
- data/lib/WSK/Actions/VolumeProfile.desc.rb +35 -0
- data/lib/WSK/Actions/VolumeProfile.rb +63 -0
- data/lib/WSK/Common.rb +292 -0
- data/lib/WSK/FFT.rb +527 -0
- data/lib/WSK/Functions.rb +770 -0
- data/lib/WSK/Launcher.rb +216 -0
- data/lib/WSK/Maps.rb +29 -0
- data/lib/WSK/Model/CachedBufferReader.rb +151 -0
- data/lib/WSK/Model/Header.rb +133 -0
- data/lib/WSK/Model/InputData.rb +193 -0
- data/lib/WSK/Model/RawReader.rb +78 -0
- data/lib/WSK/Model/WaveReader.rb +91 -0
- data/lib/WSK/OutputInterfaces/DirectStream.rb +146 -0
- data/lib/WSK/RIFFReader.rb +60 -0
- metadata +151 -0
@@ -0,0 +1,431 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2009-2010 Muriel Salvan (murielsalvan@users.sourceforge.net)
|
3
|
+
* Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
+
**/
|
5
|
+
|
6
|
+
#include "ruby.h"
|
7
|
+
#include <CommonUtils.h>
|
8
|
+
|
9
|
+
// Struct used to convey data among iterators in the getNextSilentSample method
|
10
|
+
typedef struct {
|
11
|
+
tSampleIndex* ptrIdxFirstSilentSample;
|
12
|
+
tThresholdInfo* ptrSilenceThresholds;
|
13
|
+
tSampleIndex* ptrIdxSilenceSample_Result;
|
14
|
+
tSampleIndex minSilenceSamples;
|
15
|
+
int nbrChannels;
|
16
|
+
} tFindSilentStruct;
|
17
|
+
|
18
|
+
// Struct used to convey data among iterators in the getFirstSampleBeyondThreshold method
|
19
|
+
typedef struct {
|
20
|
+
tSampleIndex* ptrIdxSample_Result;
|
21
|
+
tThresholdInfo* ptrThresholds;
|
22
|
+
int nbrChannels;
|
23
|
+
} tFirstSampleBeyondThresholdStruct;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Process a value read from an input buffer for the NextSilentSample function.
|
27
|
+
*
|
28
|
+
* Parameters:
|
29
|
+
* * *iValue* (<em>const tSampleValue</em>): The value being read
|
30
|
+
* * *iIdxSample* (<em>const tSampleIndex</em>): Index of this sample
|
31
|
+
* * *iIdxChannel* (<em>const int</em>): Channel corresponding to the value being read
|
32
|
+
* * *iPtrArgs* (<em>void*</em>): additional arguments. In fact a <em>tFindSilentStruct*</em>.
|
33
|
+
* Return:
|
34
|
+
* * _int_: The return code:
|
35
|
+
* ** 0: Continue iteration
|
36
|
+
* ** 1: Break all iterations
|
37
|
+
* ** 2: Skip directly to the next sample (don't call us for other channels of this sample)
|
38
|
+
*/
|
39
|
+
int silentutils_processValue(
|
40
|
+
const tSampleValue iValue,
|
41
|
+
const tSampleIndex iIdxSample,
|
42
|
+
const int iIdxChannel,
|
43
|
+
void* iPtrArgs) {
|
44
|
+
int rResult = 0;
|
45
|
+
|
46
|
+
// Interpret parameters
|
47
|
+
tFindSilentStruct* lPtrVariables = (tFindSilentStruct*)iPtrArgs;
|
48
|
+
|
49
|
+
if ((iValue < (lPtrVariables->ptrSilenceThresholds)[iIdxChannel].min) ||
|
50
|
+
(iValue > (lPtrVariables->ptrSilenceThresholds)[iIdxChannel].max)) {
|
51
|
+
// This value is not silent
|
52
|
+
// If we were in silence that has not yet reached its minimal duration, cancel this last silence
|
53
|
+
*(lPtrVariables->ptrIdxFirstSilentSample) = -1;
|
54
|
+
// Don't even read other channels
|
55
|
+
rResult = 2;
|
56
|
+
} else {
|
57
|
+
// This value is silent
|
58
|
+
if ((*(lPtrVariables->ptrIdxFirstSilentSample)) == -1) {
|
59
|
+
// This is the first silent value we have
|
60
|
+
*(lPtrVariables->ptrIdxFirstSilentSample) = iIdxSample;
|
61
|
+
}
|
62
|
+
// Check if the minimal duration has been reached
|
63
|
+
if (iIdxSample - (*(lPtrVariables->ptrIdxFirstSilentSample)) + 1 >= lPtrVariables->minSilenceSamples) {
|
64
|
+
// We have found a silence according to thresholds.
|
65
|
+
*(lPtrVariables->ptrIdxSilenceSample_Result) = *(lPtrVariables->ptrIdxFirstSilentSample);
|
66
|
+
// Stop iterations
|
67
|
+
rResult = 1;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
return rResult;
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* Process a value read from an input buffer for the NextSilentSample function.
|
76
|
+
* Do it in backwards search.
|
77
|
+
*
|
78
|
+
* Parameters:
|
79
|
+
* * *iValue* (<em>const tSampleValue</em>): The value being read
|
80
|
+
* * *iIdxSample* (<em>const tSampleIndex</em>): Index of this sample
|
81
|
+
* * *iIdxChannel* (<em>const int</em>): Channel corresponding to the value being read
|
82
|
+
* * *iPtrArgs* (<em>void*</em>): additional arguments. In fact a <em>tFindSilentStruct*</em>.
|
83
|
+
* Return:
|
84
|
+
* * _int_: The return code:
|
85
|
+
* ** 0: Continue iteration
|
86
|
+
* ** 1: Break all iterations
|
87
|
+
* ** 2: Skip directly to the next sample (don't call us for other channels of this sample)
|
88
|
+
*/
|
89
|
+
int silentutils_Reverse_processValue(
|
90
|
+
const tSampleValue iValue,
|
91
|
+
const tSampleIndex iIdxSample,
|
92
|
+
const int iIdxChannel,
|
93
|
+
void* iPtrArgs) {
|
94
|
+
int rResult = 0;
|
95
|
+
|
96
|
+
// Interpret parameters
|
97
|
+
tFindSilentStruct* lPtrVariables = (tFindSilentStruct*)iPtrArgs;
|
98
|
+
|
99
|
+
if ((iValue < (lPtrVariables->ptrSilenceThresholds)[iIdxChannel].min) ||
|
100
|
+
(iValue > (lPtrVariables->ptrSilenceThresholds)[iIdxChannel].max)) {
|
101
|
+
// This value is not silent
|
102
|
+
// If we were in silence that has not yet reached its minimal duration, cancel this last silence
|
103
|
+
*(lPtrVariables->ptrIdxFirstSilentSample) = -1;
|
104
|
+
// Don't even read other channels
|
105
|
+
rResult = 2;
|
106
|
+
} else {
|
107
|
+
// This value is silent
|
108
|
+
if ((*(lPtrVariables->ptrIdxFirstSilentSample)) == -1) {
|
109
|
+
// This is the first silent value we have
|
110
|
+
*(lPtrVariables->ptrIdxFirstSilentSample) = iIdxSample;
|
111
|
+
}
|
112
|
+
// Check if the minimal duration has been reached
|
113
|
+
if ((*(lPtrVariables->ptrIdxFirstSilentSample)) - iIdxSample + 1 >= lPtrVariables->minSilenceSamples) {
|
114
|
+
// We have found a silence according to thresholds.
|
115
|
+
*(lPtrVariables->ptrIdxSilenceSample_Result) = *(lPtrVariables->ptrIdxFirstSilentSample);
|
116
|
+
// Stop iterations
|
117
|
+
rResult = 1;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
return rResult;
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Code block called by getNextSilentSample in the eachRawBuffer loop.
|
126
|
+
* This is meant to be used with rb_iterate.
|
127
|
+
*
|
128
|
+
* Parameters:
|
129
|
+
* * *iValYieldArgs* (<em>list<Object></em>): The yield arguments:
|
130
|
+
* ** *iValInputRawBuffer* (_String_): The raw buffer
|
131
|
+
* ** *iValNbrSamples* (_Integer_): The number of samples in this buffer
|
132
|
+
* ** *iValNbrChannels* (_Integer_): The number of channels in this buffer
|
133
|
+
* * *iValIterateArgs* (<em>list<Object></em>): The iterate arguments:
|
134
|
+
* ** *iValNbrBitsPerSample* (_Integer_): Number of bits per sample
|
135
|
+
* ** *iValPtrIdxSample* (_Integer_): Address of the IdxSample variable
|
136
|
+
* ** *iValPtrIdxFirstSilentSample* (_Integer_): Address of the IdxFirstSilentSample variable
|
137
|
+
* ** *iValPtrSilenceThresholds* (_Integer_): Address of the SilenceThresholds variable
|
138
|
+
* ** *iValMinSilenceSamples* (_Integer_): Minimal silence samples
|
139
|
+
* ** *iValPtrIdxSilenceSample_Result* (_Integer_): Address of the IdxSilenceSample_Result variable
|
140
|
+
* ** *iValBackwardsSearch* (_Boolean_): Do we search backwards ?
|
141
|
+
*/
|
142
|
+
static VALUE silentutils_blockEachRawBuffer(
|
143
|
+
VALUE iValYieldArgs,
|
144
|
+
VALUE iValIterateArgs) {
|
145
|
+
// Read arguments
|
146
|
+
VALUE iValInputRawBuffer = rb_ary_entry(iValYieldArgs, 0);
|
147
|
+
VALUE iValNbrSamples = rb_ary_entry(iValYieldArgs, 1);
|
148
|
+
VALUE iValNbrChannels = rb_ary_entry(iValYieldArgs, 2);
|
149
|
+
VALUE iValNbrBitsPerSample = rb_ary_entry(iValIterateArgs, 0);
|
150
|
+
VALUE iValPtrIdxSample = rb_ary_entry(iValIterateArgs, 1);
|
151
|
+
VALUE iValPtrIdxFirstSilentSample = rb_ary_entry(iValIterateArgs, 2);
|
152
|
+
VALUE iValPtrSilenceThresholds = rb_ary_entry(iValIterateArgs, 3);
|
153
|
+
VALUE iValMinSilenceSamples = rb_ary_entry(iValIterateArgs, 4);
|
154
|
+
VALUE iValPtrIdxSilenceSample_Result = rb_ary_entry(iValIterateArgs, 5);
|
155
|
+
VALUE iValBackwardsSearch = rb_ary_entry(iValIterateArgs, 6);
|
156
|
+
// Translate parameters in C types
|
157
|
+
int iNbrBitsPerSample = FIX2INT(iValNbrBitsPerSample);
|
158
|
+
tSampleIndex iNbrSamples = FIX2LONG(iValNbrSamples);
|
159
|
+
int iNbrChannels = FIX2INT(iValNbrChannels);
|
160
|
+
tSampleIndex* lPtrIdxSample = (tSampleIndex*)FIX2INT(iValPtrIdxSample);
|
161
|
+
tSampleIndex* lPtrIdxFirstSilentSample = (tSampleIndex*)FIX2INT(iValPtrIdxFirstSilentSample);
|
162
|
+
tThresholdInfo* lPtrSilenceThresholds = (tThresholdInfo*)FIX2INT(iValPtrSilenceThresholds);
|
163
|
+
tSampleIndex iMinSilenceSamples = FIX2LONG(iValMinSilenceSamples);
|
164
|
+
tSampleIndex* lPtrIdxSilenceSample_Result = (tSampleIndex*)FIX2INT(iValPtrIdxSilenceSample_Result);
|
165
|
+
|
166
|
+
// Get the real underlying raw buffer
|
167
|
+
char* lPtrRawBuffer = RSTRING(iValInputRawBuffer)->ptr;
|
168
|
+
|
169
|
+
// Set variables to give to the process
|
170
|
+
tFindSilentStruct lProcessVariables;
|
171
|
+
lProcessVariables.ptrIdxFirstSilentSample = lPtrIdxFirstSilentSample;
|
172
|
+
lProcessVariables.ptrSilenceThresholds = lPtrSilenceThresholds;
|
173
|
+
lProcessVariables.ptrIdxSilenceSample_Result = lPtrIdxSilenceSample_Result;
|
174
|
+
lProcessVariables.minSilenceSamples = iMinSilenceSamples;
|
175
|
+
lProcessVariables.nbrChannels = iNbrChannels;
|
176
|
+
|
177
|
+
// Iterate through the raw buffer
|
178
|
+
if (iValBackwardsSearch == Qtrue) {
|
179
|
+
commonutils_iterateReverseThroughRawBuffer(
|
180
|
+
lPtrRawBuffer,
|
181
|
+
iNbrBitsPerSample,
|
182
|
+
iNbrChannels,
|
183
|
+
iNbrSamples,
|
184
|
+
*lPtrIdxSample,
|
185
|
+
&silentutils_Reverse_processValue,
|
186
|
+
&lProcessVariables
|
187
|
+
);
|
188
|
+
} else {
|
189
|
+
commonutils_iterateThroughRawBuffer(
|
190
|
+
lPtrRawBuffer,
|
191
|
+
iNbrBitsPerSample,
|
192
|
+
iNbrChannels,
|
193
|
+
iNbrSamples,
|
194
|
+
*lPtrIdxSample,
|
195
|
+
&silentutils_processValue,
|
196
|
+
&lProcessVariables
|
197
|
+
);
|
198
|
+
}
|
199
|
+
|
200
|
+
// If the result was found in this raw buffer, stop parsing everything
|
201
|
+
if (*lPtrIdxSilenceSample_Result != -1) {
|
202
|
+
rb_iter_break();
|
203
|
+
}
|
204
|
+
|
205
|
+
// Modify the sample index
|
206
|
+
if (iValBackwardsSearch == Qtrue) {
|
207
|
+
(*lPtrIdxSample) -= iNbrSamples;
|
208
|
+
} else {
|
209
|
+
(*lPtrIdxSample) += iNbrSamples;
|
210
|
+
}
|
211
|
+
|
212
|
+
return Qnil;
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Get the next silent sample from an input buffer
|
217
|
+
*
|
218
|
+
* Parameters:
|
219
|
+
* * *iSelf* (_FFTUtils_): Self
|
220
|
+
* * *iValInputData* (<em>WSK::Model::InputData</em>): The input data
|
221
|
+
* * *iValIdxStartSample* (_Integer_): Index of the first sample to search from
|
222
|
+
* * *iValSilenceThresholds* (<em>list<[Integer,Integer]></em>): The silence thresholds specifications
|
223
|
+
* * *iValMinSilenceSamples* (_Integer_): Number of samples minimum to identify a silence
|
224
|
+
* * *iValBackwardsSearch* (_Boolean_): Do we search backwards ?
|
225
|
+
* Return:
|
226
|
+
* * _Integer_: Index of the next silent sample, or nil if none
|
227
|
+
**/
|
228
|
+
static VALUE silentutils_getNextSilentInThresholds(
|
229
|
+
VALUE iSelf,
|
230
|
+
VALUE iValInputData,
|
231
|
+
VALUE iValIdxStartSample,
|
232
|
+
VALUE iValSilenceThresholds,
|
233
|
+
VALUE iValMinSilenceSamples,
|
234
|
+
VALUE iValBackwardsSearch) {
|
235
|
+
VALUE rValNextSilentSample = Qnil;
|
236
|
+
|
237
|
+
// Translate parameters in C types
|
238
|
+
tSampleIndex iIdxStartSample = FIX2LONG(iValIdxStartSample);
|
239
|
+
|
240
|
+
// The cursor of samples. Set it to the first sample we start from searching.
|
241
|
+
tSampleIndex lIdxSample = iIdxStartSample;
|
242
|
+
// Read some info from the Header
|
243
|
+
VALUE lValHeader = rb_funcall(iValInputData, rb_intern("Header"), 0);
|
244
|
+
VALUE lValNbrBitsPerSample = rb_funcall(lValHeader, rb_intern("NbrBitsPerSample"), 0);
|
245
|
+
VALUE lValNbrChannels = rb_funcall(lValHeader, rb_intern("NbrChannels"), 0);
|
246
|
+
// Decode the thresholds
|
247
|
+
int lNbrChannels = FIX2INT(lValNbrChannels);
|
248
|
+
tThresholdInfo lSilenceThresholds[lNbrChannels];
|
249
|
+
VALUE lTmpThresholds;
|
250
|
+
int lIdxChannel;
|
251
|
+
for(lIdxChannel = 0; lIdxChannel < lNbrChannels; ++lIdxChannel) {
|
252
|
+
lTmpThresholds = rb_ary_entry(iValSilenceThresholds, lIdxChannel);
|
253
|
+
lSilenceThresholds[lIdxChannel].min = FIX2INT(rb_ary_entry(lTmpThresholds, 0));
|
254
|
+
lSilenceThresholds[lIdxChannel].max = FIX2INT(rb_ary_entry(lTmpThresholds, 1));
|
255
|
+
}
|
256
|
+
|
257
|
+
// Index of the first silent sample encountered while parsing.
|
258
|
+
// Used to assert the minimal duration of the silence. -1 means we don't have one yet.
|
259
|
+
tSampleIndex lIdxFirstSilentSample;
|
260
|
+
// The result
|
261
|
+
tSampleIndex lIdxSilenceSample_Result;
|
262
|
+
|
263
|
+
// Encapsulate pointers to the data that will be used and modified by the iteration block
|
264
|
+
VALUE lValPtrIdxSample = INT2FIX(&lIdxSample);
|
265
|
+
VALUE lValPtrIdxFirstSilentSample = INT2FIX(&lIdxFirstSilentSample);
|
266
|
+
VALUE lValPtrSilenceThresholds = INT2FIX(&lSilenceThresholds);
|
267
|
+
VALUE lValPtrIdxSilenceSample_Result = INT2FIX(&lIdxSilenceSample_Result);
|
268
|
+
|
269
|
+
lIdxFirstSilentSample = -1;
|
270
|
+
lIdxSilenceSample_Result = -1;
|
271
|
+
|
272
|
+
// Parse the data, using thresholds matching only
|
273
|
+
if (iValBackwardsSearch == Qtrue) {
|
274
|
+
rb_iterate(
|
275
|
+
commonutils_callEachReverseRawBuffer,
|
276
|
+
rb_ary_new3(2,
|
277
|
+
iValInputData,
|
278
|
+
LONG2FIX(lIdxSample)),
|
279
|
+
silentutils_blockEachRawBuffer,
|
280
|
+
rb_ary_new3(7,
|
281
|
+
lValNbrBitsPerSample,
|
282
|
+
lValPtrIdxSample,
|
283
|
+
lValPtrIdxFirstSilentSample,
|
284
|
+
lValPtrSilenceThresholds,
|
285
|
+
iValMinSilenceSamples,
|
286
|
+
lValPtrIdxSilenceSample_Result,
|
287
|
+
iValBackwardsSearch)
|
288
|
+
);
|
289
|
+
} else {
|
290
|
+
rb_iterate(
|
291
|
+
commonutils_callEachRawBuffer,
|
292
|
+
rb_ary_new3(2,
|
293
|
+
iValInputData,
|
294
|
+
LONG2FIX(lIdxSample)),
|
295
|
+
silentutils_blockEachRawBuffer,
|
296
|
+
rb_ary_new3(7,
|
297
|
+
lValNbrBitsPerSample,
|
298
|
+
lValPtrIdxSample,
|
299
|
+
lValPtrIdxFirstSilentSample,
|
300
|
+
lValPtrSilenceThresholds,
|
301
|
+
iValMinSilenceSamples,
|
302
|
+
lValPtrIdxSilenceSample_Result,
|
303
|
+
iValBackwardsSearch)
|
304
|
+
);
|
305
|
+
}
|
306
|
+
|
307
|
+
if (lIdxSilenceSample_Result != -1) {
|
308
|
+
rValNextSilentSample = LONG2FIX(lIdxSilenceSample_Result);
|
309
|
+
}
|
310
|
+
|
311
|
+
return rValNextSilentSample;
|
312
|
+
}
|
313
|
+
|
314
|
+
/**
|
315
|
+
* Process a value read from an input buffer for the NextSilentSample function.
|
316
|
+
*
|
317
|
+
* Parameters:
|
318
|
+
* * *iValue* (<em>const tSampleValue</em>): The value being read
|
319
|
+
* * *iIdxSample* (<em>const tSampleIndex</em>): Index of this sample
|
320
|
+
* * *iIdxChannel* (<em>const int</em>): Channel corresponding to the value being read
|
321
|
+
* * *iPtrArgs* (<em>void*</em>): additional arguments. In fact an <em>tFirstSampleBeyondThresholdStruct*</em>.
|
322
|
+
* Return:
|
323
|
+
* * _int_: The return code:
|
324
|
+
* ** 0: Continue iteration
|
325
|
+
* ** 1: Break all iterations
|
326
|
+
* ** 2: Skip directly to the next sample (don't call us for other channels of this sample)
|
327
|
+
*/
|
328
|
+
int silentutils_sbt_processValue(
|
329
|
+
const tSampleValue iValue,
|
330
|
+
const tSampleIndex iIdxSample,
|
331
|
+
const int iIdxChannel,
|
332
|
+
void* iPtrArgs) {
|
333
|
+
int rResult = 0;
|
334
|
+
|
335
|
+
// Interpret parameters
|
336
|
+
tFirstSampleBeyondThresholdStruct* lPtrVariables = (tFirstSampleBeyondThresholdStruct*)iPtrArgs;
|
337
|
+
|
338
|
+
if ((iValue < (lPtrVariables->ptrThresholds)[iIdxChannel].min) ||
|
339
|
+
(iValue > (lPtrVariables->ptrThresholds)[iIdxChannel].max)) {
|
340
|
+
// This value is not silent
|
341
|
+
rResult = 1;
|
342
|
+
*(lPtrVariables->ptrIdxSample_Result) = iIdxSample;
|
343
|
+
}
|
344
|
+
|
345
|
+
return rResult;
|
346
|
+
}
|
347
|
+
|
348
|
+
/**
|
349
|
+
* Get the sample index that exceeds a threshold in a raw buffer.
|
350
|
+
*
|
351
|
+
* Parameters:
|
352
|
+
* * *iSelf* (_FFTUtils_): Self
|
353
|
+
* * *iValRawBuffer* (_String_): The raw buffer
|
354
|
+
* * *iValThresholds* (<em>list<[Integer,Integer]></em>): The thresholds
|
355
|
+
* * *iValNbrBitsPerSample* (_Integer_): Number of bits per sample
|
356
|
+
* * *iValNbrChannels* (_Integer_): Number of channels
|
357
|
+
* * *iValNbrSamples* (_Integer_): Number of samples
|
358
|
+
* * *iValLastSample* (_Boolean_): Are we looking for the last sample beyond threshold ?
|
359
|
+
* Return:
|
360
|
+
* * _Integer_: Index of the first sample exceeding thresholds, or nil if none
|
361
|
+
*/
|
362
|
+
static VALUE silentutils_getSampleBeyondThresholds(
|
363
|
+
VALUE iSelf,
|
364
|
+
VALUE iValRawBuffer,
|
365
|
+
VALUE iValThresholds,
|
366
|
+
VALUE iValNbrBitsPerSample,
|
367
|
+
VALUE iValNbrChannels,
|
368
|
+
VALUE iValNbrSamples,
|
369
|
+
VALUE iValLastSample) {
|
370
|
+
VALUE rValIdxFirstSample = Qnil;
|
371
|
+
|
372
|
+
// Translate parameters in C types
|
373
|
+
tSampleIndex iNbrSamples = FIX2LONG(iValNbrSamples);
|
374
|
+
int iNbrChannels = FIX2INT(iValNbrChannels);
|
375
|
+
int iNbrBitsPerSample = FIX2INT(iValNbrBitsPerSample);
|
376
|
+
// Get the underlying char*
|
377
|
+
char* lPtrRawBuffer = RSTRING(iValRawBuffer)->ptr;
|
378
|
+
// Decode the thresholds
|
379
|
+
tThresholdInfo lThresholds[iNbrChannels];
|
380
|
+
VALUE lTmpThresholds;
|
381
|
+
int lIdxChannel;
|
382
|
+
for(lIdxChannel = 0; lIdxChannel < iNbrChannels; ++lIdxChannel) {
|
383
|
+
lTmpThresholds = rb_ary_entry(iValThresholds, lIdxChannel);
|
384
|
+
lThresholds[lIdxChannel].min = FIX2INT(rb_ary_entry(lTmpThresholds, 0));
|
385
|
+
lThresholds[lIdxChannel].max = FIX2INT(rb_ary_entry(lTmpThresholds, 1));
|
386
|
+
}
|
387
|
+
// Set variables to give to the process
|
388
|
+
tSampleIndex lIdxSampleOut = -1;
|
389
|
+
tFirstSampleBeyondThresholdStruct lProcessVariables;
|
390
|
+
lProcessVariables.ptrThresholds = &lThresholds[0];
|
391
|
+
lProcessVariables.ptrIdxSample_Result = &lIdxSampleOut;
|
392
|
+
lProcessVariables.nbrChannels = iNbrChannels;
|
393
|
+
|
394
|
+
// Parse the buffer
|
395
|
+
if (iValLastSample == Qtrue) {
|
396
|
+
commonutils_iterateReverseThroughRawBuffer(
|
397
|
+
lPtrRawBuffer,
|
398
|
+
iNbrBitsPerSample,
|
399
|
+
iNbrChannels,
|
400
|
+
iNbrSamples,
|
401
|
+
iNbrSamples-1,
|
402
|
+
&silentutils_sbt_processValue,
|
403
|
+
&lProcessVariables
|
404
|
+
);
|
405
|
+
} else {
|
406
|
+
commonutils_iterateThroughRawBuffer(
|
407
|
+
lPtrRawBuffer,
|
408
|
+
iNbrBitsPerSample,
|
409
|
+
iNbrChannels,
|
410
|
+
iNbrSamples,
|
411
|
+
0,
|
412
|
+
&silentutils_sbt_processValue,
|
413
|
+
&lProcessVariables
|
414
|
+
);
|
415
|
+
}
|
416
|
+
if (lIdxSampleOut != -1) {
|
417
|
+
rValIdxFirstSample = LONG2FIX(lIdxSampleOut);
|
418
|
+
}
|
419
|
+
|
420
|
+
return rValIdxFirstSample;
|
421
|
+
}
|
422
|
+
|
423
|
+
// Initialize the module
|
424
|
+
void Init_SilentUtils() {
|
425
|
+
VALUE lWSKModule = rb_define_module("WSK");
|
426
|
+
VALUE lSilentUtilsModule = rb_define_module_under(lWSKModule, "SilentUtils");
|
427
|
+
VALUE lSilentUtilsClass = rb_define_class_under(lSilentUtilsModule, "SilentUtils", rb_cObject);
|
428
|
+
|
429
|
+
rb_define_method(lSilentUtilsClass, "getNextSilentInThresholds", silentutils_getNextSilentInThresholds, 5);
|
430
|
+
rb_define_method(lSilentUtilsClass, "getSampleBeyondThresholds", silentutils_getSampleBeyondThresholds, 6);
|
431
|
+
}
|
Binary file
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009-2010 Muriel Salvan (murielsalvan@users.sourceforge.net)
|
3
|
+
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
|
+
#++
|
5
|
+
|
6
|
+
lAdditionalLocalLibs = [
|
7
|
+
'CommonUtils'
|
8
|
+
]
|
9
|
+
|
10
|
+
require 'mkmf'
|
11
|
+
$CFLAGS += ' -Wall '
|
12
|
+
lAdditionalLocalLibs.each do |iLibName|
|
13
|
+
lLibDir = File.expand_path("#{File.dirname(__FILE__)}/../../../external/#{iLibName}")
|
14
|
+
$CFLAGS += " -I#{lLibDir}/include "
|
15
|
+
$LDFLAGS += " -L#{lLibDir}/lib -l#{iLibName} "
|
16
|
+
end
|
17
|
+
create_makefile('SilentUtils')
|
18
|
+
system('make')
|
@@ -0,0 +1,149 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
#### Start of system configuration section. ####
|
5
|
+
|
6
|
+
srcdir = .
|
7
|
+
topdir = /usr/lib/ruby/1.8/i386-cygwin
|
8
|
+
hdrdir = $(topdir)
|
9
|
+
VPATH = $(srcdir):$(topdir):$(hdrdir)
|
10
|
+
prefix = $(DESTDIR)/usr
|
11
|
+
exec_prefix = $(prefix)
|
12
|
+
sitedir = $(prefix)/lib/ruby/site_ruby
|
13
|
+
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
14
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
15
|
+
dvidir = $(docdir)
|
16
|
+
datarootdir = $(prefix)/share
|
17
|
+
archdir = $(rubylibdir)/$(arch)
|
18
|
+
sbindir = $(exec_prefix)/sbin
|
19
|
+
psdir = $(docdir)
|
20
|
+
localedir = $(datarootdir)/locale
|
21
|
+
htmldir = $(docdir)
|
22
|
+
datadir = $(prefix)/share
|
23
|
+
includedir = $(prefix)/include
|
24
|
+
infodir = $(prefix)/share/info
|
25
|
+
sysconfdir = $(DESTDIR)/etc
|
26
|
+
mandir = $(prefix)/share/man
|
27
|
+
libdir = $(exec_prefix)/lib
|
28
|
+
sharedstatedir = $(prefix)/com
|
29
|
+
oldincludedir = $(DESTDIR)/usr/include
|
30
|
+
pdfdir = $(docdir)
|
31
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
32
|
+
bindir = $(exec_prefix)/bin
|
33
|
+
localstatedir = $(DESTDIR)/var
|
34
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
35
|
+
libexecdir = $(prefix)/sbin
|
36
|
+
|
37
|
+
CC = gcc
|
38
|
+
LIBRUBY = lib$(RUBY_SO_NAME).dll.a
|
39
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
40
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
41
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
42
|
+
|
43
|
+
RUBY_EXTCONF_H =
|
44
|
+
CFLAGS = -g -O2 -Wall -I/cygdrive/f/RR/Source/waveswissknife/svn/waveswissknife/external/CommonUtils/include
|
45
|
+
INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
|
46
|
+
CPPFLAGS =
|
47
|
+
CXXFLAGS = $(CFLAGS)
|
48
|
+
DLDFLAGS = -L. -L/usr/local/lib -lgmp -L/cygdrive/f/RR/Source/waveswissknife/svn/waveswissknife/external/CommonUtils/lib -lCommonUtils -Wl,--enable-auto-image-base,--enable-auto-import,--export-all
|
49
|
+
LDSHARED = gcc -shared -s
|
50
|
+
AR = ar
|
51
|
+
EXEEXT = .exe
|
52
|
+
|
53
|
+
RUBY_INSTALL_NAME = ruby
|
54
|
+
RUBY_SO_NAME = ruby
|
55
|
+
arch = i386-cygwin
|
56
|
+
sitearch = i386-cygwin
|
57
|
+
ruby_version = 1.8
|
58
|
+
ruby = /usr/bin/ruby
|
59
|
+
RUBY = $(ruby)
|
60
|
+
RM = rm -f
|
61
|
+
MAKEDIRS = mkdir -p
|
62
|
+
INSTALL = /usr/bin/install -c
|
63
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
64
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
65
|
+
COPY = cp
|
66
|
+
|
67
|
+
#### End of system configuration section. ####
|
68
|
+
|
69
|
+
preload =
|
70
|
+
|
71
|
+
libpath = . $(libdir)
|
72
|
+
LIBPATH = -L"." -L"$(libdir)"
|
73
|
+
DEFFILE =
|
74
|
+
|
75
|
+
CLEANFILES = mkmf.log
|
76
|
+
DISTCLEANFILES =
|
77
|
+
|
78
|
+
extout =
|
79
|
+
extout_prefix =
|
80
|
+
target_prefix =
|
81
|
+
LOCAL_LIBS =
|
82
|
+
LIBS = $(LIBRUBYARG_SHARED) -ldl -lcrypt
|
83
|
+
SRCS = VolumeUtils.c
|
84
|
+
OBJS = VolumeUtils.o
|
85
|
+
TARGET = VolumeUtils
|
86
|
+
DLLIB = $(TARGET).so
|
87
|
+
EXTSTATIC =
|
88
|
+
STATIC_LIB =
|
89
|
+
|
90
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
91
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
92
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
93
|
+
|
94
|
+
TARGET_SO = $(DLLIB)
|
95
|
+
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
96
|
+
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
97
|
+
|
98
|
+
all: $(DLLIB)
|
99
|
+
static: $(STATIC_LIB)
|
100
|
+
|
101
|
+
clean:
|
102
|
+
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
103
|
+
|
104
|
+
distclean: clean
|
105
|
+
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
106
|
+
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
107
|
+
|
108
|
+
realclean: distclean
|
109
|
+
install: install-so install-rb
|
110
|
+
|
111
|
+
install-so: $(RUBYARCHDIR)
|
112
|
+
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
113
|
+
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
114
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
115
|
+
install-rb: pre-install-rb install-rb-default
|
116
|
+
install-rb-default: pre-install-rb-default
|
117
|
+
pre-install-rb: Makefile
|
118
|
+
pre-install-rb-default: Makefile
|
119
|
+
$(RUBYARCHDIR):
|
120
|
+
$(MAKEDIRS) $@
|
121
|
+
|
122
|
+
site-install: site-install-so site-install-rb
|
123
|
+
site-install-so: install-so
|
124
|
+
site-install-rb: install-rb
|
125
|
+
|
126
|
+
.SUFFIXES: .c .m .cc .cxx .cpp .C .o
|
127
|
+
|
128
|
+
.cc.o:
|
129
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
130
|
+
|
131
|
+
.cxx.o:
|
132
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
133
|
+
|
134
|
+
.cpp.o:
|
135
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
136
|
+
|
137
|
+
.C.o:
|
138
|
+
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
139
|
+
|
140
|
+
.c.o:
|
141
|
+
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
142
|
+
|
143
|
+
$(DLLIB): $(OBJS)
|
144
|
+
@-$(RM) $@
|
145
|
+
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
$(OBJS): ruby.h defines.h
|