/[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 410 by schoenebeck, Sat Jan 29 15:17:59 2005 UTC revision 411 by schoenebeck, Sat Feb 26 02:01:14 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 24  Line 25 
25    
26  #include "InstrumentResourceManager.h"  #include "InstrumentResourceManager.h"
27    
28    // We need to know the maximum number of sample points which are going to
29    // be processed for each render cycle of the audio output driver, to know
30    // how much initial sample points we need to cache into RAM. If the given
31    // sampler channel does not have an audio output device assigned yet
32    // though, we simply use this default value.
33    #define GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE     128
34    
35  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
36    
37      ::gig::Instrument* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) {      ::gig::Instrument* InstrumentResourceManager::Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) {
# Line 46  namespace LinuxSampler { namespace gig { Line 54  namespace LinuxSampler { namespace gig {
54          while (pRgn) {          while (pRgn) {
55              if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) {              if (pRgn->GetSample() && !pRgn->GetSample()->GetCache().Size) {
56                  dmsg(2,("C"));                  dmsg(2,("C"));
57                  CacheInitialSamples(pRgn->GetSample(), dynamic_cast<gig::Engine*>(pConsumer));                  CacheInitialSamples(pRgn->GetSample(), dynamic_cast<gig::EngineChannel*>(pConsumer));
58              }              }
59              for (uint i = 0; i < pRgn->DimensionRegions; i++) {              for (uint i = 0; i < pRgn->DimensionRegions; i++) {
60                  CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, dynamic_cast<gig::Engine*>(pConsumer));                  CacheInitialSamples(pRgn->pDimensionRegions[i]->pSample, dynamic_cast<gig::EngineChannel*>(pConsumer));
61              }              }
62    
63              pRgn = pInstrument->GetNextRegion();              pRgn = pInstrument->GetNextRegion();
# Line 60  namespace LinuxSampler { namespace gig { Line 68  namespace LinuxSampler { namespace gig {
68          instr_entry_t* pEntry = new instr_entry_t;          instr_entry_t* pEntry = new instr_entry_t;
69          pEntry->iInstrument   = Key.iInstrument;          pEntry->iInstrument   = Key.iInstrument;
70          pEntry->pGig          = pGig;          pEntry->pGig          = pGig;
71          // and this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond'          
72          pEntry->MaxSamplesPerCycle = dynamic_cast<gig::Engine*>(pConsumer)->pAudioOutputDevice->MaxSamplesPerCycle();          gig::EngineChannel* pEngineChannel = dynamic_cast<gig::EngineChannel*>(pConsumer);
73            // and we save this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond'
74            pEntry->MaxSamplesPerCycle =
75                (pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()
76                                              : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;
77          pArg = pEntry;          pArg = pEntry;
78    
79          return pInstrument;          return pInstrument;
# Line 75  namespace LinuxSampler { namespace gig { Line 87  namespace LinuxSampler { namespace gig {
87    
88      void InstrumentResourceManager::OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg) {      void InstrumentResourceManager::OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg) {
89          instr_entry_t* pEntry = (instr_entry_t*) pArg;          instr_entry_t* pEntry = (instr_entry_t*) pArg;
90          if (pEntry->MaxSamplesPerCycle < dynamic_cast<gig::Engine*>(pConsumer)->pAudioOutputDevice->MaxSamplesPerCycle()) {          gig::EngineChannel* pEngineChannel = dynamic_cast<gig::EngineChannel*>(pConsumer);
91            uint maxSamplesPerCycle =
92                (pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()
93                                              : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;
94            if (pEntry->MaxSamplesPerCycle < maxSamplesPerCycle) {
95              Update(pResource, pConsumer);              Update(pResource, pConsumer);
96          }          }
97      }      }
# Line 87  namespace LinuxSampler { namespace gig { Line 103  namespace LinuxSampler { namespace gig {
103       *  samples is needed to compensate disk reading latency.       *  samples is needed to compensate disk reading latency.
104       *       *
105       *  @param pSample - points to the sample to be cached       *  @param pSample - points to the sample to be cached
106       *  @param pEngine - pointer to Gig Engine which caused this call       *  @param pEngineChannel - pointer to Gig Engine Channel which caused this call
107       */       */
108      void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine) {      void InstrumentResourceManager::CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel) {
109          if (!pSample || pSample->GetCache().Size || !pSample->SamplesTotal) return;          if (!pSample || pSample->GetCache().Size || !pSample->SamplesTotal) return;
110          if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) {          if (pSample->SamplesTotal <= NUM_RAM_PRELOAD_SAMPLES) {
111              // Sample is too short for disk streaming, so we load the whole              // Sample is too short for disk streaming, so we load the whole
# Line 98  namespace LinuxSampler { namespace gig { Line 114  namespace LinuxSampler { namespace gig {
114              // 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
115              // the sample.              // the sample.
116              dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %d)\n", pSample->pInfo->Name.c_str(), pSample->SamplesTotal));              dmsg(3,("Caching whole sample (sample name: \"%s\", sample size: %d)\n", pSample->pInfo->Name.c_str(), pSample->SamplesTotal));
117              const uint silenceSamples = (pEngine->pAudioOutputDevice->MaxSamplesPerCycle() << MAX_PITCH) + 3;              const uint maxSamplesPerCycle =
118                    (pEngineChannel->GetEngine()) ? dynamic_cast<gig::Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle()
119                                                  : GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE;
120                const uint silenceSamples = (maxSamplesPerCycle << MAX_PITCH) + 3;
121              ::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(silenceSamples);              ::gig::buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(silenceSamples);
122              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));
123          }          }

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

  ViewVC Help
Powered by ViewVC