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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (show annotations) (download) (as text)
Sun Nov 16 19:01:50 2003 UTC (15 years, 8 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4393 byte(s)
* src/gig.cpp: fixed bug in decompression algorithm which caused it not to
  detect the end of a stream and let the disk streams reload forever also
  resulting in strange sounds at the end of disk voices (concerned only
  playback of compressed gig files)
* src/audiothread.cpp: deallocation of voices when they reached the end of
  playback (thus e.g. when sustain pedal is pressed and a disk stream
  reached it's end)
* various endian corrections needed for non intel systems
* introduced debug level, you can set the debug level and thus the
  verbosity of LinuxSampler in src/global.h

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
27 #include "global.h"
28 #include "diskthread.h"
29 #include "ringbuffer.h"
30 #include "stream.h"
31 #include "gig.h"
32
33 #define MAX_PITCH 4 //FIXME: at the moment in octaves, should be changed into semitones
34 #define USE_LINEAR_INTERPOLATION 1
35
36 class Voice {
37 public:
38 // Attributes
39 int MIDIKey; ///< MIDI key number of the key that triggered the voice
40 Voice** pSelfPtr; ///< FIXME: hack to be able to remove the voice from the active voices list within the audio thread, ugly but fast
41
42 // Methods
43 Voice(DiskThread* pDiskThread);
44 ~Voice();
45 void Kill();
46 void RenderAudio();
47 void Trigger(int MIDIKey, uint8_t Velocity, gig::Instrument* Instrument);
48 inline bool IsActive() { return Active; }
49 inline void SetOutput(float* pOutput, uint OutputBufferSize) { this->pOutput = pOutput; this->OutputBufferSize = OutputBufferSize; }
50 private:
51 // Types
52 enum playback_state_t {
53 playback_state_ram,
54 playback_state_disk,
55 playback_state_end
56 };
57
58 // Attributes
59 float* pOutput; ///< Audio output buffer
60 uint OutputBufferSize; ///< Fragment size of the audio output buffer
61 double Pos;
62 double CurrentPitch;
63 gig::Sample* pSample;
64 gig::Region* pRegion;
65 bool Active;
66 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
67 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
68 Stream::reference_t DiskStreamRef;
69 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.
70
71 // Static Attributes
72 static DiskThread* pDiskThread;
73
74 // Methods
75 void Interpolate(sample_t* pSrc);
76 inline int double_to_int(double f) {
77 #if ARCH_X86
78 int i;
79 __asm__ ("fistl %0" : "=m"(i) : "st"(f - 0.5) );
80 return i;
81 #else
82 return (int) f;
83 #endif // ARCH_X86
84 }
85 };
86
87 #endif // __VOICE_H__

  ViewVC Help
Powered by ViewVC