--- linuxsampler/trunk/src/engines/common/AbstractVoice.h 2010/09/14 17:09:08 2121 +++ linuxsampler/trunk/src/engines/common/AbstractVoice.h 2013/05/03 14:26:32 2448 @@ -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-2012 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 + int MIDIPan; ///< the current MIDI pan value plus the value from RegionInfo + + SignalUnitRack* const pSignalUnitRack; - AbstractVoice(); + AbstractVoice(SignalUnitRack* pRack); virtual ~AbstractVoice(); inline bool IsActive() { return PlaybackState; } @@ -99,7 +104,16 @@ int iKeyGroup ); + /** Invoked when the voice is freed - gone from active to inactive. */ + virtual void VoiceFreed() { } + virtual void Synthesize(uint Samples, sample_t* pSrc, uint Skip); + + uint GetSampleRate() { return GetEngine()->SampleRate; } + + uint8_t GetControllerValue(uint8_t Controller) { + return (Controller > 128) ? 0 : pEngineChannel->ControllerTable[Controller]; + } void processCCEvents(RTList::Iterator& itEvent, uint End); void processPitchEvent(RTList::Iterator& itEvent); @@ -108,6 +122,8 @@ void processGroupEvents(RTList::Iterator& itEvent, uint End); void UpdatePortamentoPos(Pool::Iterator& itNoteOffEvent); void Kill(Pool::Iterator& itKillEvent); + void CreateEq(); + void onScaleTuningChanged(); bool Orphan; ///< true if this voice is playing a sample from an instrument that is unloaded. When the voice dies, the sample (and dimension region) will be handed back to the instrument resource manager. 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 @@ -135,7 +151,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; @@ -153,6 +169,17 @@ gig::SynthesisParam finalSynthesisParameters; gig::Loop loop; RTList* pGroupEvents; ///< Events directed to an exclusive group + + EqSupport* pEq; ///< Used for per voice equalization + bool bEqSupport; + + void PrintEqInfo() { + if (!bEqSupport || pEq == NULL) { + dmsg(1,("EQ support: no\n")); + } else { + pEq->PrintInfo(); + } + } virtual AbstractEngine* GetEngine() = 0; virtual SampleInfo GetSampleInfo() = 0; @@ -160,9 +187,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. @@ -226,6 +279,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; @@ -246,6 +301,8 @@ virtual void ProcessGroupEvent(RTList::Iterator& itEvent) = 0; void EnterReleaseStage(); + + virtual int CalculatePan(uint8_t pan) = 0; }; } // namespace LinuxSampler