diff --git a/src/algorithms/tonal/multipitchklapuri.h b/src/algorithms/tonal/multipitchklapuri.h index 184b540e5..923233749 100644 --- a/src/algorithms/tonal/multipitchklapuri.h +++ b/src/algorithms/tonal/multipitchklapuri.h @@ -98,7 +98,7 @@ class MultiPitchKlapuri : public Algorithm { declareParameter("magnitudeThreshold", "spectral peak magnitude threshold (maximum allowed difference from the highest peak in dBs)", "[0,inf)", 40); declareParameter("magnitudeCompression", "magnitude compression parameter for the salience function (=0 for maximum compression, =1 for no compression)", "(0,1]", 1.0); declareParameter("numberHarmonics", "number of considered harmonics", "[1,inf)", 10); - declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "(0,1)", 0.8); + declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "[0,1]", 0.8); // pitch salience function peaks declareParameter("minFrequency", "the minimum allowed frequency for salience function peaks (ignore peaks below) [Hz]", "[0,inf)", 80.0); diff --git a/src/algorithms/tonal/multipitchmelodia.h b/src/algorithms/tonal/multipitchmelodia.h index dcc55d43a..4cabca280 100644 --- a/src/algorithms/tonal/multipitchmelodia.h +++ b/src/algorithms/tonal/multipitchmelodia.h @@ -84,7 +84,7 @@ class MultiPitchMelodia : public Algorithm { declareParameter("magnitudeThreshold", "spectral peak magnitude threshold (maximum allowed difference from the highest peak in dBs)", "[0,inf)", 40); declareParameter("magnitudeCompression", "magnitude compression parameter for the salience function (=0 for maximum compression, =1 for no compression)", "(0,1]", 1.0); declareParameter("numberHarmonics", "number of considered harmonics", "[1,inf)", 20); - declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "(0,1)", 0.8); + declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "[0,1]", 0.8); // pitch contour tracking declareParameter("peakFrameThreshold", "per-frame salience threshold factor (fraction of the highest peak salience in a frame)", "[0,1]", 0.9); @@ -167,7 +167,7 @@ class MultiPitchMelodia : public AlgorithmComposite { declareParameter("magnitudeThreshold", "peak magnitude threshold (maximum allowed difference from the highest peak in dBs)", "[0,inf)", 40); declareParameter("magnitudeCompression", "magnitude compression parameter (=0 for maximum compression, =1 for no compression)", "(0,1]", 1.0); declareParameter("numberHarmonics", "number of considered hamonics", "[1,inf)", 20); - declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "(0,1)", 0.8); + declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "[0,1]", 0.8); // pitch salience function peaks declareParameter("minFrequency", "the minimum allowed frequency for salience function peaks (ignore peaks below) [Hz]", "[0,inf)", 80.0); diff --git a/src/algorithms/tonal/pitchmelodia.h b/src/algorithms/tonal/pitchmelodia.h index 00b4b0daf..62ab2d16e 100644 --- a/src/algorithms/tonal/pitchmelodia.h +++ b/src/algorithms/tonal/pitchmelodia.h @@ -86,7 +86,7 @@ class PitchMelodia : public Algorithm { declareParameter("magnitudeThreshold", "spectral peak magnitude threshold (maximum allowed difference from the highest peak in dBs)", "[0,inf)", 40); declareParameter("magnitudeCompression", "magnitude compression parameter for the salience function (=0 for maximum compression, =1 for no compression)", "(0,1]", 1.0); declareParameter("numberHarmonics", "number of considered harmonics", "[1,inf)", 20); - declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "(0,1)", 0.8); + declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "[0,1]", 0.8); // pitch contour tracking declareParameter("peakFrameThreshold", "per-frame salience threshold factor (fraction of the highest peak salience in a frame)", "[0,1]", 0.9); @@ -170,7 +170,7 @@ class PitchMelodia : public AlgorithmComposite { declareParameter("magnitudeThreshold", "peak magnitude threshold (maximum allowed difference from the highest peak in dBs)", "[0,inf)", 40); declareParameter("magnitudeCompression", "magnitude compression parameter (=0 for maximum compression, =1 for no compression)", "(0,1]", 1.0); declareParameter("numberHarmonics", "number of considered hamonics", "[1,inf)", 20); - declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "(0,1)", 0.8); + declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "[0,1]", 0.8); // pitch salience function peaks declareParameter("minFrequency", "the minimum allowed frequency for salience function peaks (ignore peaks below) [Hz]", "[0,inf)", 80.0); diff --git a/src/algorithms/tonal/predominantpitchmelodia.h b/src/algorithms/tonal/predominantpitchmelodia.h index 9d6d75d4b..6d1a4fee3 100644 --- a/src/algorithms/tonal/predominantpitchmelodia.h +++ b/src/algorithms/tonal/predominantpitchmelodia.h @@ -86,7 +86,7 @@ class PredominantPitchMelodia : public Algorithm { declareParameter("magnitudeThreshold", "spectral peak magnitude threshold (maximum allowed difference from the highest peak in dBs)", "[0,inf)", 40); declareParameter("magnitudeCompression", "magnitude compression parameter for the salience function (=0 for maximum compression, =1 for no compression)", "(0,1]", 1.0); declareParameter("numberHarmonics", "number of considered harmonics", "[1,inf)", 20); - declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "(0,1)", 0.8); + declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "[0,1]", 0.8); // pitch contour tracking declareParameter("peakFrameThreshold", "per-frame salience threshold factor (fraction of the highest peak salience in a frame)", "[0,1]", 0.9); @@ -171,7 +171,7 @@ class PredominantPitchMelodia : public AlgorithmComposite { declareParameter("magnitudeThreshold", "peak magnitude threshold (maximum allowed difference from the highest peak in dBs)", "[0,inf)", 40); declareParameter("magnitudeCompression", "magnitude compression parameter (=0 for maximum compression, =1 for no compression)", "(0,1]", 1.0); declareParameter("numberHarmonics", "number of considered hamonics", "[1,inf)", 20); - declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "(0,1)", 0.8); + declareParameter("harmonicWeight", "harmonic weighting parameter (weight decay ratio between two consequent harmonics, =1 for no decay)", "[0,1]", 0.8); // pitch salience function peaks declareParameter("minFrequency", "the minimum allowed frequency for salience function peaks (ignore peaks below) [Hz]", "[0,inf)", 80.0); diff --git a/test/src/unittests/tonal/test_multipitchklapuri.py b/test/src/unittests/tonal/test_multipitchklapuri.py new file mode 100644 index 000000000..d20250a31 --- /dev/null +++ b/test/src/unittests/tonal/test_multipitchklapuri.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python + +# Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra +# +# This file is part of Essentia +# +# Essentia is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the Free +# Software Foundation (FSF), either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the Affero GNU General Public License +# version 3 along with this program. If not, see http://www.gnu.org/licenses/ + + +from numpy import * +from essentia_test import * + + +class TestMultiPitchKlapuri(TestCase): + + def testZero(self): + signal = zeros(1024) + pitch = MultiPitchMelodia()(signal) + self.assertEqualVector(pitch, [0., 0., 0., 0., 0., 0., 0., 0., 0.]) + + def testInvalidParam(self): + self.assertConfigureFails(MultiPitchKlapuri(), {'binResolution': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'frameSize': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'harmonicWeight': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'hopSize': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'magnitudeCompression': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'magnitudeCompression': 2}) + self.assertConfigureFails(MultiPitchKlapuri(), {'magnitudeThreshold': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'maxFrequency': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'minFrequency': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'numberHarmonics': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'referenceFrequency': -1}) + self.assertConfigureFails(MultiPitchKlapuri(), {'sampleRate': -1}) + + def testOnes(self): + # FIXME. Need to derive a rational why this output occurs for a constant input + signal = ones(1024) + pitch = MultiPitchKlapuri()(signal) + expectedPitch= [[ 92.498886, 184.99854 ], + [108.110695, 151.1358 ], + [108.73698, 151.1358 ], + [108.73698, 151.1358 ], + [108.73698, 151.1358 ], + [108.110695, 151.1358 ], + [ 92.498886, 184.99854 ]] + + self.assertEqual(len(pitch), 7) + index=0 + while (index