Page 1 of 1

Loading instruments/samples

Posted: Fri Feb 08, 2008 12:03 pm
by dahnielson
Here's a fairly n00bie question for ya': When loading an instrument, are all samples in the .gig loaded or is it just the samples referenced by the loaded instrument?

Re: Loading instruments/samples

Posted: Fri Feb 08, 2008 2:36 pm
by cuse
But definitely an eligible question. The meta informations of all samples in the instrument's gig file will be loaded in RAM (small though), but only the referenced samples will be cached. If you're interested in the code, you can find it in src/engines/gig/InstrumenResourceManager.cpp, method InstrumentResourceManager::Create() (around line 481), here the relevant part:

Code: Select all

::gig::Region* pRgn = pInstrument->GetFirstRegion();
while (pRgn) {
    // we randomly schedule 90% for the .gig file loading and the remaining 10% now for sample caching
    const float localProgress = 0.9f + 0.1f * (float) iRegion / (float) pInstrument->Regions;
    DispatchResourceProgressEvent(Key, localProgress);

    if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) {
        CacheInitialSamples(pRgn->GetSample(), (gig::EngineChannel*) pConsumer);
    for (uint i = 0; i < pRgn->DimensionRegions; i++) {
        CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, (gig::EngineChannel*) pConsumer);

    pRgn = pInstrument->GetNextRegion();
Furthermore, if you change sample reference(s) on the fly with gigedit, the respective unused samples will immediately be freed from memory as well.

But one thing you might argue, is that we also cache samples referenced by the Region (as you see in the code above). Even though the gig format only plays samples referenced by the Dimension Regions (the subregions of a region if you will). The gig synthesis format doesnt care about the samples referenced by Regions at all. That's just an unused legacy of the DLS format. So that's one thing we could drop out. Shouldn't make much a difference in practice though I think.

Re: Loading instruments/samples

Posted: Fri Feb 08, 2008 3:17 pm
by dahnielson
Ok, that makes sense in regards to the choice of loading strategy specified in a instrument map. The reason I asked was because I wondered if there was an added "cost" to load a second instrument from the same gig file in terms of cached samples or if it came free. Thinking about it more I realized that only referenced samples was dealt with otherwise it would be a huge waste of sample streams. :geek:

Re: Loading instruments/samples

Posted: Sat Feb 09, 2008 11:19 pm
by Alex
Good question this one.
There's definitely a difference when accessing instruments (articulations?) from the same gig file. My violin down bows load quickly enough, but when i add the up bows from the same gig file, they load almost instantly.

Makes short work of loading a complete orchestra!