Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase kMaxSynthGrains in JoshGrainUGens #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dyfer
Copy link
Member

@dyfer dyfer commented Jun 13, 2019

Occasionally I am running into exceeding the number of grains.
This just arbitrarily exceeds increases the maximum, but maybe there is a better way to do this?

@joshpar
Copy link
Member

joshpar commented Jun 13, 2019

thanks @dyfer - there is, actually, and we do it in the main line grain UGens that were based on these UGens. Basically, you add a parameter in the UGen that lets the user pass in the max number of grains, and RTAlloc the space for them. That is a big change to THESE UGens though and may break backward compatibility. You can see an example from this page: https://github.com/supercollider/supercollider/blob/develop/server/plugins/GrainUGens.cpp

void GrainFM_next_k(GrainFM* unit, int inNumSamples) {
    ClearUnitOutputs(unit, inNumSamples);

    if (unit->mFirst) {
        unit->mFirst = false;
        float maxGrains = IN0(7);
        unit->mMaxGrains = (int)maxGrains;
        unit->mGrains = (GrainFMG*)RTAlloc(unit->mWorld, unit->mMaxGrains * sizeof(GrainFMG));
    }

    GrainFM_next_play_active(unit, inNumSamples);

    float trig = IN0(0);
    if ((unit->curtrig <= 0) && (trig > 0.0))
        GrainFM_next_start_new<false>(unit, inNumSamples, 0);

    unit->curtrig = trig;
}

void GrainFM_Ctor(GrainFM* unit) {
    if (INRATE(0) == calc_FullRate)
        SETCALC(GrainFM_next_a);
    else
        SETCALC(GrainFM_next_k);
    int tableSizeSin = ft->mSineSize;
    unit->m_lomask = (tableSizeSin - 1) << 3;
    unit->m_radtoinc = tableSizeSin * (rtwopi * 65536.);
    unit->m_cpstoinc = tableSizeSin * SAMPLEDUR * 65536.;
    unit->curtrig = 0.f;
    unit->mNumActive = 0;
    unit->mFirst = true;
    GrainFM_next_k(unit, 1);
}

Notice the RTAlloc in next_k IF this is the first run. The value is read from the UGen input, then allocated. I'd suggest first seeing if something similar can be done without breaking backward compatibility, and if so, that would be a better fix. If backward compatibility would be broken, I'm fine with what you have already submitted.... please let me know!

@joshpar joshpar self-requested a review June 13, 2019 17:26
Copy link
Member

@joshpar joshpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see main comment on thread and let me know what you think.

@dyfer
Copy link
Member Author

dyfer commented Jun 13, 2019

Thanks @joshpar I'll look into it.
It was a change I made a while back to fix the number of grains. I'll try to look at the "proper" fix later and will update this PR then.

@capital-G
Copy link
Contributor

bump @dyfer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for review response
Development

Successfully merging this pull request may close these issues.

3 participants