/[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 30 by schoenebeck, Sun Jan 11 16:43:54 2004 UTC revision 35 by schoenebeck, Fri Mar 5 13:46:15 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>
29    #include <pthread.h>
30    #include <sstream>
31    
32  #include "global.h"  #include "global.h"
33  #include "thread.h"  #include "thread.h"
34  #include "ringbuffer.h"  #include "ringbuffer.h"
 #include "voice.h"  
35  #include "audioio.h"  #include "audioio.h"
36    #include "voice.h"
37  #include "gig.h"  #include "gig.h"
38  #include "rtelmemorypool.h"  #include "rtelmemorypool.h"
39  #include "modulationsystem.h"  #include "modulationsystem.h"
40    #include "network/lscp.h"
41    
42  #define PITCHBEND_SEMITONES     12  #define PITCHBEND_SEMITONES             12
43  #define MAX_AUDIO_VOICES        64  #define MAX_AUDIO_VOICES                64
44    
45  // 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
46  #define NUM_RAM_PRELOAD_SAMPLES 32768  #define NUM_RAM_PRELOAD_SAMPLES 32768
47    
48  class AudioThread : public Thread {  // just symbol prototyping
49    class Voice;
50    
51    //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
52    class AudioThread {
53      public:      public:
54          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)
55          int    ActiveVoiceCount;     ///< number of currently active voices          int          ActiveVoiceCount;     ///< number of currently active voices
56          int    ActiveVoiceCountMax;  ///< the maximum voice usage since application start          int          ActiveVoiceCountMax;  ///< the maximum voice usage since application start
57            DiskThread*  pDiskThread;
58    
59          AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);          AudioThread(AudioIO* pAudioIO);
60         ~AudioThread();         ~AudioThread();
61          void SendNoteOn(uint8_t Pitch, uint8_t Velocity);          result_t      LoadInstrument(const char* FileName, uint Instrument);
62          void SendNoteOff(uint8_t Pitch, uint8_t Velocity);          void          Reset();
63          void SendControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);          void          SendNoteOn(uint8_t Key, uint8_t Velocity);
64      protected:          void          SendNoteOff(uint8_t Key, uint8_t Velocity);
65          int Main(); ///< Implementation of virtual method from class Thread          void          SendPitchbend(int Pitch);
66      private:          void          SendControlChange(uint8_t Controller, uint8_t Value);
67          enum command_type_t {          int           RenderAudio(uint Samples);
68              command_type_note_on,          inline float* GetAudioSumBuffer(uint Channel) {
69              command_type_note_off,              return pAudioSumBuffer[Channel];
             command_type_continuous_controller  
70          };          };
71          struct command_t {      protected:
             command_type_t type;  
             uint8_t        channel;  
             uint8_t        pitch;  
             uint8_t        velocity;  
             uint8_t        number;  
             uint8_t        value;  
         } command;  
72          struct midi_key_info_t {          struct midi_key_info_t {
73              RTEList<Voice*>*             pActiveVoices;      ///< Contains the active voices associated with the MIDI key.              RTEList<Voice>*                      pActiveVoices;         ///< Contains the active voices associated with the MIDI key.
74              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.
75              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.
76              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
77              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)
78          };          };
79    
80          RingBuffer<command_t>*           pCommandQueue;          RingBuffer<ModulationSystem::Event>*     pEventQueue;           ///< Input event queue.
81          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)
82          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
83          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.
84          /* 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.
85             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.
86             the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited          RTEList<ModulationSystem::Event>*        pEvents;               ///< All events for the current audio fragment.
87             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.
88           */          AudioIO*                                 pAudioIO;
89          RTELMemoryPool<Voice*>*          ActiveVoicePool;          RIFF::File*                              pRIFF;
90          RTELMemoryPool<uint>*            SustainedKeyPool;   ///< Contains the MIDI key numbers of all currently sustained keys.          gig::File*                               pGig;
91          AudioIO*                         pAudioIO;          gig::Instrument*                         pInstrument;
92          DiskThread*                      pDiskThread;          bool                                     SustainPedal;          ///< true if sustain pedal is down
93          gig::Instrument*                 pInstrument;          uint8_t                                  PrevHoldCCValue;
94          bool                             SustainPedal;       ///< true if sustain pedal is down          int                                      Pitch;                 ///< Current (absolute) MIDI pitch value.
95          uint8_t                          PrevHoldCCValue;          bool                                     SuspensionRequested;
96            pthread_mutex_t                          __render_state_mutex;
97          void ProcessNoteOn(uint8_t MIDIKey, uint8_t Velocity);          pthread_cond_t                           __render_exit_condition;
98          void ProcessNoteOff(uint8_t MIDIKey, uint8_t Velocity);  
99          void ProcessControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);          void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);
100            void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
101            void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
102            void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
103          void KillVoice(Voice* pVoice);          void KillVoice(Voice* pVoice);
104          void CacheInitialSamples(gig::Sample* pSample);          void CacheInitialSamples(gig::Sample* pSample);
105            void ResetInternal();
106    
107            friend class Voice;
108  };  };
109    
110  #endif // __AUDIOTHREAD_H__  #endif // __AUDIOTHREAD_H__

Legend:
Removed from v.30  
changed lines
  Added in v.35

  ViewVC Help
Powered by ViewVC