DXFan:
Filter:
Classes (extension) | Libraries > miSCellaneous > DX suite

DXFan : AbstractDX : UGen : AbstractFunction : Object
ExtensionExtension

crossfades signals within a multichannel array according to demand-rate control

Description

DXFan crossfades signals to a sequence of channels, which, together with fadeTimes and stepTimes, can be passed as demand rate ugens.

NOTE: As interface and conventions of DX ugens are nearly identical, I didn't double examples for all features. It's recommended to start with the DX suite overview and go through the help file examples in this order: DXMix - DXMixIn - DXEnvFan - DXEnvFanOut - DXFan - DXFanOut. Some general conventions are treated in detail in the following examples: fades and steps in DXMix, Ex.2 – width and offset arguments in DXMix, Ex.3 – multichannel expansion in DXMix, Ex.6 – crossfade types in DXEnvFan, Ex.1.
NOTE: PanAz.ar's args pos and orientation were scaled wrongly in SC versions up to 3.8. DX ugens neutralize this bug by inverse scaling, so it should actually work the same with SC versions before 3.9 with the exception of examples with modulatable width (disabled in earlier versions). I didn't encounter differences in any other test examples, however I'd rather recommend a SC version from 3.9 onwards, if you have the choice.
NOTE: Depending on the multichannel sizes it might be necessary to increase server resources, i.e. the number of interconnect buffers (e.g. s.options.numWireBufs = 256; s.reboot). See DXMix, Ex.8 and DXEnvFan, Ex.2, DXEnvFan, Ex.4 for aspects of CPU demand.
NOTE: In my tests timing was exact up to one sample. So when used for granulation DX ugens avoid the inevitable inccuracies of language-based triggering in realtime. However care has to be taken: fade and step times must be larger than the duration of a control cycle. With default values sampleRate = 44100 Hz and blockSize = 64, this equals ca. 0.00145 sec. If you go below, the fade mechanism is messed up and you get jumps and clicks. Accordingly with fadeModes 3 and 4 you have to ensure that the remaining 'real' stepTime, which is calculated by stepTime minus fadeTime, is larger than this threshold. But as a workaround you can always lower the blocksize. See Ex.4 for aspects of granulation with high trigger rates / short grain durations.
NOTE: The current implementation is bound to counting with Dseries and – inherent to 32 bit floats – the integer accuracy limit of 2 ** 24 - 1 = 16777215. This can be an issue with setups that are using extreme short durations for hours.

Credits

Thanks to Wouter Snoei for his PlayBufCF class. It gave me a lot of inspiration for DX ugens – although in the end the implementation with PanAz and DemandEnvGen is quite different. Thanks also to Till Bovermann for ironing out a longstanding bug in PanAz.

Class Methods

DXFan.ar(out, channelsArrayRef, fadeTime: 1, stepTime: 1, fadeMode: 0, sine: 1, equalPower: 1, power: 1, curve: 0, allowTypeSeq: 0, fadeRate: 'ar', maxFadeNum: inf, maxWidth: 2, width: 2, initOutOffset: 0, maxDynOutOffset: 1, dynOutOffset: 0, allowFadeEnd: 1, size: 2, bus, zeroThr, doneAction: 0)

Arguments:

out

Determines the sequence of channels between which the signal should be crossfaded. A channel index, a demand rate or other ugen returning channel indices or a SequenceableCollection of such, causing multichannel expansion. If in this case the overall multichannel size is larger than the size of out and the latter contains demand rate ugens, they must all be wrapped into Functions.

channelsArrayRef

The signal to be crossfaded. A single channel can be passed as such, an array must be wrapped into a Ref object to avoid multichannel expansion. In this case the multichannel signal is crossfaded from one block of adjacent channels to the next, whereby the lowest channel index follows the base sequence defined by out. A SequenceableCollection causes multichannel expansion, whereby single items of the collection can itself be Ref objects containing multichannel signals.

fadeTime

A fade time, a demand rate or other ugens returning fade times or a SequenceableCollection of such, causing multichannel expansion. If in this case the overall multichannel size is larger than the size of fadeTime and the latter contains demand rate ugens, they must all be wrapped into Functions. The interpretation of fadeTime depends on fadeMode. fadeTime must be larger than the duration of a control cycle. Defaults to 1.

stepTime

A step time, a demand rate or other ugens returning step times or a SequenceableCollection of such, causing multichannel expansion. If in this case the overall multichannel size is larger than the size of stepTime and the latter contains demand rate ugens, they must all be wrapped into Functions. The interpretation of stepTime depends on fadeMode. stepTime must be larger than the duration of a control cycle. Defaults to 1.

fadeMode

Integers between 0 and 4 or a SequenceableCollection of such, causing multichannel expansion. Not modulatable.

  • fadeMode = 0: only fadeTimes are used, no steps
  • fadeMode = 1: alternate steps and fades, begin with step; stepTime means time without fade
  • fadeMode = 2: alternate fades and steps, begin with fade; stepTime means time without fade
  • fadeMode = 3: alternate steps and fades, begin with step; stepTime means sum of step and fade, thus stepTime must be larger than fadeTime, the difference must be larger than the duration of a control cycle
  • fadeMode = 4: alternate fades and steps, begin with fade; stepTime means sum of fade and step, thus stepTime must be larger than fadeTime, the difference must be larger than the duration of a control cycle

Defaults to 0.

sine

Determines the crossfade type: sine-based or not. A Boolean, 0 or 1 or a demand rate or other ugen returning sine numbers or a SequenceableCollection of such, causing multichannel expansion. If in this case the overall multichannel size is larger than the size of sine and the latter contains demand rate ugens, they must all be wrapped into Functions. Modulating this arg is only possible if allowTypeSeq equals 1. Defaults to 1.

equalPower

Determines if crossfading of equal power type (square root) should be applied. A Boolean, 0 or 1 or a demand rate or other ugen returning equalPower numbers or a SequenceableCollection of such, causing multichannel expansion. If in this case the overall multichannel size is larger than the size of equalPower and the latter contains demand rate ugens, they must all be wrapped into Functions. Modulating this arg is only possible if allowTypeSeq equals 1. Defaults to 1.

power

This only comes into play if equalPower equals 0, then it's applied to the crossfade amplitude. If power and curve are passed, power applies before. A positive Number or a demand rate or other ugen returning positive power numbers or a SequenceableCollection of such, causing multichannel expansion. If in this case the overall multichannel size is larger than the size of power and the latter contains demand rate ugens, they must all be wrapped into Functions. Sequencing this arg with demand rate ugens is only possible if allowTypeSeq equals 1. Defaults to 1.

curve

This only comes into play if equalPower equals 0, then it's applied to the crossfade amplitude according to the lincurve mapping. If power and curve are passed, power applies before. A Number or a demand rate or other ugen returning curve numbers or a SequenceableCollection of such, causing multichannel expansion. If in this case the overall multichannel size is larger than the size of curve and the latter contains demand rate ugens, they must all be wrapped into Functions. Sequencing this arg with demand rate ugens is only possible if allowTypeSeq equals 1. Calculation of curvature is not giving reliable results when width and / or dynOutOffset are being modulated at the same time. Defaults to 0.

allowTypeSeq

Enables sequencing of sine, equalPower, power and curve with demand rate ugens and modulating of sine and equalPower with other ugens. A Boolean, 0 or 1 or a SequenceableCollection of such, causing multichannel expansion. Not modulatable. As this requires more ugens running in parallel it is disabled by default = 0.

fadeRate

One of the Symbols \ar and \kr, determining the crossfade rate used by PanAz or a SequenceableCollection of such, causing multichannel expansion. Not modulatable. Defaults to \ar.

maxFadeNum

Integer determining the maximum number of fades, after which doneAction applies. A SequenceableCollection causes multichannel expansion. Not modulatable. Defaults to inf.

maxWidth

An Integer determining the maximum width or a SequenceableCollection of such, causing multichannel expansion, width goes into PanAz's width arg. maxWidth increases the internally used and potentially needed number of parallel channels. Not modulatable. Defaults to 2.

width

Integer, Float, UGen (only from SC 3.9 onwards) or a SequenceableCollection of such, causing multichannel expansion. Not modulatable in versions earlier than SC 3.9. It determines the width according to PanAz's width arg. Note that a ugen's output must not exceed maxWidth. Defaults to 2.

initOutOffset

An Integer or Float or a SequenceableCollection of such, causing multichannel expansion. Determines an initial offset for PanAz's pos arg. This can be useful for a start with full or reduced width. Not modulatable. Defaults to 0.

maxDynOutOffset

An Integer or Float or a SequenceableCollection of such, causing multichannel expansion. Determines the maximum dynOutOffset to be expected. maxDynOutOffset increases the internally used and potentially needed number of parallel channels. Not modulatable. Defaults to 1.

dynOutOffset

UGen, Integer or Float or a SequenceableCollection of such, causing multichannel expansion. By passing a ugen the movement between buses can be modulated. Note that a ugen's output must not exceed maxDynOutOffset. Defaults to 0.

allowFadeEnd

Integer, Boolean or a SequenceableCollection of such, causing multichannel expansion. Determines if a demand rate input to in with finite length will be monitored, which needs a quite complicated trigger logic and more running ugens. If set to 0, the behaviour after the end of in is undefined. Defaults to 1.

size

Integer or a SequenceableCollection of such, causing multichannel expansion. Determines the size of the returned multichannel signal. Not modulatable. Defaults to 2.

bus

Bus, bus index or a SequenceableCollection of such, causing multichannel expansion. Determines whether a private multichannel bus should be used for channel switching. This is recommended for larger width sizes (> 10 or so) as otherwise the number of ugens might result in an overflow error. Not modulatable. Defaults to nil.

zeroThr

A Number or a ugen returning zeroThr numbers or a SequenceableCollection of such, causing multichannel expansion. Determines if output values below this threshold are replaced by 0. This makes sense if the output signal is used as trigger (e.g. with DXEnvFan). In the case of low power numbers small inaccuracies are amplified, this is avoided with an appropriate zeroThr (e.g. = 0.001), as the operation is applied before taking the power. As this requires more ugens running in parallel it is disabled by default = nil.

doneAction

Integer or a SequenceableCollection of such, causing multichannel expansion. Determines the doneAction after maxFadeNum is exceeded. Defaults to 0.

DXFan.kr(out, channelsArrayRef, fadeTime: 1, stepTime: 1, fadeMode: 0, sine: 1, equalPower: 1, power: 1, curve: 0, allowTypeSeq: 0, fadeRate: 'kr', maxFadeNum: inf, maxWidth: 2, width: 2, initOutOffset: 0, maxDynOutOffset: 1, dynOutOffset: 0, allowFadeEnd: 1, size: 2, bus, zeroThr, doneAction: 0)

Inherited class methods

Instance Methods

Inherited instance methods

Examples

NOTE: Note that, as with DXEnvFan, higher values passed to 'size' and 'maxWidth' cause a significant growth of the number of used ugens. In this case consider passing a bus arg or the use of DXFanOut, see DXEnvFan, Ex.4.

 

Ex.1: Basic usage: simple crossfade

 

Ex.2: Multichannel expansion

 

Ex.3: Granulation by crossfading to different channels

 

Ex.4: Granulation with high trigger rates and / or short grain durations