adsynt2
Prev | Orchestra Opcodes and Operators | Next

## adsynt2

adsynt2 — Performs additive synthesis with an arbitrary number of partials -not necessarily harmonic- with interpolation.

## Description

Performs additive synthesis with an arbitrary number of partials, not necessarily harmonic. (see adsynt for detailed manual)

## Syntax

    ar adsynt2 kamp, kcps, iwfn, ifreqfn, iampfn, icnt [, iphs]

## Initialization

iwfn -- table containing a waveform, usually a sine. Table values are not interpolated for performance reasons, so larger tables provide better quality.

ifreqfn -- table containing frequency values for each partial. ifreqfn may contain beginning frequency values for each partial, but is usually used for generating parameters at runtime with tablew. Frequencies must be relative to kcps. Size must be at least icnt.

iampfn -- table containing amplitude values for each partial. iampfn may contain beginning amplitude values for each partial, but is usually used for generating parameters at runtime with tablew. Amplitudes must be relative to kamp. Size must be at least icnt.

icnt -- number of partials to be generated

iphs -- initial phase of each oscillator, if iphs = -1, initialization is skipped. If iphs > 1, all phases will be initialized with a random value.

## Performance

kamp -- amplitude of note

kcps -- base frequency of note. Partial frequencies will be relative to kcps.

Frequency and amplitude of each partial is given in the two tables provided. The purpose of this opcode is to have an instrument generate synthesis parameters at k-rate and write them to global parameter tables with the tablew opcode.

adsynt2 is identical to adsynt (by Peter Neubäcker), except it provides linear interpolation for amplitude envelopes of each partial. It is a bit slower than adsynt, but interpolation higly improves sound quality in fast amplitude envelope transients when kr < sr (i.e. when ksmps > 1). No interpolation is provided for pitch envelopes, since in this case sound quality degradation is not so evident even with high values of ksmps. It is not recommended when kr = sr, in this case adsynt is better (since it is faster).

## Examples

Here is an example of the adsynt2 opcode. It uses the file adsynt2.csd. These two instruments perform additive synthesis. The output of each sounds like a Tibetan bowl. The first one is static, as parameters are only generated at init-time. In the second one, parameters are continuously changed.

Example 40. Example of the adsynt2 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
    -odac     ;;;RT audio out
    ;-iadc    ;;;uncomment -iadc if RT audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o adsynt2.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs = 1
    ; Generate a sinewave table.
    giwave ftgen 1, 0, 1024, 10, 1
    ; Generate two empty tables for adsynt2.
    gifrqs ftgen 2, 0, 32, 7, 0, 32, 0
    ; A table for freqency and amp parameters.
    giamps ftgen 3, 0, 32, 7, 0, 32, 0

    ; Generates parameters at init time
    instr 1
      ; Generate 10 voices.
      icnt = 10
      ; Init loop index.
      index = 0

    ; Loop only executed at init time.
    loop:
      ; Define non-harmonic partials.
      ifreq pow index + 1, 1.5
      ; Define amplitudes.
      iamp = 1 / (index+1)
      ; Write to tables.
      tableiw ifreq, index, gifrqs
      ; Used by adsynt2.
      tableiw iamp, index, giamps

      index = index + 1
      ; Do loop/
      if (index < icnt) igoto loop

      asig adsynt2 0.4, 150, giwave, gifrqs, giamps, icnt
      outs asig, asig
    endin

    ; Generates parameters every k-cycle.
    instr 2
      ; Generate 10 voices.
      icnt = 10
      ; Reset loop index.
      kindex = 0

    ; Loop executed every k-cycle.
    loop:
      ; Generate lfo for frequencies.
      kspeed  pow kindex + 1, 1.6
      ; Individual phase for each voice.
      kphas phasorbnk kspeed * 0.7, kindex, icnt
      klfo table kphas, giwave, 1
      ; Arbitrary parameter twiddling...
      kdepth pow 1.4, kindex
      kfreq pow kindex + 1, 1.5
      kfreq = kfreq + klfo*0.006*kdepth

      ; Write freqs to table for adsynt2.
      tablew kfreq, kindex, gifrqs

      ; Generate lfo for amplitudes.
      kspeed  pow kindex + 1, 0.8
      ; Individual phase for each voice.
      kphas phasorbnk kspeed*0.13, kindex, icnt, 2
      klfo table kphas, giwave, 1
      ; Arbitrary parameter twiddling...
      kamp pow 1 / (kindex + 1), 0.4
      kamp = kamp * (0.3+0.35*(klfo+1))

      ; Write amps to table for adsynt2.
      tablew kamp, kindex, giamps

      kindex = kindex + 1
      ; Do loop.
      if (kindex < icnt) kgoto loop

      asig adsynt2 0.25, 150, giwave, gifrqs, giamps, icnt
      outs asig, asig
    endin

    </CsInstruments>
    <CsScore>

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

    </CsScore>
    </CsoundSynthesizer>

## Credits

Written by Gabriel Maldonado.

New in Csound 5 (Previously available only on CsoundAV)

Prev | Up | Next
adsynt | Home | aexprand