Mercurial > hg > cepstral-pitchtracker
changeset 73:939cf0e86268
Filter nans, improve tests
| author | Chris Cannam |
|---|---|
| date | Thu, 23 Mar 2017 14:50:33 +0000 |
| parents | 487321083d51 |
| children | 759ea6e988fe |
| files | Cepstrum.h Makefile.linux64 MeanFilter.h test/TestCepstrum.cpp |
| diffstat | 4 files changed, 24 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Cepstrum.h Wed Feb 03 13:17:32 2016 +0000 +++ b/Cepstrum.h Thu Mar 23 14:50:33 2017 +0000 @@ -22,8 +22,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef _CEPSTRUM_H_ -#define _CEPSTRUM_H_ +#ifndef CEPSTRUM_H +#define CEPSTRUM_H #include "vamp-sdk/FFT.h" #include <cmath> @@ -70,7 +70,9 @@ for (int i = 0; i < hs; ++i) { - double power = in[i*2] * in[i*2] + in[i*2+1] * in[i*2+1]; + double re = in[i*2]; + double im = in[i*2+1]; + double power = re * re + im * im; double mag = sqrt(power); magmean += mag;
--- a/Makefile.linux64 Wed Feb 03 13:17:32 2016 +0000 +++ b/Makefile.linux64 Thu Mar 23 14:50:33 2017 +0000 @@ -1,5 +1,5 @@ -CFLAGS := -Wall -g -fPIC +CFLAGS := -Wall -O2 -fPIC CXXFLAGS := $(CFLAGS) PLUGIN_LDFLAGS := -shared -Wl,-Bstatic -lvamp-sdk -Wl,-Bdynamic -Wl,-Bsymbolic -Wl,-z,defs -Wl,--version-script=vamp-plugin.map
--- a/MeanFilter.h Wed Feb 03 13:17:32 2016 +0000 +++ b/MeanFilter.h Thu Mar 23 14:50:33 2017 +0000 @@ -22,8 +22,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef _MEAN_FILTER_H_ -#define _MEAN_FILTER_H_ +#ifndef MEAN_FILTER_H +#define MEAN_FILTER_H class MeanFilter { @@ -59,11 +59,18 @@ for (int j = -half; j <= half; ++j) { int ix = i + j + offset; if (ix >= 0 && ix < m) { - v += in[ix]; - ++n; + double value = in[ix]; + if (value == value) { // i.e. not NaN + v += value; + } + ++n; } } - out[i] = v / n; + if (n > 0) { + out[i] = v / n; + } else { + out[i] = 0.0; + } } }
--- a/test/TestCepstrum.cpp Wed Feb 03 13:17:32 2016 +0000 +++ b/test/TestCepstrum.cpp Thu Mar 23 14:50:33 2017 +0000 @@ -53,6 +53,12 @@ BOOST_CHECK_SMALL(out[1] - out[7], 1e-14); BOOST_CHECK_SMALL(out[2] - out[6], 1e-14); BOOST_CHECK_SMALL(out[3] - out[5], 1e-14); + double mmcheck = 0; + for (int i = 0; i < 5; ++i) { + mmcheck += sqrt(in[i*2] * in[i*2] + in[i*2+1] * in[i*2+1]); + } + mmcheck /= 5; + BOOST_CHECK_EQUAL(mm, mmcheck); } BOOST_AUTO_TEST_CASE(oneHarmonic)