/[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 13 by schoenebeck, Fri Nov 21 15:07:23 2003 UTC revision 33 by schoenebeck, Mon Feb 16 19:30:42 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 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  class AudioThread : public Thread {  // 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
49    class AudioThread {
50      public:      public:
51          int ActiveVoiceCount;  ///< number of currently active voices          double Volume;               ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
52          int ActiveVoiceCountMax;          int    ActiveVoiceCount;     ///< number of currently active voices
53            int    ActiveVoiceCountMax;  ///< the maximum voice usage since application start
54    
55          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);
56         ~AudioThread();         ~AudioThread();
57          void ProcessNoteOn(uint8_t Pitch, uint8_t Velocity);          void          SendNoteOn(uint8_t Key, uint8_t Velocity);
58          void ProcessNoteOff(uint8_t Pitch, uint8_t Velocity);          void          SendNoteOff(uint8_t Key, uint8_t Velocity);
59          void ProcessContinuousController(uint8_t Channel, uint8_t Number, uint8_t Value);          void          SendPitchbend(int Pitch);
60      protected:          void          SendControlChange(uint8_t Controller, uint8_t Value);
61          int Main(); ///< Implementation of virtual method from class Thread          int           RenderAudio(uint Samples);
62      private:          inline float* GetAudioSumBuffer(uint Channel) {
63          enum command_type_t {              return pAudioSumBuffer[Channel];
             command_type_note_on,  
             command_type_note_off,  
             command_type_continuous_controller  
64          };          };
65          struct command_t {      protected:
66              command_type_t type;          struct midi_key_info_t {
67              uint8_t        channel;              RTEList<Voice>*                      pActiveVoices;         ///< Contains the active voices associated with the MIDI key.
68              uint8_t        pitch;              bool                                 KeyPressed;            ///< Is true if the respective MIDI key is currently pressed.
69              uint8_t        velocity;              bool                                 Active;                ///< If the key contains active voices.
70              uint8_t        number;              uint*                                pSelf;                 ///< hack to allow fast deallocation of the key from the list of active keys
71              uint8_t        value;              RTEList<ModulationSystem::Event>*    pEvents;               ///< Key specific events (only Note-on, Note-off and sustain pedal currently)
         } command;  
         struct sustained_key_t {  
             int midikey;  
             int velocity;  
72          };          };
73    
74          RingBuffer<command_t>*           pCommandQueue;          RingBuffer<ModulationSystem::Event>*     pEventQueue;           ///< Input event queue.
75          float*                           pAudioSumBuffer;    ///< Audio sum of all voices (32 bit)          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          RTEList<Voice *>*                pActiveVoices[128]; ///< Contains all active voices sorted by MIDI key number          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          /* SustainedVoicePool is a dynamically allocated pool (size=MAX VOICES) and list of notes          gig::Instrument*                         pInstrument;
85             notes that were sustained and where the corresponding MIDI note-off arrived          bool                                     SustainPedal;          ///< true if sustain pedal is down
86             but cannot processed yet. Basically when the sustain pedal is pressed and the          uint8_t                                  PrevHoldCCValue;
87             note-off on a certain midi key arrives. notes are not deleted from the          int                                      Pitch;                 ///< Current (absolute) MIDI pitch value.
88             ActiveVoices[MIDIKey] list but an element is added in the SustainedVoicePool,  
89             which is a dynamically allocated pool with a builtin list.          void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);
90             Then the pedal is finally released, this list is traversed and all elements          void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
91             in the lists ActiveVoices[MIDIKey] ( where MIDIKey is contained in the list of          void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
92             sustained voices) are processed (voices are released)          void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
93          */          void KillVoice(Voice* pVoice);
         RTELMemoryPool<sustained_key_t>* SustainedKeyPool;  
         AudioIO*                         pAudioIO;  
         DiskThread*                      pDiskThread;  
         gig::Instrument*                 pInstrument;  
         bool                             SustainPedal;  ///< true if sustain pedal is down  
         uint8_t                          PrevHoldCCValue;  
   
         void ActivateVoice(uint8_t MIDIKey, uint8_t Velocity);  
         void ReleaseVoice(uint8_t MIDIKey, uint8_t Velocity);  
         void ReleaseVoice(Voice* pVoice);  
         void ContinuousController(uint8_t Channel, uint8_t Number, uint8_t Value);  
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.13  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC