Skip to content

Commit

Permalink
Merge pull request #550 from pabloEntropia/gfcc-thresholding
Browse files Browse the repository at this point in the history
GFCC: Add silenceThreshold parameter #543
  • Loading branch information
dbogdanov authored Jan 5, 2017
2 parents 9a35819 + 3d354ff commit fe011a0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
43 changes: 20 additions & 23 deletions src/algorithms/spectral/gfcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ void GFCC::configure() {
"outputSize", parameter("numberCoefficients"),
INHERIT("dctType"));
_logbands.resize(parameter("numberBands").toInt());
setCompressor(parameter("logType").toString());

_logType = parameter("logType").toLower();
_silenceThreshold = parameter("silenceThreshold").toReal();
_dbSilenceThreshold = 10 * log10(_silenceThreshold);
_logSilenceThreshold = log(_silenceThreshold);
}

void GFCC::compute() {
Expand All @@ -59,11 +63,22 @@ void GFCC::compute() {
_gtFilter->output("bands").set(bands);
_gtFilter->compute();




for (int i=0; i<int(bands.size()); ++i) {
_logbands[i] = (*_compressor)(bands[i]);
if (_logType == "dbpow") {
_logbands[i] = pow2db(bands[i], _silenceThreshold, _dbSilenceThreshold);
}
else if (_logType == "dbamp") {
_logbands[i] = amp2db(bands[i], _silenceThreshold, _dbSilenceThreshold);
}
else if (_logType == "log") {
_logbands[i] = lin2log(bands[i], _silenceThreshold, _logSilenceThreshold);
}
else if (_logType == "natural") {
_logbands[i] = bands[i];
}
else {
throw EssentiaException("GFCC: Bad 'logType' parameter");
}
}

// compute the DCT of these bands
Expand All @@ -72,21 +87,3 @@ void GFCC::compute() {
_dct->compute();
}

void GFCC::setCompressor(std::string logType){
if (logType == "natural"){
_compressor = linear;
}
else if (logType == "dbpow"){
_compressor = pow2db;
}
else if (logType == "dbamp"){
_compressor = amp2db;
}
else if (logType == "log"){
_compressor = log;
}
else{
throw EssentiaException("GFCC: Bad 'logType' parameter");
}

}
10 changes: 5 additions & 5 deletions src/algorithms/spectral/gfcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ class GFCC : public Algorithm {

std::vector<Real> _logbands;

typedef Real (*funcPointer)(Real);
funcPointer _compressor;

void setCompressor(std::string logType);

std::string _logType;
Real _silenceThreshold;
Real _dbSilenceThreshold;
Real _logSilenceThreshold;

public:
GFCC() {
Expand All @@ -66,6 +65,7 @@ class GFCC : public Algorithm {
declareParameter("lowFrequencyBound", "the lower bound of the frequency range [Hz]", "[0,inf)", 40.);
declareParameter("highFrequencyBound", "the upper bound of the frequency range [Hz]", "(0,inf)", 22050.);
declareParameter("type", "use magnitude or power spectrum","{magnitude,power}", "power");
declareParameter("silenceThreshold", "silence threshold for computing log-energy bands", "(0,inf)", 1e-9);
declareParameter("logType","logarithmic compression type. Use 'dbpow' if working with power and 'dbamp' if working with magnitudes","{natural,dbpow,dbamp,log}","dbamp");
declareParameter("dctType", "the DCT type", "[2,3]", 2);
}
Expand Down
3 changes: 2 additions & 1 deletion test/src/unittest/spectral/test_gfcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def InitGFCC(self, numCoeffs, logType):
sampleRate = 44100,
numberBands = 40,
numberCoefficients = numCoeffs,
silenceThreshold = 1e-9,
lowFrequencyBound = 0,
highFrequencyBound = 11000,
logType = logType)
Expand All @@ -52,7 +53,7 @@ def testRegression(self):
def testZero(self):
# zero input should return dct(lin2db(0)). Try with different sizes
size = 1025
val = amp2db(0)
val = 2 * 10 * np.log10(1e-9)
expected = DCT(inputSize=40, outputSize=13)([val for x in range(40)])
while (size > 256 ):
bands, gfcc = GFCC(inputSize = size)(zeros(size))
Expand Down

0 comments on commit fe011a0

Please sign in to comment.