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 |
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 |
|
result_t LoadInstrument(const char* FileName, uint Instrument); |
57 |
|
void Reset(); |
58 |
void SendNoteOn(uint8_t Key, uint8_t Velocity); |
void SendNoteOn(uint8_t Key, uint8_t Velocity); |
59 |
void SendNoteOff(uint8_t Key, uint8_t Velocity); |
void SendNoteOff(uint8_t Key, uint8_t Velocity); |
60 |
void SendPitchbend(int Pitch); |
void SendPitchbend(int Pitch); |
72 |
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) |
73 |
}; |
}; |
74 |
|
|
75 |
|
uint8_t ControllerTable[128]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel. |
76 |
RingBuffer<ModulationSystem::Event>* pEventQueue; ///< Input event queue. |
RingBuffer<ModulationSystem::Event>* pEventQueue; ///< Input event queue. |
77 |
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) |
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 |
80 |
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. |
81 |
RTELMemoryPool<ModulationSystem::Event>* pEventPool; ///< Contains all Event objects that can be used. |
RTELMemoryPool<ModulationSystem::Event>* pEventPool; ///< Contains all Event objects that can be used. |
82 |
RTEList<ModulationSystem::Event>* pEvents; ///< All events for the current audio fragment. |
RTEList<ModulationSystem::Event>* pEvents; ///< All events for the current audio fragment. |
83 |
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. |
84 |
|
RTEList<ModulationSystem::Event>* pSynthesisEvents[ModulationSystem::destination_count]; ///< Events directly affecting synthesis parameter (like pitch, volume and filter). |
85 |
AudioIO* pAudioIO; |
AudioIO* pAudioIO; |
86 |
DiskThread* pDiskThread; |
RIFF::File* pRIFF; |
87 |
|
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 |
|
uint8_t PrevHoldCCValue; |
|
90 |
int Pitch; ///< Current (absolute) MIDI pitch value. |
int Pitch; ///< Current (absolute) MIDI pitch value. |
91 |
|
bool SuspensionRequested; |
92 |
|
pthread_mutex_t __render_state_mutex; |
93 |
|
pthread_cond_t __render_exit_condition; |
94 |
|
|
95 |
void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent); |
void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent); |
96 |
void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent); |
void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent); |
98 |
void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent); |
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; |
friend class Voice; |
104 |
}; |
}; |