--- linuxsampler/trunk/src/engines/common/AbstractVoice.h 2010/08/12 15:36:15 2115 +++ linuxsampler/trunk/src/engines/common/AbstractVoice.h 2011/07/28 12:35:49 2219 @@ -4,7 +4,7 @@ * * * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * * Copyright (C) 2005-2008 Christian Schoenebeck * - * Copyright (C) 2009-2010 Christian Schoenebeck and Grigor Iliev * + * Copyright (C) 2009-2011 Christian Schoenebeck and Grigor Iliev * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -37,6 +37,7 @@ #include "../gig/SmoothVolume.h" #include "../gig/Synthesizer.h" #include "../gig/Profiler.h" +#include "SignalUnitRack.h" // include the appropriate (unsigned) triangle LFO implementation #if CONFIG_UNSIGNED_TRIANG_ALGO == INT_MATH_SOLUTION @@ -82,8 +83,12 @@ public: type_t Type; ///< Voice Type (bit field, a voice may have several types) int MIDIKey; ///< MIDI key number of the key that triggered the voice + uint8_t MIDIVelocity; ///< MIDI velocity of the key that triggered the voice + uint8_t MIDIPan; ///< the current MIDI pan value + + SignalUnitRack* const pSignalUnitRack; - AbstractVoice(); + AbstractVoice(SignalUnitRack* pRack); virtual ~AbstractVoice(); inline bool IsActive() { return PlaybackState; } @@ -100,6 +105,8 @@ ); virtual void Synthesize(uint Samples, sample_t* pSrc, uint Skip); + + uint GetSampleRate() { return GetEngine()->SampleRate; } void processCCEvents(RTList::Iterator& itEvent, uint End); void processPitchEvent(RTList::Iterator& itEvent); @@ -135,7 +142,7 @@ 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. uint Delay; ///< Number of sample points the rendering process of this voice should be delayed (jitter correction), will be set to 0 after the first audio fragment cycle EG* pEG1; ///< Envelope Generator 1 (Amplification) - gig::EGADSR EG2; ///< Envelope Generator 2 (Filter cutoff frequency) TODO: use common EG instead of gig + EG* pEG2; ///< Envelope Generator 2 (Filter cutoff frequency) gig::EGDecay EG3; ///< Envelope Generator 3 (Pitch) TODO: use common EG instead? midi_ctrl VCFCutoffCtrl; midi_ctrl VCFResonanceCtrl; @@ -160,9 +167,35 @@ virtual InstrumentInfo GetInstrumentInfo() = 0; /** + * Most of the important members of the voice are set when the voice + * is triggered (like pEngineChannel, pRegion, pSample, etc). + * This method is called after these members are set and before + * the voice is actually triggered. + * Override this method if you need to do some additional + * initialization which depends on these members before the voice + * is triggered. + */ + virtual void AboutToTrigger() { } + + virtual bool EG1Finished(); + + /** * Gets the sample cache size in bytes. */ virtual unsigned long GetSampleCacheSize() = 0; + + /** + * Because in most cases we cache part of the sample in RAM, if the + * offset is too big (will extend beyond the RAM cache if the cache contains + * the beginning of the sample) we should cache in the RAM buffer not the + * beginning of the sample but a part that starts from the sample offset point. + * In that case the current sample position should start from zero (Pos). + * When the offset fits into RAM buffer or the whole sample is cached + * in RAM, Pos should contain the actual offset. + * We don't trim the sample because it might have a defined + * loop start point before the start point of the playback. + */ + virtual void SetSampleStartOffset(); /** * Returns the correct amplitude factor for the given \a MIDIKeyVelocity. @@ -188,6 +221,8 @@ */ virtual double CalculateCrossfadeVolume(uint8_t MIDIKeyVelocity) = 0; + virtual MidiKeyBase* GetMidiKeyInfo(int MIDIKey) = 0; + virtual int OrderNewStream() = 0; virtual PitchInfo CalculatePitchInfo(int PitchBend); @@ -224,6 +259,8 @@ */ virtual EGInfo CalculateEG2ControllerInfluence(double eg2ControllerValue) = 0; + virtual void TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) = 0; + virtual float CalculateCutoffBase(uint8_t MIDIKeyVelocity) = 0; virtual float CalculateFinalCutoff(float cutoffBase) = 0;