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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations) (download) (as text)
Tue Feb 3 13:21:19 2004 UTC (20 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6483 byte(s)
* introduced time stamped events
* implemented jitter correction
* added pitchbend wheel support
* src/audiothread.cpp: using voice pool instead of a voice array, makes
  voice allocation more efficient and code more readable
* src/rtelmemorypool: redesigned, added some new methods and pool is now
  derived from list

1 schoenebeck 9 /***************************************************************************
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    
30     #include "global.h"
31     #include "thread.h"
32     #include "ringbuffer.h"
33 schoenebeck 31 #include "audioio.h"
34 schoenebeck 9 #include "voice.h"
35     #include "gig.h"
36 senoner 10 #include "rtelmemorypool.h"
37 schoenebeck 30 #include "modulationsystem.h"
38 senoner 10
39 schoenebeck 32 #define PITCHBEND_SEMITONES 12
40     #define MAX_AUDIO_VOICES 64
41     #define MAX_EVENTS_PER_FRAGMENT 1024
42 schoenebeck 9
43     // preload 64k samples = 128kB of data in RAM for 16 bit mono samples
44 senoner 10 #define NUM_RAM_PRELOAD_SAMPLES 32768
45 schoenebeck 9
46 schoenebeck 32 // just symbol prototyping
47     class Voice;
48    
49 schoenebeck 31 //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
50     class AudioThread {
51 schoenebeck 9 public:
52 schoenebeck 20 double Volume; ///< overall volume (a value < 1.0 means attenuation, a value > 1.0 means amplification)
53     int ActiveVoiceCount; ///< number of currently active voices
54     int ActiveVoiceCountMax; ///< the maximum voice usage since application start
55 schoenebeck 12
56 schoenebeck 9 AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);
57     ~AudioThread();
58 schoenebeck 32 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 schoenebeck 31 int RenderAudio(uint Samples);
63     inline float* GetAudioSumBuffer(uint Channel) {
64     return pAudioSumBuffer[Channel];
65     };
66 schoenebeck 32 protected:
67 schoenebeck 15 struct midi_key_info_t {
68 schoenebeck 32 RTEList<Voice>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
69     Voice* pSustainPtr; ///< 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)
70     bool Sustained; ///< Is true if the MIDI key is currently sustained, thus if Note-off arrived while sustain pedal pressed.
71     bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
72     uint* pSustainPoolNode; ///< FIXME: hack to allow fast deallocation of the key from the sustained key pool
73 schoenebeck 12 };
74 senoner 10
75 schoenebeck 32 RingBuffer<ModulationSystem::Event>* pEventQueue; ///< Input event queue.
76     float* pAudioSumBuffer[2]; ///< Audio sum of all voices (32 bit, index 0 = left channel, index 1 = right channel)
77     midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
78 senoner 10 /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.
79     it can be allocated dynamically in real time and the allocated elements can be added to
80     the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited
81     active voices per key. This if for example useful to manage the sustain pedal messages
82     */
83 schoenebeck 32 RTELMemoryPool<Voice>* pVoicePool; ///< Contains all voices that can be activated.
84     RTELMemoryPool<uint>* pSustainedKeyPool; ///< Contains the MIDI key numbers of all currently sustained keys.
85     RTELMemoryPool<ModulationSystem::Event>* pEventPool; ///< Contains all Event objects that can be used.
86     RTEList<ModulationSystem::Event>* pEvents; ///< All events for the current audio fragment.
87     RTEList<ModulationSystem::Event>* pCCEvents[ModulationSystem::destination_count]; ///< Control change events for the current audio fragment.
88     AudioIO* pAudioIO;
89     DiskThread* pDiskThread;
90     gig::Instrument* pInstrument;
91     bool SustainPedal; ///< true if sustain pedal is down
92     uint8_t PrevHoldCCValue;
93     int Pitch; ///< Current (absolute) MIDI pitch value.
94 senoner 10
95 schoenebeck 32 void ProcessNoteOn(ModulationSystem::Event* pNoteOnEvent);
96     void ProcessNoteOff(ModulationSystem::Event* pNoteOffEvent);
97     void ProcessPitchbend(ModulationSystem::Event* pPitchbendEvent);
98     void ProcessControlChange(ModulationSystem::Event* pControlChangeEvent);
99 schoenebeck 30 void KillVoice(Voice* pVoice);
100 schoenebeck 9 void CacheInitialSamples(gig::Sample* pSample);
101 schoenebeck 32
102     friend class Voice;
103 schoenebeck 9 };
104    
105     #endif // __AUDIOTHREAD_H__

  ViewVC Help
Powered by ViewVC