44 |
dmsg(1,("Caching initial samples...")); |
dmsg(1,("Caching initial samples...")); |
45 |
::gig::Region* pRgn = pInstrument->GetFirstRegion(); |
::gig::Region* pRgn = pInstrument->GetFirstRegion(); |
46 |
while (pRgn) { |
while (pRgn) { |
47 |
if (!pRgn->GetSample()->GetCache().Size) { |
if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) { |
48 |
dmsg(2,("C")); |
dmsg(2,("C")); |
49 |
CacheInitialSamples(pRgn->GetSample(), dynamic_cast<gig::Engine*>(pConsumer)); |
CacheInitialSamples(pRgn->GetSample(), dynamic_cast<gig::Engine*>(pConsumer)); |
50 |
} |
} |
90 |
* @param pEngine - pointer to Gig Engine which caused this call |
* @param pEngine - pointer to Gig Engine which caused this call |
91 |
*/ |
*/ |
92 |
void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine) { |
void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine) { |
93 |
if (!pSample || pSample->GetCache().Size) return; |
if (!pSample || pSample->GetCache().Size || !pSample->SamplesTotal) return; |
94 |
if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) { |
if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) { |
95 |
// Sample is too short for disk streaming, so we load the whole |
// Sample is too short for disk streaming, so we load the whole |
96 |
// sample into RAM and place 'pAudioIO->FragmentSize << MAX_PITCH' |
// sample into RAM and place 'pAudioIO->FragmentSize << MAX_PITCH' |
97 |
// number of '0' samples (silence samples) behind the official buffer |
// number of '0' samples (silence samples) behind the official buffer |
98 |
// border, to allow the interpolator do it's work even at the end of |
// border, to allow the interpolator do it's work even at the end of |
99 |
// the sample. |
// the sample. |
100 |
::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)); |
101 |
|
const uint silenceSamples = (pEngine->pAudioOutputDevice->MaxSamplesPerCycle() << MAX_PITCH) + 3; |
102 |
|
::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(silenceSamples); |
103 |
dmsg(4,("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize)); |
dmsg(4,("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize)); |
104 |
} |
} |
105 |
else { // we only cache NUM_RAM_PRELOAD_SAMPLES and stream the other sample points from disk |
else { // we only cache NUM_RAM_PRELOAD_SAMPLES and stream the other sample points from disk |