/[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 31 by schoenebeck, Sun Jan 18 20:31:31 2004 UTC revision 33 by schoenebeck, Mon Feb 16 19:30:42 2004 UTC
# Line 36  Line 36 
36  #include "rtelmemorypool.h"  #include "rtelmemorypool.h"
37  #include "modulationsystem.h"  #include "modulationsystem.h"
38    
39  #define PITCHBEND_SEMITONES     12  #define PITCHBEND_SEMITONES             12
40  #define MAX_AUDIO_VOICES        64  #define MAX_AUDIO_VOICES                64
41    
42  // 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
43  #define NUM_RAM_PRELOAD_SAMPLES 32768  #define NUM_RAM_PRELOAD_SAMPLES 32768
44    
45    // just symbol prototyping
46    class Voice;
47    
48  //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
49  class AudioThread {  class AudioThread {
50      public:      public:
# Line 51  class AudioThread { Line 54  class AudioThread {
54    
55          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);
56         ~AudioThread();         ~AudioThread();
57          void          SendNoteOn(uint8_t Pitch, uint8_t Velocity);          void          SendNoteOn(uint8_t Key, uint8_t Velocity);
58          void          SendNoteOff(uint8_t Pitch, uint8_t Velocity);          void          SendNoteOff(uint8_t Key, uint8_t Velocity);
59          void          SendControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);          void          SendPitchbend(int Pitch);
60            void          SendControlChange(uint8_t Controller, uint8_t Value);
61          int           RenderAudio(uint Samples);          int           RenderAudio(uint Samples);
62          inline float* GetAudioSumBuffer(uint Channel) {          inline float* GetAudioSumBuffer(uint Channel) {
63              return pAudioSumBuffer[Channel];              return pAudioSumBuffer[Channel];
64          };          };
65      private:      protected:
         enum command_type_t {  
             command_type_note_on,  
             command_type_note_off,  
             command_type_continuous_controller  
         };  
         struct command_t {  
             command_type_t type;  
             uint8_t        channel;  
             uint8_t        pitch;  
             uint8_t        velocity;  
             uint8_t        number;  
             uint8_t        value;  
         } command;  
66          struct midi_key_info_t {          struct midi_key_info_t {
67              RTEList<Voice*>*             pActiveVoices;         ///< Contains the active voices associated with the MIDI key.              RTEList<Voice>*                      pActiveVoices;         ///< Contains the active voices associated with the MIDI key.
68              RTEList<Voice*>::NodeHandle  hSustainPtr;           ///< 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                                 KeyPressed;            ///< Is true if the respective MIDI key is currently pressed.
69              bool                         Sustained;             ///< Is true if the MIDI key is currently sustained, thus if Note-off arrived while sustain pedal pressed.              bool                                 Active;                ///< If the key contains active voices.
70              bool                         KeyPressed;            ///< Is true if the respective MIDI key is currently pressed.              uint*                                pSelf;                 ///< hack to allow fast deallocation of the key from the list of active keys
71              uint*                        pSustainPoolNode;      ///< FIXME: hack to allow fast deallocation of the key from the sustained key pool              RTEList<ModulationSystem::Event>*    pEvents;               ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
72          };          };
73    
74          RingBuffer<command_t>*           pCommandQueue;          RingBuffer<ModulationSystem::Event>*     pEventQueue;           ///< Input event queue.
75          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)
76          Voice**                          pVoices;               ///< The voice pool, containing all Voices (active and inactice voices) in unsorted order          midi_key_info_t                          pMIDIKeyInfo[128];     ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
77          midi_key_info_t                  pMIDIKeyInfo[128];     ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key          RTELMemoryPool<Voice>*                   pVoicePool;            ///< Contains all voices that can be activated.
78          /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.          RTELMemoryPool<uint>*                    pActiveKeys;           ///< Holds all keys in it's allocation list with active voices.
79             it can be allocated dynamically in real time and the allocated elements can be added to          RTELMemoryPool<ModulationSystem::Event>* pEventPool;            ///< Contains all Event objects that can be used.
80             the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited          RTEList<ModulationSystem::Event>*        pEvents;               ///< All events for the current audio fragment.
81             active voices per key. This if for example useful to manage the sustain pedal messages          RTEList<ModulationSystem::Event>*        pCCEvents[ModulationSystem::destination_count];  ///< Control change events for the current audio fragment.
82           */          AudioIO*                                 pAudioIO;
83          RTELMemoryPool<Voice*>*          ActiveVoicePool;          DiskThread*                              pDiskThread;
84          RTELMemoryPool<uint>*            SustainedKeyPool;      ///< Contains the MIDI key numbers of all currently sustained keys.          gig::Instrument*                         pInstrument;
85          AudioIO*                         pAudioIO;          bool                                     SustainPedal;          ///< true if sustain pedal is down
86          DiskThread*                      pDiskThread;          uint8_t                                  PrevHoldCCValue;
87          gig::Instrument*                 pInstrument;          int                                      Pitch;                 ///< Current (absolute) MIDI pitch value.
88          bool                             SustainPedal;          ///< true if sustain pedal is down  
89          uint8_t                          PrevHoldCCValue;          void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);
90            void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
91          void ProcessNoteOn(uint8_t MIDIKey, uint8_t Velocity);          void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
92          void ProcessNoteOff(uint8_t MIDIKey, uint8_t Velocity);          void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
         void ProcessControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);  
93          void KillVoice(Voice* pVoice);          void KillVoice(Voice* pVoice);
94          void CacheInitialSamples(gig::Sample* pSample);          void CacheInitialSamples(gig::Sample* pSample);
95    
96            friend class Voice;
97  };  };
98    
99  #endif // __AUDIOTHREAD_H__  #endif // __AUDIOTHREAD_H__

Legend:
Removed from v.31  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC