--- linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp 2004/04/27 09:21:58 56 +++ linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp 2005/01/29 15:17:59 354 @@ -44,7 +44,7 @@ dmsg(1,("Caching initial samples...")); ::gig::Region* pRgn = pInstrument->GetFirstRegion(); while (pRgn) { - if (!pRgn->GetSample()->GetCache().Size) { + if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) { dmsg(2,("C")); CacheInitialSamples(pRgn->GetSample(), dynamic_cast(pConsumer)); } @@ -90,14 +90,16 @@ * @param pEngine - pointer to Gig Engine which caused this call */ void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine) { - if (!pSample || pSample->GetCache().Size) return; + if (!pSample || pSample->GetCache().Size || !pSample->SamplesTotal) return; if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) { // Sample is too short for disk streaming, so we load the whole // sample into RAM and place 'pAudioIO->FragmentSize << MAX_PITCH' // number of '0' samples (silence samples) behind the official buffer // border, to allow the interpolator do it's work even at the end of // the sample. - ::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension((pEngine->pAudioOutputDevice->MaxSamplesPerCycle() << MAX_PITCH) + 3); + dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %d)\n", pSample->pInfo->Name.c_str(), pSample->SamplesTotal)); + const uint silenceSamples = (pEngine->pAudioOutputDevice->MaxSamplesPerCycle() << MAX_PITCH) + 3; + ::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(silenceSamples); dmsg(4,("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize)); } else { // we only cache NUM_RAM_PRELOAD_SAMPLES and stream the other sample points from disk