/[svn]/linuxsampler/trunk/src/audiothread.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/audiothread.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download) (as text)
Wed Mar 31 10:28:42 2004 UTC (20 years ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6527 byte(s)
removed unnecessary dependencies

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #ifndef __AUDIOTHREAD_H__
24 #define __AUDIOTHREAD_H__
25
26 #include <sstream>
27
28 #include "global.h"
29 #include "ringbuffer.h"
30 #include "audioio.h"
31 #include "voice.h"
32 #include "gig.h"
33 #include "rtelmemorypool.h"
34 #include "modulationsystem.h"
35 #include "network/lscp.h"
36
37 #define PITCHBEND_SEMITONES 12
38 #define MAX_AUDIO_VOICES 64
39
40 // preload 64k samples = 128kB of data in RAM for 16 bit mono samples
41 #define NUM_RAM_PRELOAD_SAMPLES 32768
42
43 // just symbol prototyping
44 class Voice;
45
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
47 class AudioThread {
48 public:
49 double Volume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
50 int ActiveVoiceCount; ///< number of currently active voices
51 int ActiveVoiceCountMax; ///< the maximum voice usage since application start
52 DiskThread* pDiskThread;
53
54 AudioThread(AudioIO* pAudioIO);
55 ~AudioThread();
56 result_t LoadInstrument(const char* FileName, uint Instrument);
57 void Reset();
58 void SendNoteOn(uint8_t Key, uint8_t Velocity);
59 void SendNoteOff(uint8_t Key, uint8_t Velocity);
60 void SendPitchbend(int Pitch);
61 void SendControlChange(uint8_t Controller, uint8_t Value);
62 int RenderAudio(uint Samples);
63 inline float* GetAudioSumBuffer(uint Channel) {
64 return pAudioSumBuffer[Channel];
65 };
66 protected:
67 struct midi_key_info_t {
68 RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
69 bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
70 bool Active; ///< If the key contains active voices.
71 uint* pSelf; ///< hack to allow fast deallocation of the key from the list of active keys
72 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.
77 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
79 RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
80 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.
82 RTEList<ModulationSystem::Event>* pEvents; ///< All events for the current audio fragment.
83 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;
86 RIFF::File* pRIFF;
87 gig::File* pGig;
88 gig::Instrument* pInstrument;
89 bool SustainPedal; ///< true if sustain pedal is down
90 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);
96 void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
97 void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
98 void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
99 void KillVoice(Voice* pVoice);
100 void CacheInitialSamples(gig::Sample* pSample);
101 void ResetInternal();
102
103 friend class Voice;
104 };
105
106 #endif // __AUDIOTHREAD_H__

  ViewVC Help
Powered by ViewVC