30 |
#include "../../common/global_private.h" |
#include "../../common/global_private.h" |
31 |
#include "../../plugins/InstrumentEditorFactory.h" |
#include "../../plugins/InstrumentEditorFactory.h" |
32 |
|
|
|
// We need to know the maximum number of sample points which are going to |
|
|
// be processed for each render cycle of the audio output driver, to know |
|
|
// how much initial sample points we need to cache into RAM. If the given |
|
|
// sampler channel does not have an audio output device assigned yet |
|
|
// though, we simply use this default value. |
|
|
#define GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE 128 |
|
|
|
|
33 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
34 |
|
|
35 |
// data stored as long as an instrument resource exists |
// data stored as long as an instrument resource exists |
602 |
pEntry->ID.Index = Key.Index; |
pEntry->ID.Index = Key.Index; |
603 |
pEntry->pGig = pGig; |
pEntry->pGig = pGig; |
604 |
|
|
605 |
|
// (try to resolve the audio device context) |
606 |
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
607 |
|
AudioOutputDevice* pDevice = |
608 |
|
(pEngineChannel) ? dynamic_cast<Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice : NULL; |
609 |
|
|
610 |
// and we save this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond' |
// and we save this to check if we need to reallocate for a engine with higher value of 'MaxSamplesPerSecond' |
611 |
pEntry->MaxSamplesPerCycle = |
pEntry->MaxSamplesPerCycle = |
612 |
(!pEngineChannel) ? 0 /* don't care for instrument editors */ : |
(pDevice) ? pDevice->MaxSamplesPerCycle() : DefaultMaxSamplesPerCycle(); |
613 |
(pEngineChannel->GetEngine()) ? |
|
|
dynamic_cast<Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() |
|
|
: GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; |
|
614 |
pArg = pEntry; |
pArg = pEntry; |
615 |
|
|
616 |
return pInstrument; |
return pInstrument; |
625 |
|
|
626 |
void InstrumentResourceManager::OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg) { |
void InstrumentResourceManager::OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg) { |
627 |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
instr_entry_t* pEntry = (instr_entry_t*) pArg; |
628 |
|
|
629 |
|
// (try to resolve the audio device context) |
630 |
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
EngineChannel* pEngineChannel = dynamic_cast<EngineChannel*>(pConsumer); |
631 |
|
AudioOutputDevice* pDevice = |
632 |
|
(pEngineChannel) ? dynamic_cast<Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice : NULL; |
633 |
|
|
634 |
uint maxSamplesPerCycle = |
uint maxSamplesPerCycle = |
635 |
(pEngineChannel && pEngineChannel->GetEngine()) ? dynamic_cast<Engine*>(pEngineChannel->GetEngine())->pAudioOutputDevice->MaxSamplesPerCycle() |
(pDevice) ? pDevice->MaxSamplesPerCycle() : DefaultMaxSamplesPerCycle(); |
636 |
: GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; |
|
637 |
if (pEntry->MaxSamplesPerCycle < maxSamplesPerCycle) { |
if (pEntry->MaxSamplesPerCycle < maxSamplesPerCycle) { |
638 |
|
dmsg(1,("Completely reloading instrument due to insufficient precached samples ...\n")); |
639 |
Update(pResource, pConsumer); |
Update(pResource, pConsumer); |
640 |
} |
} |
641 |
} |
} |
643 |
void InstrumentResourceManager::DeleteRegionIfNotUsed(::gig::DimensionRegion* pRegion, region_info_t* pRegInfo) { |
void InstrumentResourceManager::DeleteRegionIfNotUsed(::gig::DimensionRegion* pRegion, region_info_t* pRegInfo) { |
644 |
// TODO: we could delete Region and Instrument here if they have become unused |
// TODO: we could delete Region and Instrument here if they have become unused |
645 |
} |
} |
646 |
|
|
647 |
void InstrumentResourceManager::DeleteSampleIfNotUsed(::gig::Sample* pSample, region_info_t* pRegInfo) { |
void InstrumentResourceManager::DeleteSampleIfNotUsed(::gig::Sample* pSample, region_info_t* pRegInfo) { |
648 |
::gig::File* gig = pRegInfo->file; |
::gig::File* gig = pRegInfo->file; |
649 |
::RIFF::File* riff = static_cast< ::RIFF::File*>(pRegInfo->pArg); |
::RIFF::File* riff = static_cast< ::RIFF::File*>(pRegInfo->pArg); |
698 |
// the sample. |
// the sample. |
699 |
const uint maxSamplesPerCycle = |
const uint maxSamplesPerCycle = |
700 |
(pEngine) ? pEngine->pAudioOutputDevice->MaxSamplesPerCycle() |
(pEngine) ? pEngine->pAudioOutputDevice->MaxSamplesPerCycle() |
701 |
: GIG_RESOURCE_MANAGER_DEFAULT_MAX_SAMPLES_PER_CYCLE; |
: DefaultMaxSamplesPerCycle(); |
702 |
const uint neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3; |
const uint neededSilenceSamples = (maxSamplesPerCycle << CONFIG_MAX_PITCH) + 3; |
703 |
const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->FrameSize; |
const uint currentlyCachedSilenceSamples = pSample->GetCache().NullExtensionSize / pSample->FrameSize; |
704 |
if (currentlyCachedSilenceSamples < neededSilenceSamples) { |
if (currentlyCachedSilenceSamples < neededSilenceSamples) { |
926 |
} |
} |
927 |
|
|
928 |
void InstrumentResourceManager::GigResourceManager::Destroy(::gig::File* pResource, void* pArg) { |
void InstrumentResourceManager::GigResourceManager::Destroy(::gig::File* pResource, void* pArg) { |
929 |
dmsg(1,("Freeing gig file from memory...")); |
dmsg(1,("Freeing gig file '%s' from memory ...", pResource->GetFileName().c_str())); |
930 |
|
|
931 |
// Delete as much as possible of the gig file. Some of the |
// Delete as much as possible of the gig file. Some of the |
932 |
// dimension regions and samples may still be in use - these |
// dimension regions and samples may still be in use - these |