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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 37 - (show annotations) (download) (as text)
Wed Mar 10 22:01:36 2004 UTC (20 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6633 byte(s)
* src/eg_vca.cpp: added following transitions to the envelope generator:
  'Attack_Hold' -> 'Release', 'Decay_1' -> 'Release' in case of a release
  event
* EG1 parameters 'Attack Time', 'Release Time' and 'Sustain Time' are now
  controllable by a MIDI controller defined in the .gig file
* src/voice.cpp: fixed bug in pitch calculation which caused new triggered
  voices to be played back without honoring the current pitch bend value

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 <math.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <pthread.h>
30 #include <sstream>
31
32 #include "global.h"
33 #include "thread.h"
34 #include "ringbuffer.h"
35 #include "audioio.h"
36 #include "voice.h"
37 #include "gig.h"
38 #include "rtelmemorypool.h"
39 #include "modulationsystem.h"
40 #include "network/lscp.h"
41
42 #define PITCHBEND_SEMITONES 12
43 #define MAX_AUDIO_VOICES 64
44
45 // preload 64k samples = 128kB of data in RAM for 16 bit mono samples
46 #define NUM_RAM_PRELOAD_SAMPLES 32768
47
48 // 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:
54 double Volume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
55 int ActiveVoiceCount; ///< number of currently active voices
56 int ActiveVoiceCountMax; ///< the maximum voice usage since application start
57 DiskThread* pDiskThread;
58
59 AudioThread(AudioIO* pAudioIO);
60 ~AudioThread();
61 result_t LoadInstrument(const char* FileName, uint Instrument);
62 void Reset();
63 void SendNoteOn(uint8_t Key, uint8_t Velocity);
64 void SendNoteOff(uint8_t Key, uint8_t Velocity);
65 void SendPitchbend(int Pitch);
66 void SendControlChange(uint8_t Controller, uint8_t Value);
67 int RenderAudio(uint Samples);
68 inline float* GetAudioSumBuffer(uint Channel) {
69 return pAudioSumBuffer[Channel];
70 };
71 protected:
72 struct midi_key_info_t {
73 RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
74 bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
75 bool Active; ///< If the key contains active voices.
76 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)
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.
82 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
84 RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
85 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.
87 RTEList<ModulationSystem::Event>* pEvents; ///< All events for the current audio fragment.
88 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;
91 RIFF::File* pRIFF;
92 gig::File* pGig;
93 gig::Instrument* pInstrument;
94 bool SustainPedal; ///< true if sustain pedal is down
95 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);
101 void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
102 void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
103 void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
104 void KillVoice(Voice* pVoice);
105 void CacheInitialSamples(gig::Sample* pSample);
106 void ResetInternal();
107
108 friend class Voice;
109 };
110
111 #endif // __AUDIOTHREAD_H__

  ViewVC Help
Powered by ViewVC