/[svn]/linuxsampler/tags/singlechannel/src/audiothread.h
ViewVC logotype

Diff of /linuxsampler/tags/singlechannel/src/audiothread.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 32 by schoenebeck, Tue Feb 3 13:21:19 2004 UTC revision 37 by schoenebeck, Wed Mar 10 22:01:36 2004 UTC
# Line 26  Line 26 
26  #include <math.h>  #include <math.h>
27  #include <unistd.h>  #include <unistd.h>
28  #include <fcntl.h>  #include <fcntl.h>
29    #include <pthread.h>
30    #include <sstream>
31    
32  #include "global.h"  #include "global.h"
33  #include "thread.h"  #include "thread.h"
# Line 35  Line 37 
37  #include "gig.h"  #include "gig.h"
38  #include "rtelmemorypool.h"  #include "rtelmemorypool.h"
39  #include "modulationsystem.h"  #include "modulationsystem.h"
40    #include "network/lscp.h"
41    
42  #define PITCHBEND_SEMITONES             12  #define PITCHBEND_SEMITONES             12
43  #define MAX_AUDIO_VOICES                64  #define MAX_AUDIO_VOICES                64
 #define MAX_EVENTS_PER_FRAGMENT         1024  
44    
45  // preload 64k samples = 128kB of data in RAM for 16 bit mono samples  // preload 64k samples = 128kB of data in RAM for 16 bit mono samples
46  #define NUM_RAM_PRELOAD_SAMPLES 32768  #define NUM_RAM_PRELOAD_SAMPLES 32768
# Line 49  class Voice; Line 51  class Voice;
51  //FIXME: Class name "AudioThread" is now misleading, because there is no thread anymore, but the name will change soon to "Engine" when we restructure the source tree  //FIXME: Class name "AudioThread" is now misleading, because there is no thread anymore, but the name will change soon to "Engine" when we restructure the source tree
52  class AudioThread {  class AudioThread {
53      public:      public:
54          double Volume;               ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)          double       Volume;               ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
55          int    ActiveVoiceCount;     ///< number of currently active voices          int          ActiveVoiceCount;     ///< number of currently active voices
56          int    ActiveVoiceCountMax;  ///< the maximum voice usage since application start          int          ActiveVoiceCountMax;  ///< the maximum voice usage since application start
57            DiskThread*  pDiskThread;
58    
59          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);          AudioThread(AudioIO* pAudioIO);
60         ~AudioThread();         ~AudioThread();
61            result_t      LoadInstrument(const char* FileName, uint Instrument);
62            void          Reset();
63          void          SendNoteOn(uint8_t Key, uint8_t Velocity);          void          SendNoteOn(uint8_t Key, uint8_t Velocity);
64          void          SendNoteOff(uint8_t Key, uint8_t Velocity);          void          SendNoteOff(uint8_t Key, uint8_t Velocity);
65          void          SendPitchbend(int Pitch);          void          SendPitchbend(int Pitch);
# Line 66  class AudioThread { Line 71  class AudioThread {
71      protected:      protected:
72          struct midi_key_info_t {          struct midi_key_info_t {
73              RTEList<Voice>*                      pActiveVoices;         ///< Contains the active voices associated with the MIDI key.              RTEList<Voice>*                      pActiveVoices;         ///< Contains the active voices associated with the MIDI key.
             Voice*                               pSustainPtr;           ///< Points to the voice element in the active voice list which has not received a note-off yet (this pointer is needed for sustain pedal handling)  
             bool                                 Sustained;             ///< Is true if the MIDI key is currently sustained, thus if Note-off arrived while sustain pedal pressed.  
74              bool                                 KeyPressed;            ///< Is true if the respective MIDI key is currently pressed.              bool                                 KeyPressed;            ///< Is true if the respective MIDI key is currently pressed.
75              uint*                                pSustainPoolNode;      ///< FIXME: hack to allow fast deallocation of the key from the sustained key pool              bool                                 Active;                ///< If the key contains active voices.
76                uint*                                pSelf;                 ///< hack to allow fast deallocation of the key from the list of active keys
77                RTEList<ModulationSystem::Event>*    pEvents;               ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
78          };          };
79            
80            uint8_t                                  ControllerTable[128];  ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
81          RingBuffer<ModulationSystem::Event>*     pEventQueue;           ///< Input event queue.          RingBuffer<ModulationSystem::Event>*     pEventQueue;           ///< Input event queue.
82          float*                                   pAudioSumBuffer[2];    ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel)          float*                                   pAudioSumBuffer[2];    ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel)
83          midi_key_info_t                          pMIDIKeyInfo[128];     ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key          midi_key_info_t                          pMIDIKeyInfo[128];     ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
         /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.  
            it can be allocated dynamically in real time and the allocated elements can be added to  
            the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited  
            active voices per key. This if for example useful to manage the sustain pedal messages  
          */  
84          RTELMemoryPool<Voice>*                   pVoicePool;            ///< Contains all voices that can be activated.          RTELMemoryPool<Voice>*                   pVoicePool;            ///< Contains all voices that can be activated.
85          RTELMemoryPool<uint>*                    pSustainedKeyPool;     ///< Contains the MIDI key numbers of all currently sustained keys.          RTELMemoryPool<uint>*                    pActiveKeys;           ///< Holds all keys in it's allocation list with active voices.
86          RTELMemoryPool<ModulationSystem::Event>* pEventPool;            ///< Contains all Event objects that can be used.          RTELMemoryPool<ModulationSystem::Event>* pEventPool;            ///< Contains all Event objects that can be used.
87          RTEList<ModulationSystem::Event>*        pEvents;               ///< All events for the current audio fragment.          RTEList<ModulationSystem::Event>*        pEvents;               ///< All events for the current audio fragment.
88          RTEList<ModulationSystem::Event>*        pCCEvents[ModulationSystem::destination_count];  ///< Control change events for the current audio fragment.          RTEList<ModulationSystem::Event>*        pCCEvents;             ///< All control change events for the current audio fragment.
89            RTEList<ModulationSystem::Event>*        pSynthesisEvents[ModulationSystem::destination_count];  ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
90          AudioIO*                                 pAudioIO;          AudioIO*                                 pAudioIO;
91          DiskThread*                              pDiskThread;          RIFF::File*                              pRIFF;
92            gig::File*                               pGig;
93          gig::Instrument*                         pInstrument;          gig::Instrument*                         pInstrument;
94          bool                                     SustainPedal;          ///< true if sustain pedal is down          bool                                     SustainPedal;          ///< true if sustain pedal is down
         uint8_t                                  PrevHoldCCValue;  
95          int                                      Pitch;                 ///< Current (absolute) MIDI pitch value.          int                                      Pitch;                 ///< Current (absolute) MIDI pitch value.
96            bool                                     SuspensionRequested;
97            pthread_mutex_t                          __render_state_mutex;
98            pthread_cond_t                           __render_exit_condition;
99    
100          void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);          void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);
101          void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);          void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
# Line 98  class AudioThread { Line 103  class AudioThread {
103          void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);          void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
104          void KillVoice(Voice* pVoice);          void KillVoice(Voice* pVoice);
105          void CacheInitialSamples(gig::Sample* pSample);          void CacheInitialSamples(gig::Sample* pSample);
106            void ResetInternal();
107    
108          friend class Voice;          friend class Voice;
109  };  };

Legend:
Removed from v.32  
changed lines
  Added in v.37

  ViewVC Help
Powered by ViewVC