3.3beta: MFCC fails to init outputs in ctor (fix attached) #79
Description
[Issue migrated from SourceForge | ID: 2612642 | Submitted by 'danstowell']
[http://sourceforge.net/support/tracker.php?aid=2612642]
The ctor for the MFCC UGen does not intialise the outputs (e.g. ZOUT0(0)=0.f to start off at zero), which means the very first frame of output is undetermined (I was getting NaNs in my analysis, yuk).
Attached patch fixes this. It also allows MFCC ugen to use LocalBuf. Will commit soon.
Index: Source/plugins/MFCC.cpp
--- Source/plugins/MFCC.cpp(revision 8791)
+++ Source/plugins/MFCC.cpp(working copy)
@@ -98,7 +98,8 @@
unit->m_mfcc = (float*)RTAlloc(unit->mWorld, unit->m_numcoefficients * sizeof(float));
for (j=0; jm_numcoefficients; ++j) {
-unit->m_mfcc[j]= 0.0;
+unit->m_mfcc[j]= 0.f;
+ZOUT0(j) = 0.f;
}
unit->mCalcFunc = (UnitCalcFunc)&MFCC_next;
@@ -108,9 +109,10 @@
void MFCC_Dtor(MFCC *unit)
{
-RTFree(unit->mWorld, unit->m_mfcc);
-RTFree(unit->mWorld, unit->m_bands);
+if(unit->m_mfcc)
+RTFree(unit->mWorld, unit->m_mfcc);
+if(unit->m_bands)
+RTFree(unit->mWorld, unit->m_bands);
}
@@ -151,8 +153,20 @@
int j,k;
World *world = unit->mWorld;
-if (ibufnum >= world->mNumSndBufs) ibufnum = 0;
-SndBuf *buf = world->mSndBufs + ibufnum;
+
+SndBuf *buf;
+if (ibufnum >= world->mNumSndBufs) {
+int localBufNum = ibufnum - world->mNumSndBufs;
+Graph *parent = unit->mParent;
+if(localBufNum <= parent->localBufNum) {
+buf = parent->mLocalSndBufs + localBufNum;
+} else {
+buf = world->mSndBufs;
+}
+} else {
+buf = world->mSndBufs + ibufnum;
+}
+
//int numbins = buf->samples - 2 >> 1;
//assumed in this representation