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

Annotation of /linuxsampler/trunk/src/engines/AbstractEngine.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2015 - (hide annotations) (download) (as text)
Sun Oct 25 22:22:52 2009 UTC (14 years, 5 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 7516 byte(s)
* Refactoring: moved the independent code from gig::Voice to base classes
* SoundFont format engine: implemented EG1 & EG2

1 iliev 2012 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck *
6     * Copyright (C) 2005-2009 Christian Schoenebeck *
7     * Copyright (C) 2009 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_ABSTRACTENGINE_H__
26     #define __LS_ABSTRACTENGINE_H__
27    
28     #include "Engine.h"
29     #include "../common/ArrayList.h"
30     #include "../common/atomic.h"
31     #include "../common/ConditionServer.h"
32     #include "../common/Pool.h"
33     #include "../common/RingBuffer.h"
34     #include "../drivers/audio/AudioOutputDevice.h"
35     #include "common/Event.h"
36    
37     namespace LinuxSampler {
38    
39     class AbstractEngineChannel;
40    
41     class AbstractEngine: public Engine {
42    
43     public:
44     enum Format { GIG = 1, SF2, SFZ };
45     static String GetFormatString(Format f);
46     static AbstractEngine* AcquireEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
47     static void FreeEngine(AbstractEngineChannel* pChannel, AudioOutputDevice* pDevice);
48    
49     AbstractEngine();
50     virtual ~AbstractEngine();
51    
52     // implementation of abstract methods derived from class 'LinuxSampler::Engine'
53     virtual void SendSysex(void* pData, uint Size, MidiInputPort* pSender);
54     virtual void Reset();
55     virtual void Enable();
56     virtual void Disable();
57     virtual uint VoiceCount();
58     virtual uint VoiceCountMax();
59     virtual String EngineName();
60    
61     virtual Format GetEngineFormat() = 0;
62     virtual void Connect(AudioOutputDevice* pAudioOut) = 0;
63     virtual void DisableAndLock();
64    
65     void SetVoiceCount(uint Count);// Simple array wrapper just to make sure memory is freed
66     // when liblinuxsampler is unloaded
67     class FloatTable {
68     private:
69     const float* array;
70     public:
71     FloatTable(const float* array) : array(array) { }
72     ~FloatTable() { delete[] array; }
73     const float& operator[](int i) const { return array[i]; }
74     };
75    
76     static const FloatTable VolumeCurve; ///< Table that maps volume control change values 0..127 to amplitude. Unity gain is at 90.
77     static const FloatTable PanCurve; ///< Table that maps pan control change values 0..128 to right channel amplitude. Unity gain is at 64 (center).
78     static const FloatTable CrossfadeCurve; ///< Table that maps crossfade control change values 0..127 to amplitude. Unity gain is at 127.
79    
80     AudioOutputDevice* pAudioOutputDevice;
81    
82 iliev 2015 friend class AbstractVoice;
83 iliev 2012 friend class AbstractEngineChannel;
84     template<class V, class R, class I> friend class EngineChannelBase;
85 iliev 2015 template<class EC, class R, class S, class D> friend class VoiceBase;
86 iliev 2012
87     protected:
88     ArrayList<EngineChannel*> engineChannels; ///< All engine channels of a Engine instance.
89     ConditionServer EngineDisabled;
90     int8_t ScaleTuning[12]; ///< contains optional detune factors (-64..+63 cents) for all 12 semitones of an octave
91     RingBuffer<Event,false>* pEventQueue; ///< Input event queue for engine global events (e.g. SysEx messages).
92     EventGenerator* pEventGenerator;
93     RTList<Event>* pGlobalEvents; ///< All engine global events for the current audio fragment (usually only SysEx messages).
94     Pool<Event>* pEventPool; ///< Contains all Event objects that can be used.
95     RingBuffer<uint8_t,false>* pSysexBuffer; ///< Input buffer for MIDI system exclusive messages.
96     uint SampleRate; ///< Sample rate of the engines output audio signal (in Hz)
97     uint MaxSamplesPerCycle; ///< Size of each audio output buffer
98     unsigned long FrameTime; ///< Time in frames of the start of the current audio fragment
99     int ActiveVoiceCountMax; ///< the maximum voice usage since application start
100     atomic_t ActiveVoiceCount; ///< number of currently active voices
101    
102     void RouteAudio(EngineChannel* pEngineChannel, uint Samples);
103     void ClearEventLists();
104     void ImportEvents(uint Samples);
105     void ProcessSysex(Pool<Event>::Iterator& itSysexEvent);
106     void ResetScaleTuning();
107     void ProcessPitchbend(AbstractEngineChannel* pEngineChannel, Pool<Event>::Iterator& itPitchbendEvent);
108    
109     void ProcessFxSendControllers (
110     AbstractEngineChannel* pEngineChannel,
111     Pool<Event>::Iterator& itControlChangeEvent
112     );
113    
114     uint8_t GSCheckSum(const RingBuffer<uint8_t,false>::NonVolatileReader AddrReader, uint DataSize);
115    
116     virtual void ResetInternal() = 0;
117     virtual void KillAllVoices(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itKillEvent) = 0;
118     virtual void ProcessNoteOn(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOnEvent) = 0;
119     virtual void ProcessNoteOff(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itNoteOffEvent) = 0;
120     virtual void ProcessControlChange(EngineChannel* pEngineChannel, Pool<Event>::Iterator& itControlChangeEvent) = 0;
121 iliev 2015 virtual int GetMinFadeOutSamples() = 0;
122 iliev 2012
123     private:
124     static std::map<Format, std::map<AudioOutputDevice*,AbstractEngine*> > engines;
125    
126     static float* InitVolumeCurve();
127     static float* InitPanCurve();
128     static float* InitCrossfadeCurve();
129     static float* InitCurve(const float* segments, int size = 128);
130    
131     void AdjustScale(int8_t ScaleTunes[12]);
132     };
133    
134     } // namespace LinuxSampler
135    
136     #endif /* __LS_ABSTRACTENGINE_H__ */
137    

  ViewVC Help
Powered by ViewVC