Skip to content

quadosc

Generates a quadrature oscillator as an array of complex samples.

The real and imaginary parts form a cosine and sine pair, separated by a quarter cycle. Use them for complex modulation or extract two audio signals with real and imag. No user-supplied function table is needed.

Syntax

signal:Complex[] = quadosc(kfreq [, ipolar [, iskip]])
signal:Complex[] = quadosc(afreq [, ipolar [, iskip]])
signal:Complex[] quadosc kfreq [, ipolar [, iskip]]
signal:Complex[] quadosc afreq [, ipolar [, iskip]]

Initialization

ipolar selects the stored form of each complex sample. It defaults to 0, for rectangular form with real and imaginary components. Use 1 for polar form with magnitude and phase. Both forms describe the same oscillator. The functions real and imag return the corresponding components in either mode.

iskip defaults to 0, which resets the oscillator to phase zero. A nonzero value keeps its phase state during reinitialization. Use 0 on first initialization and keep the same ipolar setting when retaining state.

Performance

kfreq or afreq sets the frequency in Hz. The k-rate form uses one frequency throughout each control block. The audio-rate form accepts a separate frequency for each sample. Frequency changes keep the phase continuous.

Zero frequency holds the current phase. Negative frequency reverses the direction of rotation. Keep the frequency between -sr/2 and sr/2 to avoid aliasing. The opcode does not clamp it to that range.

signal is a one-dimensional Complex array with ksmps elements, one for each audio sample in the current block. It updates at performance time. Extract audio with an audio-rate result, such as aCos = real(signal) and aSin = imag(signal).

The oscillator advances its phase before writing each sample. After a reset, its first active sample has phase 2*pi*frequency/sr radians. With constant frequency, later samples continue in equal phase steps. There is no initial-phase argument.

Polar mode stores magnitude 1 and wraps phase to the range from -pi inclusive to pi exclusive. Rectangular mode rotates the previous complex value and can accumulate small numerical changes in magnitude over long runs. Scale the output to set its level.

With sample-accurate note timing, elements before the note starts or after it ends within a block are zero. The oscillator advances only through active samples.

Examples

The example sends the cosine component to the left channel and the sine component to the right. Each note rises from 220 to 440 Hz. The first uses rectangular storage and the second uses polar storage, with the same extraction code for both.

It uses quadosc.csd.

Play the real and imaginary parts of a complex oscillator
<CsoundSynthesizer>
<CsOptions>
-d -odac
</CsOptions>
<CsInstruments>
sr = 48000
ksmps = 32
nchnls = 2
0dbfs = 1

instr Quadrature
  iPolar = p4
  kFrequency = linseg(220, p3, 440)
  signal:Complex[] = quadosc(kFrequency, iPolar)

  // Extract audio from the block of complex samples.
  aCos = real(signal)
  aSin = imag(signal)
  aLevel = linseg(0, 0.05, 0.15, p3 - 0.1, 0.15, 0.05, 0)
  out(aCos * aLevel, aSin * aLevel)
endin
</CsInstruments>
<CsScore>
// Rectangular storage, then polar storage.
i "Quadrature" 0 3 0
i "Quadrature" 3.5 3 1
e
</CsScore>
</CsoundSynthesizer>

See also

real, imag, hilbert, Complex Arithmetic and Operators, Basic Oscillators

Credits

Author Victor Lazzarini, 2026.

New in Csound 7.