comparison plugins/Silence.cpp @ 18:70472f9558da

...
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 09 Oct 2007 15:56:50 +0000
parents b85fbc77677b
children 8c939fff7ee1
comparison
equal deleted inserted replaced
17:b85fbc77677b 18:70472f9558da
9 This program is free software; you can redistribute it and/or 9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as 10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14
15 */ 14 */
16 15
17 #include <math.h> 16 #include <math.h>
18 #include "Silence.h" 17 #include "Silence.h"
19 18
25 Silence::Silence(float inputSampleRate) : 24 Silence::Silence(float inputSampleRate) :
26 Plugin(inputSampleRate), 25 Plugin(inputSampleRate),
27 m_ibuf(0), 26 m_ibuf(0),
28 m_pbuf(0), 27 m_pbuf(0),
29 m_tmpptrs(0), 28 m_tmpptrs(0),
30 m_threshold(-70), 29 m_threshold(-80),
31 m_prevSilent(false), 30 m_prevSilent(false),
32 m_first(true) 31 m_first(true)
33 { 32 {
34 } 33 }
35 34
117 desc = ParameterDescriptor(); 116 desc = ParameterDescriptor();
118 desc.identifier = "silencethreshold"; 117 desc.identifier = "silencethreshold";
119 desc.name = "Silence Threshold"; 118 desc.name = "Silence Threshold";
120 desc.minValue = -120; 119 desc.minValue = -120;
121 desc.maxValue = 0; 120 desc.maxValue = 0;
122 desc.defaultValue = -70; 121 desc.defaultValue = -80;
123 desc.unit = "dB"; 122 desc.unit = "dB";
124 desc.isQuantized = false; 123 desc.isQuantized = false;
125 list.push_back(desc); 124 list.push_back(desc);
126 125
127 return list; 126 return list;
150 { 149 {
151 OutputList list; 150 OutputList list;
152 151
153 OutputDescriptor d; 152 OutputDescriptor d;
154 d.identifier = "silencestart"; 153 d.identifier = "silencestart";
155 d.name = "Starts of Silent Regions"; 154 d.name = "Beginnings of Silent Regions";
156 d.description = "Return a single instant at the point where each silent region begins"; 155 d.description = "Return a single instant at the point where each silent region begins";
157 d.hasFixedBinCount = true; 156 d.hasFixedBinCount = true;
158 d.binCount = 0; 157 d.binCount = 0;
159 d.sampleType = OutputDescriptor::VariableSampleRate; 158 d.sampleType = OutputDescriptor::VariableSampleRate;
159 d.sampleRate = 0;
160 list.push_back(d); 160 list.push_back(d);
161 161
162 d.identifier = "silenceend"; 162 d.identifier = "silenceend";
163 d.name = "Ends of Silent Regions"; 163 d.name = "Ends of Silent Regions";
164 d.description = "Return a single instant at the point where each silent region ends"; 164 d.description = "Return a single instant at the point where each silent region ends";
165 d.hasFixedBinCount = true; 165 d.hasFixedBinCount = true;
166 d.binCount = 0; 166 d.binCount = 0;
167 d.sampleType = OutputDescriptor::VariableSampleRate; 167 d.sampleType = OutputDescriptor::VariableSampleRate;
168 d.sampleRate = 0;
168 list.push_back(d); 169 list.push_back(d);
169 170
170 d.identifier = "silencelevel"; 171 d.identifier = "silencelevel";
171 d.name = "Silence Test"; 172 d.name = "Silence Test";
172 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends"; 173 d.description = "Return a function that switches from 1 to 0 when silence falls, and back again when it ends";
176 d.minValue = 0; 177 d.minValue = 0;
177 d.maxValue = 1; 178 d.maxValue = 1;
178 d.isQuantized = true; 179 d.isQuantized = true;
179 d.quantizeStep = 1; 180 d.quantizeStep = 1;
180 d.sampleType = OutputDescriptor::VariableSampleRate; 181 d.sampleType = OutputDescriptor::VariableSampleRate;
182 d.sampleRate = 0;
181 list.push_back(d); 183 list.push_back(d);
182 184
183 return list; 185 return list;
184 } 186 }
185 187
210 212
211 fvec_t vec; 213 fvec_t vec;
212 vec.length = incr * 4; 214 vec.length = incr * 4;
213 vec.channels = m_channelCount; 215 vec.channels = m_channelCount;
214 vec.data = m_tmpptrs; 216 vec.data = m_tmpptrs;
215
216 if (silent) {
217 std::cerr << "silence at " << timestamp << std::endl;
218 }
219 217
220 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) { 218 for (size_t i = 0; i < m_stepSize - incr * 4; i += incr) {
221 for (size_t j = 0; j < m_channelCount; ++j) { 219 for (size_t j = 0; j < m_channelCount; ++j) {
222 m_tmpptrs[j] = m_ibuf->data[j] + i; 220 m_tmpptrs[j] = m_ibuf->data[j] + i;
223 } 221 }
224 bool subsilent = aubio_silence_detection(&vec, m_threshold); 222 bool subsilent = aubio_silence_detection(&vec, m_threshold);
225 if (silent == subsilent) { 223 if (silent == subsilent) {
226 std::cerr << "silent == subsilent at " << i << " after" << std::endl;
227 off = i; 224 off = i;
228 break; 225 break;
229 } 226 }
230 } 227 }
231 228
234 for (size_t j = 0; j < m_channelCount; ++j) { 231 for (size_t j = 0; j < m_channelCount; ++j) {
235 m_tmpptrs[j] = m_pbuf->data[j] + m_stepSize - i - incr; 232 m_tmpptrs[j] = m_pbuf->data[j] + m_stepSize - i - incr;
236 } 233 }
237 bool subsilent = aubio_silence_detection(&vec, m_threshold); 234 bool subsilent = aubio_silence_detection(&vec, m_threshold);
238 if (!subsilent) { 235 if (!subsilent) {
239 std::cerr << "non-silence at " << i << " samples before" << std::endl;
240 off = -(long)i; 236 off = -(long)i;
241 break; 237 break;
242 } else {
243 std::cerr << "silence at " << i << " samples before" << std::endl;
244 } 238 }
245 } 239 }
246 } else { 240 } else {
247 } 241 }
248 242