Skip to content
This repository
Browse code

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...
commit a72b3b5a1cb8471c08a35f952129f5a57fb16974 1 parent f90b188
Tim Blechmann authored

Showing 1 changed file with 7 additions and 9 deletions. Show diff stats Hide diff stats

  1. +7 9 common/Source/plugins/GrainUGens.cpp
16 common/Source/plugins/GrainUGens.cpp
@@ -101,7 +101,6 @@ struct GrainBuf : public Unit
101 101 {
102 102 int mNumActive, m_channels, mMaxGrains;
103 103 float curtrig;
104   - bool mFirst;
105 104 GrainBufG *mGrains;
106 105 };
107 106
@@ -1189,15 +1188,9 @@ void GrainBuf_next_a(GrainBuf *unit, int inNumSamples)
1189 1188 }
1190 1189 }
1191 1190
1192   -void GrainBuf_next_k(GrainBuf *unit, int inNumSamples)
  1191 +void GrainBuf_next_k(GrainBuf * unit, int inNumSamples)
1193 1192 {
1194 1193 ClearUnitOutputs(unit, inNumSamples);
1195   - if(unit->mFirst){
1196   - unit->mFirst = false;
1197   - float maxGrains = IN0(8);
1198   - unit->mMaxGrains = (int)maxGrains;
1199   - unit->mGrains = (GrainBufG*)RTAlloc(unit->mWorld, unit->mMaxGrains * sizeof(GrainBufG));
1200   - }
1201 1194
1202 1195 GrainBuf_next_play_active(unit, inNumSamples);
1203 1196
@@ -1213,9 +1206,14 @@ void GrainBuf_Ctor(GrainBuf *unit)
1213 1206 SETCALC(GrainBuf_next_a);
1214 1207 else
1215 1208 SETCALC(GrainBuf_next_k);
  1209 +
1216 1210 unit->mNumActive = 0;
1217 1211 unit->curtrig = 0.f;
1218   - unit->mFirst = true;
  1212 +
  1213 + float maxGrains = IN0(8);
  1214 + unit->mMaxGrains = (int)maxGrains;
  1215 + unit->mGrains = (GrainBufG*)RTAlloc(unit->mWorld, unit->mMaxGrains * sizeof(GrainBufG));
  1216 +
1219 1217 GrainBuf_next_k(unit, 1); // should be _k
1220 1218 }
1221 1219

0 comments on commit a72b3b5

Please sign in to comment.
Something went wrong with that request. Please try again.