/[svn]/linuxsampler/trunk/src/audiothread.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/audiothread.h

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

revision 9 by schoenebeck, Wed Nov 5 14:47:10 2003 UTC revision 20 by schoenebeck, Thu Dec 25 00:02:45 2003 UTC
# Line 35  Line 35 
35  #include "voice.h"  #include "voice.h"
36  #include "audioio.h"  #include "audioio.h"
37  #include "gig.h"  #include "gig.h"
38    #include "rtelmemorypool.h"
39    
 #define DEBUG                   0  
40  #define PITCHBEND_SEMITONES     12  #define PITCHBEND_SEMITONES     12
41  #define MAX_AUDIO_VOICES        64  #define MAX_AUDIO_VOICES        64
42    
43  // 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
44  #define NUM_RAM_PRELOAD_SAMPLES 65536  #define NUM_RAM_PRELOAD_SAMPLES 32768
45    
46  class AudioThread : public Thread {  class AudioThread : public Thread {
47      public:      public:
48            double Volume;               ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
49            int    ActiveVoiceCount;     ///< number of currently active voices
50            int    ActiveVoiceCountMax;  ///< the maximum voice usage since application start
51    
52          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);
53         ~AudioThread();         ~AudioThread();
54          void ProcessNoteOn(uint8_t Pitch, uint8_t Velocity);          void SendNoteOn(uint8_t Pitch, uint8_t Velocity);
55          void ProcessNoteOff(uint8_t Pitch, uint8_t Velocity);          void SendNoteOff(uint8_t Pitch, uint8_t Velocity);
56            void SendControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);
57      protected:      protected:
58          int Main(); ///< Implementation of virtual method from class Thread          int Main(); ///< Implementation of virtual method from class Thread
59      private:      private:
60          enum command_type_t {          enum command_type_t {
61              command_type_note_on,              command_type_note_on,
62              command_type_note_off              command_type_note_off,
63                command_type_continuous_controller
64          };          };
65          struct command_t {          struct command_t {
66              command_type_t type;              command_type_t type;
67                uint8_t        channel;
68              uint8_t        pitch;              uint8_t        pitch;
69              uint8_t        velocity;              uint8_t        velocity;
70                uint8_t        number;
71                uint8_t        value;
72          } command;          } command;
73          RingBuffer<command_t>* pCommandQueue;          struct midi_key_info_t {
74          float*                 pAudioSumBuffer;    ///< Audio sum of all voices (32 bit)              RTEList<Voice*>*             pActiveVoices;      ///< Contains the active voices associated with the MIDI key.
75          Voice**                pVoices;            ///< The voice pool, containing all Voices (active and inactice voices) in unsorted order              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)
76          Voice*                 ActiveVoices[128];  ///< Contains all active voices sorted by MIDI key number              bool                         Sustained;          ///< Is true if the MIDI key is currently sustained, thus if Note-off arrived while sustain pedal pressed.
77          AudioIO*               pAudioIO;              bool                         KeyPressed;         ///< Is true if the respective MIDI key is currently pressed.
78          DiskThread*            pDiskThread;              uint*                        pSustainPoolNode;   ///< FIXME: hack to allow fast deallocation of the key from the sustained key pool
79          gig::Instrument*       pInstrument;          };
80    
81            RingBuffer<command_t>*           pCommandQueue;
82            float*                           pAudioSumBuffer;    ///< Audio sum of all voices (32 bit)
83            Voice**                          pVoices;            ///< The voice pool, containing all Voices (active and inactice voices) in unsorted order
84            midi_key_info_t                  pMIDIKeyInfo[128];  ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
85            /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.
86               it can be allocated dynamically in real time and the allocated elements can be added to
87               the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited
88               active voices per key. This if for example useful to manage the sustain pedal messages
89             */
90            RTELMemoryPool<Voice*>*          ActiveVoicePool;
91            RTELMemoryPool<uint>*            SustainedKeyPool;   ///< Contains the MIDI key numbers of all currently sustained keys.
92            AudioIO*                         pAudioIO;
93            DiskThread*                      pDiskThread;
94            gig::Instrument*                 pInstrument;
95            bool                             SustainPedal;       ///< true if sustain pedal is down
96            uint8_t                          PrevHoldCCValue;
97    
98          void ActivateVoice(uint8_t MIDIKey, uint8_t Velocity);          void ProcessNoteOn(uint8_t MIDIKey, uint8_t Velocity);
99          void ReleaseVoice(uint8_t MIDIKey, uint8_t Velocity);          void ProcessNoteOff(uint8_t MIDIKey, uint8_t Velocity);
100            void ProcessControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);
101            void ReleaseVoice(Voice* pVoice);
102          void CacheInitialSamples(gig::Sample* pSample);          void CacheInitialSamples(gig::Sample* pSample);
103  };  };
104    

Legend:
Removed from v.9  
changed lines
  Added in v.20

  ViewVC Help
Powered by ViewVC