/[svn]/linuxsampler/tags/v0_1_0/src/voice.h
ViewVC logotype

Annotation of /linuxsampler/tags/v0_1_0/src/voice.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, 5 months ago) by schoenebeck
Original Path: linuxsampler/trunk/src/voice.h
File MIME type: text/x-c++hdr
File size: 4639 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 __VOICE_H__
24     #define __VOICE_H__
25    
26 senoner 10
27 schoenebeck 9 #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 schoenebeck 18 #define USE_LINEAR_INTERPOLATION 1 ///< set to 0 if you prefer cubic interpolation (slower, better quality)
35 schoenebeck 9
36     class Voice {
37     public:
38 schoenebeck 12 // Attributes
39 schoenebeck 15 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     uint ReleaseVelocity; ///< Reflects the release velocity value if a note-off command arrived for the voice.
42 schoenebeck 12
43 schoenebeck 9 // Methods
44     Voice(DiskThread* pDiskThread);
45     ~Voice();
46     void Kill();
47     void RenderAudio();
48 schoenebeck 18 int Trigger(int MIDIKey, uint8_t Velocity, gig::Instrument* Instrument);
49 schoenebeck 9 inline bool IsActive() { return Active; }
50     inline void SetOutput(float* pOutput, uint OutputBufferSize) { this->pOutput = pOutput; this->OutputBufferSize = OutputBufferSize; }
51     private:
52     // Types
53     enum playback_state_t {
54     playback_state_ram,
55     playback_state_disk,
56     playback_state_end
57     };
58    
59     // Attributes
60 schoenebeck 17 float Volume;
61 schoenebeck 9 float* pOutput; ///< Audio output buffer
62     uint OutputBufferSize; ///< Fragment size of the audio output buffer
63     double Pos;
64     double CurrentPitch;
65     gig::Sample* pSample;
66     gig::Region* pRegion;
67     bool Active;
68     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
69     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
70     Stream::reference_t DiskStreamRef;
71     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.
72    
73     // Static Attributes
74     static DiskThread* pDiskThread;
75    
76     // Methods
77     void Interpolate(sample_t* pSrc);
78     inline int double_to_int(double f) {
79     #if ARCH_X86
80     int i;
81     __asm__ ("fistl %0" : "=m"(i) : "st"(f - 0.5) );
82     return i;
83     #else
84     return (int) f;
85     #endif // ARCH_X86
86     }
87     };
88    
89     #endif // __VOICE_H__

  ViewVC Help
Powered by ViewVC