syncphasor

syncphasor — Produces a normalized moving phase value with sync input and output.

Description

Produces a moving phase value between zero and one and an extra impulse output ("sync out") whenever its phase value crosses or is reset to zero. The phase can be reset at any time by an impulse on the "sync in" parameter.

Syntax

aphase, asyncout syncphasor xcps, asyncin, [, iphs]

Initialization

iphs (optional) -- initial phase, expressed as a fraction of a cycle (0 to 1). A negative value will cause phase initialization to be skipped. The default value is zero.

Performance

aphase -- the output phase value; always between 0 and 1.

asyncout -- the sync output has a value of 1.0 for one sample whenever the phase value crosses zero or whenever the sync input is non-zero. It is zero at all other times.

asyncin -- the sync input causes the phase to reset to zero whenever asyncin is non-zero.

xcps -- frequency of the phasor in cycles-per-second. If xcps is negative, the phase value will decrease from 1 to 0 instead of increasing.

An internal phase is successively accumulated in accordance with the xcps frequency to produce a moving phase value, normalized to lie in the range 0 <= phs < 1. When used as the index to a table unit, this phase (multiplied by the desired function table length) will cause it to behave like an oscillator.

The phase of syncphasor though can be synced to another phasor (or other signal) using the asyncin parameter. Any time that asyncin is a non-zero value, the value of aphase will be reset to zero. syncphasor also outputs its own "sync" signal that consists of a one-sample impulse whenever its phase crosses zero or is reset. This makes it easy to chain together multiple syncphasor opcodes to create an oscillator "hard sync" effect.

Examples

Here is an example of the syncphasor opcode. It uses the file syncphasor.csd.

Example 445. Example of the syncphasor opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o abs.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

instr 1
    ; Use two syncphasors - one is the "master",
    ; the other the "slave"
    
    ; master's frequency determines pitch
    imastercps  =           cpspch(p4)
    imaxamp     =           10000

    ; the slave's frequency affects the timbre 
    kslavecps   line        imastercps, p3, imastercps * 3
    
    ; the master "oscillator"
    ; the master has no sync input 
    anosync     init        0.0
    am, async   syncphasor  imastercps, anosync
    
    ; the slave "oscillator"
    aout, as    syncphasor  kslavecps, async
    
    adeclick    linseg      0.0, 0.05, 1.0, p3 - 0.1, 1.0, 0.05, 0.0
    
    ; Output the slave's phase value which is a rising
    ; sawtooth wave.  This produces aliasing, but hey, this
    ; this is just an example ;)
    
              out         aout * adeclick * imaxamp
endin

</CsInstruments>
<CsScore>

i1 0 1    7.00
i1 + 0.5  7.02
i1 + .    7.05
i1 + .    7.07
i1 + .    7.09
i1 + 2    7.06

e

</CsScore>
</CsoundSynthesizer>


See also

phasor.

And the Table Access opcodes like: table, tablei, table3 and tab.

Credits

Adapted from the phasor opcode by Anthony Kozar
January 2008

New in Csound version 5.08