Skip to content

vco2ift

Returns a table number at i-time for a given oscillator frequency and waveform.

vco2ift is the same as vco2ft, but works at i-time. It is suitable for use with opcodes that expect an i-rate table number (for example, oscili).

Syntax

ifn = vco2ift(icps, iwave [, inyx])
ifn vco2ift icps, iwave [, inyx]

Initialization

ifn -- the ftable number.

icps -- frequency in Hz. Zero and negative values are allowed. However, if the absolute value exceeds sr/2 (or sr * inyx), the selected table will contain silence.

iwave -- the waveform for which table number is to be selected. Allowed values are:

  • 0: sawtooth
  • 1: 4 * x * (1 - x) (integrated sawtooth)
  • 2: pulse (not normalized)
  • 3: square wave
  • 4: triangle

Additionally, negative iwave values select user defined waveforms (see also vco2init).

inyx (optional, default=0.5) -- bandwidth of the generated waveform, as percentage (0 to 1) of the sample rate. The expected range is 0 to 0.5 (i.e. up to sr/2), other values are limited to the allowed range.

Setting inyx to 0.25 (sr/4), or 0.3333 (sr/3) can produce a “fatter” sound in some cases, although it is more likely to reduce quality.

Examples

This example builds a band-limited table set from a user-defined waveform, then uses vco2ift to select a table for each note. It uses the file vco2ift.csd.

The generated tables start after the source table. The frequency passed to vco2ift also drives oscili, so the selected table has the right bandwidth for playback. Because selection happens only at initialization, use vco2ft with an oscillator that accepts a k-rate table number if the frequency changes during a note.

Example of the vco2ift opcode.
<CsoundSynthesizer>
<CsOptions>
-odac -d
; For a sound file, replace -odac with -o vco2ift.wav -W.
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

; Source waveform: a fundamental and seven successively weaker harmonics.
giSource ftgen 2, 0, 4096, 10, 1, 0.5, 0.333333, 0.25, 0.2, 0.166667, 0.142857, 0.125

; Register it as waveform -2. Start the generated tables AFTER the source
; table, so vco2init does not overwrite it. Each generated table has 4096
; points; 1.4 controls the spacing of the harmonic counts in the table set.
giNextFree vco2init -2, giSource + 1, 1.4, 4096, 4096, giSource
; giNextFree is the first unused table number after the generated set.

instr 1
  iFrequency = p4
  ; Select once at note start, keeping harmonics below sr/2.
  iTable vco2ift iFrequency, -2, 0.5
  printf_i "Frequency: %.0f Hz; selected table: %.0f\n", 1, iFrequency, iTable

  ; Use the SAME frequency for table selection and playback.
  aTone oscili 0.2, iFrequency, iTable
  aEnvelope linseg 0, 0.01, 1, p3 - 0.02, 1, 0.01, 0
  outs aTone * aEnvelope, aTone * aEnvelope
endin
</CsInstruments>
<CsScore>
; Higher notes need tables with fewer harmonics to stay below Nyquist.
i 1 0 2 220
i 1 3 2 1760
i 1 6 2 7040
e
</CsScore>
</CsoundSynthesizer>

The example prints each note's frequency and selected table number. Higher notes select tables with fewer harmonics. The table numbers depend on the generated set and should not be hard-coded.

See the example for the vco2 opcode too.

See Also

Dynamic Spectrum Oscillators

Credits

Author: Istvan Varga

New in version 4.22