harmon2
Prev | Orchestra Opcodes and Operators | Next

## harmon2

harmon2 — Analyze an audio input and generate harmonizing voices in synchrony with formants preserved.

## Description

Generate harmonizing voices with formants preserved.

## Syntax

    ares harmon2 asig, koct, kfrq1, kfrq2, icpsmode, ilowest[, ipolarity]

    ares harmon3 asig, koct, kfrq1, \
        kfrq2, kfrq3, icpsmode, ilowest[, ipolarity]

    ares harmon4 asig, koct, kfrq1, \
        kfrq2, kfrq3, kfrq4, icpsmode, ilowest[, ipolarity]

## Initialization

icpsmode -- interpreting mode for the generating frequency inputs kfrq1, kfrq2, kfrq3 and kfrq4: 0: input values are ratios w.r.t. the cps equivalent of koct. 1: input values are the actual requested frequencies in cps.

ilowest -- lowest value of the koct input for which harmonizing voices will be generated.

ipolarity -- polarity of asig input, 1 = positive glottal pulses, 0 = negative. Default is 1.

## Performance

Harmon2, harmon3 and harmon4 are high-performance harmonizers, able to provide up to four pitch-shifted copies of the input asig with spectral formants preserved. The pitch-shifting algorithm requires an accurate running estimate (koct, in decimal oct units) of the pitched content of asig, normally gained from an independent pitch tracker such as specptrk. The algorithm then isolates the most recent full pulse within asig, and uses this to generate the other voices at their required pulse rates.

If the frequency (or ratio) presented to kfrq1, kfrq2, kfrq3 or kfrq4 is zero, then no signal is generated for that voice. If any of them is non-zero, but the koct input is below the value ilowest, then that voice will output a direct copy of the input asig. As a consequence, the data arriving at the k-rate inputs can variously cause the generated voices to be turned on or off, to pass a direct copy of a non-voiced fricative source, or to harmonize the source according to some constructed algorithm. The transition from one mode to another is cross-faded, giving seemless alternating between voiced (harmonized) and non-voiced fricatives during spoken or sung input.

harmon2, harmon3, harmon4 are especially matched to the output of specptrk. The latter generates pitch data in decimal octave format; it also emits its base value if no pitch is identified (as in fricative noise) and emits zero if the energy falls below a threshold, so that harmon2, harmon3, harmon4 can be set to pass the direct signal in both cases. Of course, any other form of pitch estimation could also be used. Since pitch trackers usually incur a slight delay for accurate estimation (for specptrk the delay is printed by the spectrum unit), it is normal to delay the audio signal by the same amount so that harmon2, harmon3, harmon4 can work from a fully concurrent estimate.

## Examples

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

Example 427. Example of the harmon2 opcode.

    a1,a2      ins                                     ; get mic input
    w1         spectrum  a1, .02, 7, 24, 12, 1, 3      ; and examine it
    koct,kamp  specptrk  w1, 1, 6.5, 9.5, 7.5, 10, 7, .7, 0, 3, 1
    a3         delay     a1, .065                      ; allow for ptrk delay
    a4         harmon2   a3, koct, 1.25, 0.75, 0, 6.9  ; output a fixed 6-4 harmony
               outs      a3, a4                        ; as well as the original

Here is a complete example of the harmon3 opcode. It uses the file harmon3.csd.

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

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

    instr 1

    ilow = p4					;lowest value to harmonize
    aout diskin2 "sing.wav", 1, 0, 1
    koct, kamp pitch aout, .01, 6, 10, 10		;track pitch
    asig harmon3 aout, koct, .9, 1.5, 0.7, 0, ilow
         outs (asig + aout)*.4, (asig + aout)*.4	;mix dry&wet signal

    endin
    </CsInstruments>
    <CsScore>

    i1 0 2.2 8.8
    i1 3 2.2 8.2
    i1 6 2.2 7.0

    e
    </CsScore>
    </CsoundSynthesizer>

## Credits

Author: Barry L. Vercoe
M.I.T., Cambridge, Mass
2006

New in version 5.04

Prev | Up | Next
harmon | Home | hdf5read