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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3052 - (show annotations) (download) (as text)
Wed Dec 14 17:34:54 2016 UTC (7 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7190 byte(s)
- Preparations for Xcode project update.

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 - 2013 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_GIG_VOICE_H__
26 #define __LS_GIG_VOICE_H__
27
28 #include "../../common/global_private.h"
29
30 #if AC_APPLE_UNIVERSAL_BUILD
31 # include <libgig/gig.h>
32 #else
33 # include <gig.h>
34 #endif
35
36 #include "../../common/RTMath.h"
37 #include "../../common/Pool.h"
38 #include "../../drivers/audio/AudioOutputDevice.h"
39 #include "Stream.h"
40 #include "DiskThread.h"
41 #include "EGADSR.h"
42 #include "EGDecay.h"
43 #include "Filter.h"
44 #include "../common/VoiceBase.h"
45 #include "SynthesisParam.h"
46 #include "SmoothVolume.h"
47 #include "EngineChannel.h"
48
49 namespace LinuxSampler { namespace gig {
50 class Engine;
51 class EngineChannel;
52
53 /** Gig Voice
54 *
55 * Renders a voice for the Gigasampler format.
56 */
57 class Voice : public LinuxSampler::VoiceBase<EngineChannel, ::gig::DimensionRegion, ::gig::Sample, DiskThread> {
58 public:
59 Voice();
60 virtual ~Voice();
61 void SetOutput(AudioOutputDevice* pAudioOutputDevice);
62 void SetEngine(LinuxSampler::Engine* pEngine);
63 void CalculateFadeOutCoeff(float FadeOutTime, float SampleRate);
64
65 protected:
66 virtual SampleInfo GetSampleInfo();
67 virtual RegionInfo GetRegionInfo();
68 virtual InstrumentInfo GetInstrumentInfo();
69 virtual double CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity);
70 virtual AbstractEngine* GetEngine() { return (AbstractEngine*)pEngine; }
71 virtual double GetEG1ControllerValue(uint8_t MIDIKeyVelocity);
72 virtual EGInfo CalculateEG1ControllerInfluence(double eg1ControllerValue);
73 virtual void TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity);
74 virtual double GetEG2ControllerValue(uint8_t MIDIKeyVelocity);
75 virtual EGInfo CalculateEG2ControllerInfluence(double eg2ControllerValue);
76 virtual void TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity);
77 virtual void InitLFO1();
78 virtual void InitLFO2();
79 virtual void InitLFO3();
80 virtual float CalculateCutoffBase(uint8_t MIDIKeyVelocity);
81 virtual float CalculateFinalCutoff(float cutoffBase);
82 virtual uint8_t GetVCFCutoffCtrl();
83 virtual uint8_t GetVCFResonanceCtrl();
84 virtual void ProcessCCEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
85 virtual void ProcessChannelPressureEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
86 virtual void ProcessPolyphonicKeyPressureEvent(RTList<Event>::Iterator& itEvent) OVERRIDE;
87 virtual void ProcessCutoffEvent(RTList<Event>::Iterator& itEvent);
88 virtual double GetVelocityAttenuation(uint8_t MIDIKeyVelocity);
89 virtual double GetVelocityRelease(uint8_t MIDIKeyVelocity);
90 virtual double GetSampleAttenuation();
91 virtual void ProcessGroupEvent(RTList<Event>::Iterator& itEvent);
92 virtual int CalculatePan(uint8_t pan);
93
94 private:
95 EGADSR EG1;
96 EGADSR EG2;
97
98 public: // FIXME: just made public for debugging (sanity check in Engine::RenderAudio()), should be changed to private before the final release
99 // Attributes
100 Engine* pEngine; ///< Pointer to the sampler engine, to be able to access the event lists.
101 //uint LoopCyclesLeft; ///< In case there is a RAMLoop and it's not an endless loop; reflects number of loop cycles left to be passed
102
103 // Static Methods
104 static float CalculateFilterCutoffCoeff();
105
106 // Methods
107 void ProcessEvents(uint Samples);
108 void processCrossFadeEvent(RTList<Event>::Iterator& itEvent);
109
110 EngineChannel* GetGigEngineChannel();
111
112 protected:
113 virtual uint8_t CrossfadeAttenuation(uint8_t& CrossfadeControllerValue) {
114 uint8_t c = std::max(CrossfadeControllerValue, pRegion->AttenuationControllerThreshold);
115 c = (!pRegion->Crossfade.out_end) ? c /* 0,0,0,0 means no crossfade defined */
116 : (c < pRegion->Crossfade.in_end) ?
117 ((c <= pRegion->Crossfade.in_start) ? 0
118 : 127 * (c - pRegion->Crossfade.in_start) / (pRegion->Crossfade.in_end - pRegion->Crossfade.in_start))
119 : (c <= pRegion->Crossfade.out_start) ? 127
120 : (c < pRegion->Crossfade.out_end) ? 127 * (pRegion->Crossfade.out_end - c) / (pRegion->Crossfade.out_end - pRegion->Crossfade.out_start)
121 : 0;
122 return pRegion->InvertAttenuationController ? 127 - c : c;
123 }
124
125 inline float Constrain(float ValueToCheck, float Min, float Max) {
126 if (ValueToCheck > Max) ValueToCheck = Max;
127 else if (ValueToCheck < Min) ValueToCheck = Min;
128 return ValueToCheck;
129 }
130 };
131
132 }} // namespace LinuxSampler::gig
133
134 #endif // __LS_GIG_VOICE_H__

  ViewVC Help
Powered by ViewVC