foscil
Prev | Orchestra Opcodes and Operators | Next

## foscil

foscil — A basic frequency modulated oscillator.

## Description

A basic frequency modulated oscillator.

## Syntax

    ares foscil xamp, kcps, xcar, xmod, kndx, ifn [, iphs]

## Initialization

ifn -- function table number. Requires a wrap-around guard point.

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

## Performance

xamp -- the amplitude of the output signal.

kcps -- a common denominator, in cycles per second, for the carrier and modulating frequencies.

xcar -- a factor that, when multiplied by the kcps parameter, gives the carrier frequency.

xmod -- a factor that, when multiplied by the kcps parameter, gives the modulating frequency.

kndx -- the modulation index.

foscil is a composite unit that effectively banks two oscil opcodes in the familiar Chowning FM setup, wherein the audio-rate output of one generator is used to modulate the frequency input of another (the “carrier”). Effective carrier frequency = kcps * xcar, and modulating frequency = kcps * xmod. For integral values of xcar and xmod, the perceived fundamental will be the minimum positive value of kcps * (xcar - n * xmod), n = 0,1,2,... The input kndx is the index of modulation (usually time-varying and ranging 0 to 4 or so) which determines the spread of acoustic energy over the partial positions given by n = 0,1,2,.., etc. ifn should point to a stored sine wave. Previous to version 3.50, xcar and xmod could be k-rate only.

The actual formula used for this implementation of FM synthesis is xamp * cos(2π * t * kcps * xcar + kndx * sin(2π * t * kcps * xmod) - π), assuming that the table is a sine wave.

## Examples

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

Example 197. Example of the foscil 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    No messages
    -odac           -iadc     -d     ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o foscil.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Instrument #1 - a basic FM waveform.
    instr 1
      kamp = 10000
      kcps = 440
      kcar = 600
      kmod = 210
      kndx = 2
      ifn = 1

      a1 foscil kamp, kcps, kcar, kmod, kndx, ifn
      out a1
    endin

    </CsInstruments>
    <CsScore>

    ; Table #1, a sine wave.
    f 1 0 16384 10 1

    ; Play Instrument #1 for 2 seconds.
    i 1 0 2
    e

    </CsScore>
    </CsoundSynthesizer>

## Credits

Example written by Kevin Conder.

Prev | Up | Next
follow2 | Home | foscili