/[svn]/linuxsampler/tags/start/voice.h
ViewVC logotype

Contents of /linuxsampler/tags/start/voice.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations) (download) (as text)
Sat Oct 25 20:24:32 2003 UTC (20 years, 5 months ago) by (unknown author)
File MIME type: text/x-c++hdr
File size: 4039 byte(s)
This commit was manufactured by cvs2svn to create tag 'start'.
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 __VOICE_H__
24 #define __VOICE_H__
25
26 #include "global.h"
27 #include "diskthread.h"
28 #include "ringbuffer.h"
29 #include "stream.h"
30 #include "gig.h"
31
32 #define MAX_PITCH 4 //FIXME: at the moment in octaves, should be changed into semitones
33 #define USE_LINEAR_INTERPOLATION 1
34
35 class Voice {
36 public:
37 // Methods
38 Voice(DiskThread* pDiskThread);
39 ~Voice();
40 void Kill();
41 void RenderAudio();
42 void Trigger(int MIDIKey, uint8_t Velocity, gig::Instrument* Instrument);
43 inline bool IsActive() { return Active; }
44 inline void SetOutput(float* pOutput, uint OutputBufferSize) { this->pOutput = pOutput; this->OutputBufferSize = OutputBufferSize; }
45 private:
46 // Types
47 enum playback_state_t {
48 playback_state_ram,
49 playback_state_disk,
50 playback_state_end
51 };
52
53 // Attributes
54 float* pOutput; ///< Audio output buffer
55 uint OutputBufferSize; ///< Fragment size of the audio output buffer
56 double Pos;
57 double CurrentPitch;
58 gig::Sample* pSample;
59 gig::Region* pRegion;
60 bool Active;
61 playback_state_t PlaybackState; ///< When a sample will be triggered, it will be first played from RAM cache and after a couple of sample points it will switch to disk streaming and at the end of a disk stream we have to add null samples, so the interpolator can do it's work correctly
62 bool DiskVoice; ///< If the sample is very short it completely fits into the RAM cache and doesn't need to be streamed from disk, in that case this flag is set to false
63 Stream::reference_t DiskStreamRef;
64 unsigned long MaxRAMPos; ///< The upper allowed limit (not actually the end) in the RAM sample cache, after that point it's not safe to chase the interpolator another time over over the current cache position, instead we switch to disk then.
65
66 // Static Attributes
67 static DiskThread* pDiskThread;
68
69 // Methods
70 void Interpolate(sample_t* pSrc);
71 inline int double_to_int(double f) {
72 int i;
73 __asm__ ("fistl %0" : "=m"(i) : "st"(f - 0.5) );
74 return i;
75 }
76 };
77
78 #endif // __VOICE_H__

  ViewVC Help
Powered by ViewVC