thestk / stk

The Synthesis ToolKit in C++ (STK) is a set of open source audio signal processing and algorithmic synthesis classes written in the C++ programming language.
https://ccrma.stanford.edu/software/stk/
Other
1.01k stars 179 forks source link

Issues after creating stk::FreeVerb instances repeatedly #120

Open renetik opened 2 years ago

renetik commented 2 years ago

I discovered that reverb effect is changing sound after I create remove repeatedly that I made simple test like this and it proved my theory that some value or something get modified and is shared across instances..

You can reproduce it like this:

 stk::FreeVerb *freeVerb20 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb19 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb18 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb17 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb16 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb15 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb14 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb13 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb12 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb11 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb10 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb9 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb8 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb7 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb6 = new stk::FreeVerb();
    stk::FreeVerb *freeVerb = new stk::FreeVerb();

Here just use the last instance .. It has broken sound..
I am trying to find out why now but not yet with luck.

renetik commented 2 years ago

Ok I fixed it by moving cDelayLengths and aDelayLengths inside constructor like this while commenting it out outside.

FreeVerb::FreeVerb( void )
{
  int cDelayLengths[] = {1617, 1557, 1491, 1422, 1356, 1277, 1188, 1116};
  int aDelayLengths[] = {225, 556, 441, 341};

This way problem is fixed .. looks like library is not used much because I cannot get how could I be alone to face this issue.

renetik commented 2 years ago

Would you be interested if I create pull request ?

garyscavone commented 2 years ago

It is not immediately clear why the global definition outside the scope of the constructor would cause such behaviour but the fix makes sense and I would be happy to have it submitted as a PR. There could be several reasons why this has not come up before, including that example usage to reproduce the problem is not very typical and also because the issue seems like it may be compiler-specific.