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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (hide annotations) (download) (as text)
Sun Dec 7 05:03:43 2003 UTC (20 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5660 byte(s)
* src/audioio.cpp: added support for Alsa 1.0.0
* src/audiothread.cpp: fixed several bugs in sustain pedal handling
* src/diskthread.cpp: fixed several bugs which occured under extreme
  conditions (endless loop in audiothread, freezing the whole application,
  outage of available disk streams)
* src/voice.cpp: fixed cubic interpolation (disabled by default; you can
  enable it by setting USE_LINEAR_INTERPOLATION to 0 in src/voice.h)
* src/configure.in: added check for Alsa version

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 <stdio.h>
27     #include <stdlib.h>
28     #include <math.h>
29     #include <unistd.h>
30     #include <fcntl.h>
31    
32     #include "global.h"
33     #include "thread.h"
34     #include "ringbuffer.h"
35     #include "voice.h"
36     #include "audioio.h"
37     #include "gig.h"
38 senoner 10 #include "rtelmemorypool.h"
39    
40 schoenebeck 9 #define PITCHBEND_SEMITONES 12
41     #define MAX_AUDIO_VOICES 64
42    
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     class AudioThread : public Thread {
47     public:
48 schoenebeck 15 int ActiveVoiceCount; ///< number of currently active voices
49     int ActiveVoiceCountMax; ///< the maximum voice usage since application start
50 schoenebeck 12
51 schoenebeck 9 AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument);
52     ~AudioThread();
53 schoenebeck 18 void SendNoteOn(uint8_t Pitch, uint8_t Velocity);
54     void SendNoteOff(uint8_t Pitch, uint8_t Velocity);
55     void SendControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);
56 schoenebeck 9 protected:
57     int Main(); ///< Implementation of virtual method from class Thread
58     private:
59     enum command_type_t {
60     command_type_note_on,
61 senoner 10 command_type_note_off,
62     command_type_continuous_controller
63 schoenebeck 9 };
64     struct command_t {
65     command_type_t type;
66 senoner 10 uint8_t channel;
67 schoenebeck 9 uint8_t pitch;
68     uint8_t velocity;
69 senoner 10 uint8_t number;
70     uint8_t value;
71 schoenebeck 9 } command;
72 schoenebeck 15 struct midi_key_info_t {
73 schoenebeck 18 RTEList<Voice*>* pActiveVoices; ///< Contains the active voices associated with the MIDI key.
74     RTEList<Voice*>::NodeHandle hSustainPtr; ///< 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)
75     bool Sustained; ///< Is true if the MIDI key is currently sustained, thus if Note-off arrived while sustain pedal pressed.
76     bool KeyPressed; ///< Is true if the respective MIDI key is currently pressed.
77     uint* pSustainPoolNode; ///< FIXME: hack to allow fast deallocation of the key from the sustained key pool
78 schoenebeck 12 };
79 senoner 10
80 schoenebeck 12 RingBuffer<command_t>* pCommandQueue;
81     float* pAudioSumBuffer; ///< Audio sum of all voices (32 bit)
82     Voice** pVoices; ///< The voice pool, containing all Voices (active and inactice voices) in unsorted order
83 schoenebeck 15 midi_key_info_t pMIDIKeyInfo[128]; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key
84 senoner 10 /* ActiveVoicePool is a memory pool of limited size (size=MAX VOICES) of active voices.
85     it can be allocated dynamically in real time and the allocated elements can be added to
86     the linked lists represented by ActiveVoices[MIDIKey]. This means we can have unlimited
87     active voices per key. This if for example useful to manage the sustain pedal messages
88     */
89 schoenebeck 15 RTELMemoryPool<Voice*>* ActiveVoicePool;
90     RTELMemoryPool<uint>* SustainedKeyPool; ///< Contains the MIDI key numbers of all currently sustained keys.
91 schoenebeck 12 AudioIO* pAudioIO;
92     DiskThread* pDiskThread;
93     gig::Instrument* pInstrument;
94 schoenebeck 15 bool SustainPedal; ///< true if sustain pedal is down
95 schoenebeck 12 uint8_t PrevHoldCCValue;
96 senoner 10
97 schoenebeck 18 void ProcessNoteOn(uint8_t MIDIKey, uint8_t Velocity);
98     void ProcessNoteOff(uint8_t MIDIKey, uint8_t Velocity);
99     void ProcessControlChange(uint8_t Channel, uint8_t Number, uint8_t Value);
100 schoenebeck 12 void ReleaseVoice(Voice* pVoice);
101 schoenebeck 9 void CacheInitialSamples(gig::Sample* pSample);
102     };
103    
104     #endif // __AUDIOTHREAD_H__

  ViewVC Help
Powered by ViewVC