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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3054 - (hide 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 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 persson 2055 * Copyright (C) 2005 - 2008 Christian Schoenebeck *
7 schoenebeck 3054 * Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev *
8     * Copyright (C) 2010 - 2016 Christian Schoenebeck and Andreas Persson *
9 schoenebeck 53 * *
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 schoenebeck 1424 #include "../../common/global_private.h"
30 schoenebeck 53
31 schoenebeck 3052 #if AC_APPLE_UNIVERSAL_BUILD
32     # include <libgig/gig.h>
33     #else
34     # include <gig.h>
35     #endif
36 schoenebeck 505
37 schoenebeck 53 #include "../../common/RTMath.h"
38 schoenebeck 273 #include "../../common/Pool.h"
39 schoenebeck 203 #include "../../drivers/audio/AudioOutputDevice.h"
40 schoenebeck 53 #include "Stream.h"
41     #include "DiskThread.h"
42 schoenebeck 738 #include "EGADSR.h"
43 schoenebeck 53 #include "EGDecay.h"
44     #include "Filter.h"
45 iliev 2012 #include "../common/VoiceBase.h"
46 schoenebeck 770 #include "SynthesisParam.h"
47 persson 832 #include "SmoothVolume.h"
48 persson 2390 #include "EngineChannel.h"
49 schoenebeck 53
50     namespace LinuxSampler { namespace gig {
51     class Engine;
52 iliev 2012 class EngineChannel;
53 schoenebeck 53
54     /** Gig Voice
55     *
56     * Renders a voice for the Gigasampler format.
57     */
58 iliev 2015 class Voice : public LinuxSampler::VoiceBase<EngineChannel, ::gig::DimensionRegion, ::gig::Sample, DiskThread> {
59 schoenebeck 53 public:
60     Voice();
61 letz 502 virtual ~Voice();
62 schoenebeck 53 void SetOutput(AudioOutputDevice* pAudioOutputDevice);
63 iliev 2012 void SetEngine(LinuxSampler::Engine* pEngine);
64 persson 2327 void CalculateFadeOutCoeff(float FadeOutTime, float SampleRate);
65 schoenebeck 829
66 iliev 2015 protected:
67 schoenebeck 3054 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 schoenebeck 2559 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 schoenebeck 3054 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 iliev 2012
95 iliev 2015 private:
96 persson 2055 EGADSR EG1;
97 persson 2175 EGADSR EG2;
98 persson 2055
99 iliev 2015 public: // FIXME: just made public for debugging (sanity check in Engine::RenderAudio()), should be changed to private before the final release
100 schoenebeck 53 // Attributes
101 schoenebeck 411 Engine* pEngine; ///< Pointer to the sampler engine, to be able to access the event lists.
102 schoenebeck 770 //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 schoenebeck 738
104 schoenebeck 53 // Static Methods
105     static float CalculateFilterCutoffCoeff();
106    
107     // Methods
108 schoenebeck 319 void ProcessEvents(uint Samples);
109 schoenebeck 738 void processCrossFadeEvent(RTList<Event>::Iterator& itEvent);
110 schoenebeck 245
111 iliev 2015 EngineChannel* GetGigEngineChannel();
112    
113     protected:
114 schoenebeck 3054 virtual uint8_t CrossfadeAttenuation(uint8_t& CrossfadeControllerValue) OVERRIDE {
115 iliev 2015 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 persson 832 : 0;
123 iliev 2015 return pRegion->InvertAttenuationController ? 127 - c : c;
124 schoenebeck 236 }
125    
126 schoenebeck 53 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