/[svn]/linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 411 by schoenebeck, Sat Feb 26 02:01:14 2005 UTC revision 420 by schoenebeck, Thu Mar 3 03:25:17 2005 UTC
# Line 105  namespace LinuxSampler { namespace gig { Line 105  namespace LinuxSampler { namespace gig {
105       *  @param pSample - points to the sample to be cached       *  @param pSample - points to the sample to be cached
106       *  @param pEngineChannel - pointer to Gig Engine Channel which caused this call       *  @param pEngineChannel - pointer to Gig Engine Channel which caused this call
107       */       */
108      void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel) {      void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel) {        
109          if (!pSample || pSample->GetCache().Size || !pSample->SamplesTotal) return;          if (!pSample) {
110                dmsg(1,("gig::InstrumentResourceManager: Warning, skipping sample (pSample == NULL)\n"));
111                return;
112            }
113            if (!pSample->SamplesTotal) return; // skip zero size samples
114            
115          if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) {          if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) {
116              // Sample is too short for disk streaming, so we load the whole              // Sample is too short for disk streaming, so we load the whole
117              // sample into RAM and place 'pAudioIO->FragmentSize << MAX_PITCH'              // sample into RAM and place 'pAudioIO->FragmentSize << MAX_PITCH'
118              // number of '0' samples (silence samples) behind the official buffer              // number of '0' samples (silence samples) behind the official buffer
119              // 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
120              // the sample.              // the sample.            
             dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %d)\n", pSample->pInfo->Name.c_str(), pSample->SamplesTotal));  
121              const uint maxSamplesPerCycle =              const uint maxSamplesPerCycle =
122                  (pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()                  (pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()
123                                                : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;                                                : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;
124              const uint silenceSamples = (maxSamplesPerCycle << MAX_PITCH) + 3;              const uint neededSilenceSamples = (maxSamplesPerCycle << MAX_PITCH) + 3;
125              ::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(silenceSamples);              const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->FrameSize;
126              dmsg(4,("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize));              if (currentlyCachedSilenceSamples < neededSilenceSamples) {
127                    dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %d)\n", pSample->pInfo->Name.c_str(), pSample->SamplesTotal));
128                    ::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(neededSilenceSamples);
129                    dmsg(4,("Cached %d Bytes, %d silence bytes.\n", buf.Size, buf.NullExtensionSize));
130                }
131          }          }
132          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
133              pSample->LoadSampleData(NUM_RAM_PRELOAD_SAMPLES);              if (!pSample->GetCache().Size) pSample->LoadSampleData(NUM_RAM_PRELOAD_SAMPLES);
134          }          }
135    
136          if (!pSample->GetCache().Size) std::cerr << "Unable to cache sample - maybe memory full!" << std::endl << std::flush;          if (!pSample->GetCache().Size) std::cerr << "Unable to cache sample - maybe memory full!" << std::endl << std::flush;

Legend:
Removed from v.411  
changed lines
  Added in v.420

  ViewVC Help
Powered by ViewVC