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" |
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 |
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 |
//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 { |
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 |
|
result_t LoadInstrument(const char* FileName, uint Instrument); |
62 |
|
void Reset(); |
63 |
void SendNoteOn(uint8_t Key, uint8_t Velocity); |
void SendNoteOn(uint8_t Key, uint8_t Velocity); |
64 |
void SendNoteOff(uint8_t Key, uint8_t Velocity); |
void SendNoteOff(uint8_t Key, uint8_t Velocity); |
65 |
void SendPitchbend(int Pitch); |
void SendPitchbend(int Pitch); |
76 |
uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys |
uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys |
77 |
RTEList<ModulationSystem::Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently) |
RTEList<ModulationSystem::Event>* pEvents; ///< Key specific events (only Note-on, Note-off and sustain pedal currently) |
78 |
}; |
}; |
79 |
|
|
80 |
|
uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel. |
81 |
RingBuffer<ModulationSystem::Event>* pEventQueue; ///< Input event queue. |
RingBuffer<ModulationSystem::Event>* pEventQueue; ///< Input event queue. |
82 |
float* pAudioSumBuffer[2]; ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel) |
float* pAudioSumBuffer[2]; ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel) |
83 |
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 |
85 |
RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices. |
RTELMemoryPool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices. |
86 |
RTELMemoryPool<ModulationSystem::Event>* pEventPool; ///< Contains all Event objects that can be used. |
RTELMemoryPool<ModulationSystem::Event>* pEventPool; ///< Contains all Event objects that can be used. |
87 |
RTEList<ModulationSystem::Event>* pEvents; ///< All events for the current audio fragment. |
RTEList<ModulationSystem::Event>* pEvents; ///< All events for the current audio fragment. |
88 |
RTEList<ModulationSystem::Event>* pCCEvents[ModulationSystem::destination_count]; ///< Control change events for the current audio fragment. |
RTEList<ModulationSystem::Event>* pCCEvents; ///< All control change events for the current audio fragment. |
89 |
|
RTEList<ModulationSystem::Event>* pSynthesisEvents[ModulationSystem::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter). |
90 |
AudioIO* pAudioIO; |
AudioIO* pAudioIO; |
91 |
DiskThread* pDiskThread; |
RIFF::File* pRIFF; |
92 |
|
gig::File* pGig; |
93 |
gig::Instrument* pInstrument; |
gig::Instrument* pInstrument; |
94 |
bool SustainPedal; ///< true if sustain pedal is down |
bool SustainPedal; ///< true if sustain pedal is down |
|
uint8_t PrevHoldCCValue; |
|
95 |
int Pitch; ///< Current (absolute) MIDI pitch value. |
int Pitch; ///< Current (absolute) MIDI pitch value. |
96 |
|
bool SuspensionRequested; |
97 |
|
pthread_mutex_t __render_state_mutex; |
98 |
|
pthread_cond_t __render_exit_condition; |
99 |
|
|
100 |
void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent); |
void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent); |
101 |
void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent); |
void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent); |
103 |
void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent); |
void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent); |
104 |
void KillVoice(Voice* pVoice); |
void KillVoice(Voice* pVoice); |
105 |
void CacheInitialSamples(gig::Sample* pSample); |
void CacheInitialSamples(gig::Sample* pSample); |
106 |
|
void ResetInternal(); |
107 |
|
|
108 |
friend class Voice; |
friend class Voice; |
109 |
}; |
}; |