1 |
schoenebeck |
5 |
/*************************************************************************** |
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 |
|
|
|
39 |
|
|
#define DEBUG 0 |
40 |
|
|
#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 |
|
|
#define NUM_RAM_PRELOAD_SAMPLES 65536 |
45 |
|
|
|
46 |
|
|
class AudioThread : public Thread { |
47 |
|
|
public: |
48 |
|
|
AudioThread(AudioIO* pAudioIO, DiskThread* pDiskThread, gig::Instrument* pInstrument); |
49 |
|
|
~AudioThread(); |
50 |
|
|
void ProcessNoteOn(uint8_t Pitch, uint8_t Velocity); |
51 |
|
|
void ProcessNoteOff(uint8_t Pitch, uint8_t Velocity); |
52 |
|
|
protected: |
53 |
|
|
int Main(); ///< Implementation of virtual method from class Thread |
54 |
|
|
private: |
55 |
|
|
enum command_type_t { |
56 |
|
|
command_type_note_on, |
57 |
|
|
command_type_note_off |
58 |
|
|
}; |
59 |
|
|
struct command_t { |
60 |
|
|
command_type_t type; |
61 |
|
|
uint8_t pitch; |
62 |
|
|
uint8_t velocity; |
63 |
|
|
} command; |
64 |
|
|
RingBuffer<command_t>* pCommandQueue; |
65 |
|
|
float* pAudioSumBuffer; ///< Audio sum of all voices (32 bit) |
66 |
|
|
Voice** pVoices; ///< The voice pool, containing all Voices (active and inactice voices) in unsorted order |
67 |
|
|
Voice* ActiveVoices[128]; ///< Contains all active voices sorted by MIDI key number |
68 |
|
|
AudioIO* pAudioIO; |
69 |
|
|
DiskThread* pDiskThread; |
70 |
|
|
gig::Instrument* pInstrument; |
71 |
|
|
|
72 |
|
|
void ActivateVoice(uint8_t MIDIKey, uint8_t Velocity); |
73 |
|
|
void ReleaseVoice(uint8_t MIDIKey, uint8_t Velocity); |
74 |
|
|
void CacheInitialSamples(gig::Sample* pSample); |
75 |
|
|
}; |
76 |
|
|
|
77 |
|
|
#endif // __AUDIOTHREAD_H__ |