/[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 3054 - (show annotations) (download) (as text)
Thu Dec 15 12:47:45 2016 UTC (7 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7492 byte(s)
* Fixed numerous compiler warnings.
* Bumped version (2.0.0.svn32).

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

  ViewVC Help
Powered by ViewVC