/[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

revision 10 by senoner, Tue Nov 11 23:30:47 2003 UTC revision 32 by schoenebeck, Tue Feb 3 13:21:19 2004 UTC
# Line 23  Line 23 
23  #ifndef __AUDIOTHREAD_H__  #ifndef __AUDIOTHREAD_H__
24  #define __AUDIOTHREAD_H__  #define __AUDIOTHREAD_H__
25    
 #include <stdio.h>  
 #include <stdlib.h>  
26  #include <math.h>  #include <math.h>
27  #include <unistd.h>  #include <unistd.h>
28  #include <fcntl.h>  #include <fcntl.h>
# Line 32  Line 30 
30  #include "global.h"  #include "global.h"
31  #include "thread.h"  #include "thread.h"
32  #include "ringbuffer.h"  #include "ringbuffer.h"
 #include "voice.h"  
33  #include "audioio.h"  #include "audioio.h"
34    #include "voice.h"
35  #include "gig.h"  #include "gig.h"
   
36  #include "rtelmemorypool.h"  #include "rtelmemorypool.h"
37    #include "modulationsystem.h"
38    
39  #define DEBUG                   0  #define PITCHBEND_SEMITONES             12
40  #define PITCHBEND_SEMITONES     12  #define MAX_AUDIO_VOICES                64
41  #define MAX_AUDIO_VOICES        64  #define MAX_EVENTS_PER_FRAGMENT         1024
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 32768  #define NUM_RAM_PRELOAD_SAMPLES 32768
45    
46  class AudioThread : public Thread {  // just symbol prototyping
47    class Voice;
48    
49    //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
50    class AudioThread {
51      public:      public:
52            double Volume;               ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
53            int    ActiveVoiceCount;     ///< number of currently active voices
54            int    ActiveVoiceCountMax;  ///< the maximum voice usage since application start
55    
56          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);
57         ~AudioThread();         ~AudioThread();
58          void ProcessNoteOn(uint8_t Pitch, uint8_t Velocity);          void          SendNoteOn(uint8_t Key, uint8_t Velocity);
59          void ProcessNoteOff(uint8_t Pitch, uint8_t Velocity);          void          SendNoteOff(uint8_t Key, uint8_t Velocity);
60          void ProcessContinuousController(uint8_t Channel, uint8_t Number, uint8_t Value);          void          SendPitchbend(int Pitch);
61            void          SendControlChange(uint8_t Controller, uint8_t Value);
62          // the number of currently active streams          int           RenderAudio(uint Samples);
63          // printed on the console the main thread (along with the active streams count)          inline float* GetAudioSumBuffer(uint Channel) {
64          int ActiveVoiceCount;              return pAudioSumBuffer[Channel];
65            };
66      protected:      protected:
67          int Main(); ///< Implementation of virtual method from class Thread          struct midi_key_info_t {
68      private:              RTEList<Voice>*                      pActiveVoices;         ///< Contains the active voices associated with the MIDI key.
69          enum command_type_t {              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)
70              command_type_note_on,              bool                                 Sustained;             ///< Is true if the MIDI key is currently sustained, thus if Note-off arrived while sustain pedal pressed.
71              command_type_note_off,              bool                                 KeyPressed;            ///< Is true if the respective MIDI key is currently pressed.
72              command_type_continuous_controller              uint*                                pSustainPoolNode;      ///< FIXME: hack to allow fast deallocation of the key from the sustained key pool
73          };          };
         struct command_t {  
             command_type_t type;  
             uint8_t        channel;  
             uint8_t        pitch;  
             uint8_t        velocity;  
             uint8_t        number;  
             uint8_t        value;  
         } command;  
         RingBuffer<command_t>* pCommandQueue;  
         float*                 pAudioSumBuffer;    ///< Audio sum of all voices (32 bit)  
         Voice**                pVoices;            ///< The voice pool, containing all Voices (active and inactice voices) in unsorted order  
74    
75          RTEList<Voice *> *pActiveVoices[128];  ///< Contains all active voices sorted by MIDI key number          RingBuffer<ModulationSystem::Event>*     pEventQueue;           ///< Input event queue.
76            float*                                   pAudioSumBuffer[2];    ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel)
77            midi_key_info_t                          pMIDIKeyInfo[128];     ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
78          /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.          /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.
79             it can be allocated dynamically in real time and the allocated elements can be added to             it can be allocated dynamically in real time and the allocated elements can be added to
80             the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited             the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited
81             active voices per key. This if for example useful to manage the sustain pedal messages             active voices per key. This if for example useful to manage the sustain pedal messages
82           */           */
83          RTELMemoryPool<Voice *> *ActiveVoicePool;          RTELMemoryPool<Voice>*                   pVoicePool;            ///< Contains all voices that can be activated.
84          /* SustainedVoicePool is a dynamically allocated pool (size=MAX VOICES) and list of notes          RTELMemoryPool<uint>*                    pSustainedKeyPool;     ///< Contains the MIDI key numbers of all currently sustained keys.
85             notes that were sustained and where the corresponding MIDI note-off arrived          RTELMemoryPool<ModulationSystem::Event>* pEventPool;            ///< Contains all Event objects that can be used.
86             but cannot processed yet. Basically when the sustain pedal is pressed and the          RTEList<ModulationSystem::Event>*        pEvents;               ///< All events for the current audio fragment.
87             note-off on a certain midi key arrives. notes are not deleted from the          RTEList<ModulationSystem::Event>*        pCCEvents[ModulationSystem::destination_count];  ///< Control change events for the current audio fragment.
88             ActiveVoices[MIDIKey] list but an element is added in the SustainedVoicePool,          AudioIO*                                 pAudioIO;
89             which is a dynamically allocated pool with a builtin list.          DiskThread*                              pDiskThread;
90             Then the pedal is finally released, this list is traversed and all elements          gig::Instrument*                         pInstrument;
91             in the lists ActiveVoices[MIDIKey] ( where MIDIKey is contained in the list of          bool                                     SustainPedal;          ///< true if sustain pedal is down
92             sustained voices) are processed (voices are released)          uint8_t                                  PrevHoldCCValue;
93          */          int                                      Pitch;                 ///< Current (absolute) MIDI pitch value.
94    
95          typedef struct {          void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);
96                           int midikey;          void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
97                           int velocity;          void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
98                         } sustained_key_t;          void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
99            void KillVoice(Voice* pVoice);
         RTELMemoryPool<sustained_key_t> *SustainedKeyPool;  
   
         uint8_t PrevHoldCCValue;  
         // SustainPedal = 1 if the sustain pedal is down, otherwise it is 0  
         uint8_t SustainPedal;  
   
   
   
         AudioIO*               pAudioIO;  
         DiskThread*            pDiskThread;  
         gig::Instrument*       pInstrument;  
   
         void ActivateVoice(uint8_t MIDIKey, uint8_t Velocity);  
         void ReleaseVoice(uint8_t MIDIKey, uint8_t Velocity);  
         void ContinuousController(uint8_t Channel, uint8_t Number, uint8_t Value);  
         
100          void CacheInitialSamples(gig::Sample* pSample);          void CacheInitialSamples(gig::Sample* pSample);
101    
102            friend class Voice;
103  };  };
104    
105  #endif // __AUDIOTHREAD_H__  #endif // __AUDIOTHREAD_H__

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

  ViewVC Help
Powered by ViewVC