Permalink
Browse files

GrainBuf: allocate grain memory only during constructor

Signed-off-by: Tim Blechmann <tim@klingt.org>

git-svn-id: https://supercollider.svn.sourceforge.net/svnroot/supercollider/trunk@9908 a380766d-ff14-0410-b294-a243070f3f08
  • Loading branch information...
1 parent f90b188 commit a72b3b5a1cb8471c08a35f952129f5a57fb16974 Tim Blechmann committed Mar 1, 2010
Showing with 7 additions and 9 deletions.
  1. +7 −9 common/Source/plugins/GrainUGens.cpp
@@ -101,7 +101,6 @@ struct GrainBuf : public Unit
{
int mNumActive, m_channels, mMaxGrains;
float curtrig;
- bool mFirst;
GrainBufG *mGrains;
};
@@ -1189,15 +1188,9 @@ void GrainBuf_next_a(GrainBuf *unit, int inNumSamples)
}
}
-void GrainBuf_next_k(GrainBuf *unit, int inNumSamples)
+void GrainBuf_next_k(GrainBuf * unit, int inNumSamples)
{
ClearUnitOutputs(unit, inNumSamples);
- if(unit->mFirst){
- unit->mFirst = false;
- float maxGrains = IN0(8);
- unit->mMaxGrains = (int)maxGrains;
- unit->mGrains = (GrainBufG*)RTAlloc(unit->mWorld, unit->mMaxGrains * sizeof(GrainBufG));
- }
GrainBuf_next_play_active(unit, inNumSamples);
@@ -1213,9 +1206,14 @@ void GrainBuf_Ctor(GrainBuf *unit)
SETCALC(GrainBuf_next_a);
else
SETCALC(GrainBuf_next_k);
+
unit->mNumActive = 0;
unit->curtrig = 0.f;
- unit->mFirst = true;
+
+ float maxGrains = IN0(8);
+ unit->mMaxGrains = (int)maxGrains;
+ unit->mGrains = (GrainBufG*)RTAlloc(unit->mWorld, unit->mMaxGrains * sizeof(GrainBufG));
+
GrainBuf_next_k(unit, 1); // should be _k
}

0 comments on commit a72b3b5

Please sign in to comment.