1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
// -*-C++-*-
// This file is part of the gmod package
// Copyright (C) 1997 by Andrew J. Robinson
#ifndef VOICE_H
#define VOICE_H
#include <limits.h>
#ifdef USE_LOCAL
#include "soundcard.h"
#else
#include <sys/soundcard.h>
#endif
#include "defines.h"
#define VOL_CHANGED 0x01
#define NOTE_CHANGED 0x02
#define PAN_CHANGED 0x04
#define KEY_CHANGED 0x10
#define BEND_CHANGED 0x20
#define OFFSET_CHANGED 0x40
#define SAMPLE_CHANGED 0x80
#define TREMOR_VOL 0x01
#define SAMPLE_VOL 0x02
#define SLIDE_VOL 0x04
class Sample;
struct songInfo;
class Voice
{
public:
Voice() :
arpegBend_(0),
arpegNum_(0),
channel_(0),
cutCount_(0),
delayCount_(0),
envelopePan_(0),
envelopeVol_(0),
finetune_(0),
fineVol_(0),
flagVol_(SAMPLE_VOL),
glissando_(0),
globalVolSlide_(0),
inPanSustain_(0),
inVolumeSustain_(0),
lastBend_(INT_MAX),
lastNote_(0),
lastRate_(0),
lastVol_(INT_MAX),
mainVolume_(255),
noteDelayed_(0),
offset_(0),
pan_(0),
panEnvelopePos_(0),
panFactor_(100),
panSlide_(0),
pitchbender_(0),
retrigger_(0),
//retrigVol_(0),
sample_(0),
slideDir_(0),
slideGoal_(0),
slidePeriod_(0),
slidePeriodGoal_(0),
slidePitch_(0),
slideRate_(0),
tremolo_(0),
tremoloDepth_(0),
tremoloOld_(0),
tremoloPosition_(0),
tremoloVol_(0),
tremoloWave_(0),
tremor_(0),
vibraBend_(0),
vibraDepth_(0),
vibraOldRate_(0),
vibraPosition_(0),
vibraRate_(0),
vibraWave_(0),
volSlide_(0),
volType_(0),
volume_(0),
volumeEnvelopePos_(0),
whatChanged_(VOL_CHANGED | PAN_CHANGED | BEND_CHANGED)
{ channel_ = numVoices_++; };
virtual ~Voice() { numVoices_--; };
virtual void doUpdates(int) = 0;
void arpeg(int);
void cutNote(int parm) { cutCount_ = parm; }
void delayNote(int amt) { delayCount_ = amt; }
int doTick(int, int, songInfo *);
void finetune(int);
void fineVol(int);
void glissando(int parm) { glissando_ = parm; }
void globalVolSlide(int amt) { globalVolSlide_ = amt; }
void init(int, const Sample *);
void keyOff();
void mainVolume(int);
void note(int, int);
void offset(int pos);
void pan(int);
void panFactor(int factor) { panFactor_ = factor; }
void panSlide(int amt) { panSlide_ = amt; }
void portAndVol(int parm);
void resetEffects(int);
void retrigger(int p, int v) { retrigger_ = p; retrigVol_ = v; }
void sample(const Sample *);
void setEnvelopePos(int);
void slideTo(int, int, int, int, int);
void tremolo(int);
void tremoloWave(int);
void tremor(int);
void vibrato(int);
void vibratoSpeed(int speed) { vibraOldRate_ = speed; }
void vibratoWave(int wave);
void volType(int type) { volType_ = type; }
void volSlide(int);
void volume(int);
protected:
virtual int doPreUpdates(int);
virtual void startNote(int, int);
void envelopePan(int);
void envelopeVol(int vol);
static unsigned char numVoices_;
static short vibraTable[][NUM_VIBRA];
unsigned char arpegCurr_;
short arpegBend_;
short arpegNote_[3];
unsigned char arpegNum_;
unsigned char channel_;
unsigned char cutCount_;
unsigned char delayCount_;
unsigned char envelopePan_; // 0..64
unsigned char envelopeVol_; // 0..64
unsigned short fadeVol_;
short finetune_;
unsigned char fineVol_;
unsigned char flagVol_;
unsigned char glissando_;
signed char globalVolSlide_;
char inPanSustain_;
char inVolumeSustain_;
int lastBend_;
unsigned char lastNote_;
short lastRate_;
int lastVol_;
unsigned char mainVolume_; // 0..255
unsigned char note_;
unsigned char noteDelayed_;
int offset_;
unsigned char pan_; // 0..255
int panEnvelopePos_;
signed char panFactor_;
signed char panSlide_;
short pitchbender_;
unsigned char retrigger_;
unsigned char retrigVol_;
const Sample *sample_;
unsigned char slideDir_;
short slideGoal_;
int slidePeriod_;
int slidePeriodGoal_;
unsigned char slidePitch_;
int slideRate_;
unsigned char tremolo_;
unsigned char tremoloDepth_;
unsigned char tremoloOld_;
unsigned char tremoloPosition_;
signed char tremoloVol_; // -128..127 (adjustment)
unsigned char tremoloWave_;
unsigned char tremor_;
unsigned char tremTotal_;
short vibraBend_;
unsigned char vibraDepth_;
unsigned char vibraOldRate_;
unsigned char vibraPosition_;
unsigned char vibraRate_;
unsigned char vibraWave_;
signed char volSlide_;
unsigned char volType_;
unsigned char volume_; // 0..255
int volumeEnvelopePos_;
unsigned char whatChanged_;
};
inline void
Voice::arpeg(int amount)
{
arpegNum_ = 3;
arpegCurr_ = 0;
arpegNote_[0] = 0;
arpegNote_[1] = ((amount >> 4) & 0x0f) * 100;
arpegNote_[2] = (amount & 0x0f) * 100;
}
inline void
Voice::envelopePan(int pan)
{
if (envelopePan_ != pan)
{
envelopePan_ = pan;
whatChanged_ |= PAN_CHANGED;
}
}
inline void
Voice::envelopeVol(int vol)
{
if (envelopeVol_ != vol)
{
envelopeVol_ = vol;
whatChanged_ |= VOL_CHANGED;
}
}
inline void
Voice::finetune(int parm)
{
if (finetune_ != parm)
{
finetune_ = parm;
whatChanged_ |= BEND_CHANGED;
}
}
inline void
Voice::fineVol(int parm)
{
volSlide_ = VOL_SLIDE_RATE * parm;
fineVol_ = 1;
}
inline void
Voice::mainVolume(int vol)
{
if (mainVolume_ != vol)
{
mainVolume_ = vol;
whatChanged_ |= VOL_CHANGED;
}
}
inline void
Voice::pan(int panVal)
{
if (pan_ != panVal)
{
pan_ = panVal;
whatChanged_ |= PAN_CHANGED;
}
}
inline void
Voice::tremolo(int amount)
{
tremolo_ = (amount >> 4) & 0x0f;
if (!tremolo_)
tremolo_ = tremoloOld_;
else
tremoloOld_ = tremolo_;
if (amount &= 0x0f)
tremoloDepth_ = amount;
}
inline void
Voice::tremoloWave(int parm)
{
if ((parm & 0x03) == 0x03)
parm -= 1;
tremoloWave_ = parm;
}
inline void
Voice::tremor(int amount)
{
tremor_ = (amount >> 4) & 0x0f;
tremTotal_ = tremor_ + (amount & 0x0f);
if (!tremTotal_)
tremor_ = 0;
}
inline void
Voice::vibratoWave(int wave)
{
if ((wave & 0x03) == 0x03)
wave--;
vibraWave_ = wave;
}
inline void
Voice::volSlide(int parm)
{
if (parm & 0xf0)
volSlide_ = VOL_SLIDE_RATE * ((parm >> 4) & 0x0f);
else
volSlide_ = -VOL_SLIDE_RATE * (parm & 0x0f);
fineVol_ = 0;
}
inline void
Voice::portAndVol(int parm)
{
volSlide(parm);
slidePitch_ = SLIDE_PORT; // this was 1, but I think SLIDE_PORT is right
}
inline void
Voice::volume(int vol)
{
if (volume_ != vol)
{
volume_ = vol;
whatChanged_ |= VOL_CHANGED;
}
};
#endif
|