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

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

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

linuxsampler/trunk/src/audiothread.h revision 31 by schoenebeck, Sun Jan 18 20:31:31 2004 UTC linuxsampler/tags/v0_1_0/src/audiothread.h revision 44, Sun Apr 11 17:25:40 2004 UTC
# Line 23  Line 23 
23  #ifndef __AUDIOTHREAD_H__  #ifndef __AUDIOTHREAD_H__
24  #define __AUDIOTHREAD_H__  #define __AUDIOTHREAD_H__
25    
26  #include <math.h>  #include <sstream>
 #include <unistd.h>  
 #include <fcntl.h>  
27    
28  #include "global.h"  #include "global.h"
 #include "thread.h"  
29  #include "ringbuffer.h"  #include "ringbuffer.h"
30  #include "audioio.h"  #include "audioio.h"
31  #include "voice.h"  #include "voice.h"
32  #include "gig.h"  #include "gig.h"
33  #include "rtelmemorypool.h"  #include "rtelmemorypool.h"
34  #include "modulationsystem.h"  #include "modulationsystem.h"
35    #include "network/lscp.h"
36    
37  #define PITCHBEND_SEMITONES     12  #define PITCHBEND_SEMITONES             12
38  #define MAX_AUDIO_VOICES        64  #define MAX_AUDIO_VOICES                64
39    
40  // 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
41  #define NUM_RAM_PRELOAD_SAMPLES 32768  #define NUM_RAM_PRELOAD_SAMPLES 32768
42    
43    // just symbol prototyping
44    class Voice;
45    
46  //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
47  class AudioThread {  class AudioThread {
48      public:      public:
49          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)
50          int    ActiveVoiceCount;     ///< number of currently active voices          int          ActiveVoiceCount;     ///< number of currently active voices
51          int    ActiveVoiceCountMax;  ///< the maximum voice usage since application start          int          ActiveVoiceCountMax;  ///< the maximum voice usage since application start
52            DiskThread*  pDiskThread;
53    
54          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);          AudioThread(AudioIO* pAudioIO);
55         ~AudioThread();         ~AudioThread();
56          void          SendNoteOn(uint8_t Pitch, uint8_t Velocity);          result_t      LoadInstrument(const char* FileName, uint Instrument);
57          void          SendNoteOff(uint8_t Pitch, uint8_t Velocity);          void          Reset();
58          void          SendControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);          void          SendNoteOn(uint8_t Key, uint8_t Velocity);
59            void          SendNoteOff(uint8_t Key, uint8_t Velocity);
60            void          SendPitchbend(int Pitch);
61            void          SendControlChange(uint8_t Controller, uint8_t Value);
62          int           RenderAudio(uint Samples);          int           RenderAudio(uint Samples);
63          inline float* GetAudioSumBuffer(uint Channel) {          inline float* GetAudioSumBuffer(uint Channel) {
64              return pAudioSumBuffer[Channel];              return pAudioSumBuffer[Channel];
65          };          };
66      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;  
67          struct midi_key_info_t {          struct midi_key_info_t {
68              RTEList<Voice*>*             pActiveVoices;         ///< Contains the active voices associated with the MIDI key.              RTEList<Voice>*                      pActiveVoices;         ///< Contains the active voices associated with the MIDI key.
69              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.
70              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.
71              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
72              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)
73          };          };
74    
75          RingBuffer<command_t>*           pCommandQueue;          uint8_t                                  ControllerTable[128];  ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel.
76          float*                           pAudioSumBuffer[2];    ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel)          RingBuffer<ModulationSystem::Event>*     pEventQueue;           ///< Input event queue.
77          Voice**                          pVoices;               ///< The voice pool, containing all Voices (active and inactice voices) in unsorted order          float*                                   pAudioSumBuffer[2];    ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel)
78          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
79          /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.          RTELMemoryPool<Voice>*                   pVoicePool;            ///< Contains all voices that can be activated.
80             it can be allocated dynamically in real time and the allocated elements can be added to          RTELMemoryPool<uint>*                    pActiveKeys;           ///< Holds all keys in it's allocation list with active voices.
81             the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited          RTELMemoryPool<ModulationSystem::Event>* pEventPool;            ///< Contains all Event objects that can be used.
82             active voices per key. This if for example useful to manage the sustain pedal messages          RTEList<ModulationSystem::Event>*        pEvents;               ///< All events for the current audio fragment.
83           */          RTEList<ModulationSystem::Event>*        pCCEvents;             ///< All control change events for the current audio fragment.
84          RTELMemoryPool<Voice*>*          ActiveVoicePool;          RTEList<ModulationSystem::Event>*        pSynthesisEvents[ModulationSystem::destination_count];  ///< Events directly affecting synthesis parameter (like pitch, volume and filter).
85          RTELMemoryPool<uint>*            SustainedKeyPool;      ///< Contains the MIDI key numbers of all currently sustained keys.          AudioIO*                                 pAudioIO;
86          AudioIO*                         pAudioIO;          RIFF::File*                              pRIFF;
87          DiskThread*                      pDiskThread;          gig::File*                               pGig;
88          gig::Instrument*                 pInstrument;          gig::Instrument*                         pInstrument;
89          bool                             SustainPedal;          ///< true if sustain pedal is down          bool                                     SustainPedal;          ///< true if sustain pedal is down
90          uint8_t                          PrevHoldCCValue;          int                                      Pitch;                 ///< Current (absolute) MIDI pitch value.
91            bool                                     SuspensionRequested;
92          void ProcessNoteOn(uint8_t MIDIKey, uint8_t Velocity);          pthread_mutex_t                          __render_state_mutex;
93          void ProcessNoteOff(uint8_t MIDIKey, uint8_t Velocity);          pthread_cond_t                           __render_exit_condition;
94          void ProcessControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);  
95            void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);
96            void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
97            void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
98            void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
99          void KillVoice(Voice* pVoice);          void KillVoice(Voice* pVoice);
100          void CacheInitialSamples(gig::Sample* pSample);          void CacheInitialSamples(gig::Sample* pSample);
101            void ResetInternal();
102    
103            friend class Voice;
104  };  };
105    
106  #endif // __AUDIOTHREAD_H__  #endif // __AUDIOTHREAD_H__

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

  ViewVC Help
Powered by ViewVC