/[svn]/linuxsampler/trunk/src/engines/sfz/Voice.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/sfz/Voice.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2244 - (show annotations) (download) (as text)
Thu Aug 18 11:32:33 2011 UTC (12 years, 8 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 7323 byte(s)
* sfz engine: use common pool of CC objects to minimize RAM usage

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7 * Copyright (C) 2009 - 2011 Christian Schoenebeck and Grigor Iliev *
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License *
20 * along with this program; if not, write to the Free Software *
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
22 * MA 02111-1307 USA *
23 ***************************************************************************/
24
25 #ifndef __LS_SFZ_VOICE_H__
26 #define __LS_SFZ_VOICE_H__
27
28 #include "../../common/global_private.h"
29
30 #include "../../common/RTMath.h"
31 #include "../../common/Pool.h"
32 #include "../../drivers/audio/AudioOutputDevice.h"
33 #include "DiskThread.h"
34 #include "../gig/Filter.h"
35 #include "../common/VoiceBase.h"
36 #include "../gig/SynthesisParam.h"
37 #include "EG.h"
38 #include "EGADSR.h"
39 #include "SfzSignalUnitRack.h"
40
41 namespace LinuxSampler { namespace sfz {
42 class Engine;
43 class EngineChannel;
44
45 /** SoundFont Voice
46 *
47 * Renders a voice for the SoundFont format.
48 */
49 class Voice : public LinuxSampler::VoiceBase<EngineChannel, ::sfz::Region, Sample, DiskThread> {
50 public:
51 Voice();
52 virtual ~Voice();
53 void SetOutput(AudioOutputDevice* pAudioOutputDevice);
54 void SetEngine(LinuxSampler::Engine* pEngine);
55
56 virtual void VoiceFreed() { SignalRack.Reset(); }
57
58 protected:
59 virtual SampleInfo GetSampleInfo();
60 virtual RegionInfo GetRegionInfo();
61 virtual InstrumentInfo GetInstrumentInfo();
62 virtual double CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity);
63 virtual AbstractEngine* GetEngine() { return (AbstractEngine*)pEngine; }
64 virtual float GetReleaseTriggerAttenuation(float noteLength);
65 virtual double GetEG1ControllerValue(uint8_t MIDIKeyVelocity);
66 virtual EGInfo CalculateEG1ControllerInfluence(double eg1ControllerValue);
67 virtual void TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { }
68 virtual double GetEG2ControllerValue(uint8_t MIDIKeyVelocity);
69 virtual EGInfo CalculateEG2ControllerInfluence(double eg2ControllerValue);
70 virtual void TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { }
71 virtual void InitLFO1() { }
72 virtual void InitLFO2() { }
73 virtual void InitLFO3() { }
74 virtual float CalculateCutoffBase(uint8_t MIDIKeyVelocity);
75 virtual float CalculateFinalCutoff(float cutoffBase);
76 virtual uint8_t GetVCFCutoffCtrl();
77 virtual uint8_t GetVCFResonanceCtrl();
78 virtual void ProcessCCEvent(RTList<Event>::Iterator& itEvent);
79 virtual void ProcessCutoffEvent(RTList<Event>::Iterator& itEvent);
80 virtual double GetVelocityAttenuation(uint8_t MIDIKeyVelocity);
81 virtual double GetVelocityRelease(uint8_t MIDIKeyVelocity);
82 virtual double GetSampleAttenuation();
83 virtual void ProcessGroupEvent(RTList<Event>::Iterator& itEvent);
84 virtual void SetSampleStartOffset();
85 virtual int GetRAMCacheOffset() { return pRegion->pSample->RAMCacheOffset; }
86
87 private:
88 EG EG1;
89 EGADSR EGADSR1;
90 EG EG2;
91 EGADSR EGADSR2;
92 SfzSignalUnitRack SignalRack;
93
94 public: // FIXME: just made public for debugging (sanity check in Engine::RenderAudio()), should be changed to private before the final release
95 // Attributes
96 Engine* pEngine; ///< Pointer to the sampler engine, to be able to access the event lists.
97 //uint LoopCyclesLeft; ///< In case there is a RAMLoop and it's not an endless loop; reflects number of loop cycles left to be passed
98
99 // Static Methods
100 static float CalculateFilterCutoffCoeff();
101
102 // Methods
103 void ProcessEvents(uint Samples);
104 void processCrossFadeEvent(RTList<Event>::Iterator& itEvent);
105
106 EngineChannel* GetSfzEngineChannel();
107
108 friend class CCUnit;
109 friend class XFInCCUnit;
110 friend class XFOutCCUnit;
111 friend class AmpEGUnit;
112 friend class FilEGUnit;
113 friend class PitchEGUnit;
114 friend class PitchLFOUnit;
115 friend class AmpLFOUnit;
116 friend class FilLFOUnit;
117 friend class EndpointUnit;
118 friend class SfzSignalUnitRack;
119
120 protected:
121 virtual uint8_t CrossfadeAttenuation(uint8_t& CrossfadeControllerValue) {
122 /*uint8_t c = std::max(CrossfadeControllerValue, pRegion->AttenuationControllerThreshold);
123 c = (!pRegion->Crossfade.out_end) ? c // 0,0,0,0 means no crossfade defined
124 : (c < pRegion->Crossfade.in_end) ?
125 ((c <= pRegion->Crossfade.in_start) ? 0
126 : 127 * (c - pRegion->Crossfade.in_start) / (pRegion->Crossfade.in_end - pRegion->Crossfade.in_start))
127 : (c <= pRegion->Crossfade.out_start) ? 127
128 : (c < pRegion->Crossfade.out_end) ? 127 * (pRegion->Crossfade.out_end - c) / (pRegion->Crossfade.out_end - pRegion->Crossfade.out_start)
129 : 0;
130 return pRegion->InvertAttenuationController ? 127 - c : c;*/ // TODO: ^^^
131 return 0;
132 }
133 };
134
135 }} // namespace LinuxSampler::sfz
136
137 #endif // __LS_SFZ_VOICE_H__

  ViewVC Help
Powered by ViewVC