Skip to content

pvscross

Performs cross-synthesis between two source fsigs.

Syntax

fsig = pvscross(fsrc, fdest, kamp1, kamp2)
fsig pvscross fsrc, fdest, kamp1, kamp2

Performance

For each bin, the output adds the amplitude from fsrc scaled by abs(kamp1) to the amplitude from fdest scaled by abs(kamp2). It keeps the frequency from fsrc. For amplitude+phase input, it keeps the phase from fsrc instead. Unlike pvcross, it reads f-signals and does not preserve the spectral envelope.

kamp1 and kamp2 use their absolute values: negative gains act like positive gains. Values above 1 amplify the input; gains are not clipped to 1. Use values between 0 and 1 for a crossfade.

Both inputs must use amplitude+frequency (format 0) or amplitude+phase (format 1), with matching FFT size, hop size, window size, window type, format and sliding mode. Complex frames and partial tracks are not supported. Use pvsanal to generate inputs from real-time audio.

For ordinary analysis frames, the output updates when fsrc supplies a new frame, using the latest frame from fdest. Sliding signals process each active sample in the control block. Samples before the note starts or after it ends have zero output.

⚠ Warning

It is unsafe to use the same f-variable for both input and output of pvs opcodes. Using the same one might lead to undefined behavior on some opcodes. Use a different one on the left and right sides of the opcode.

Examples

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

Example of the pvscross opcode.
<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 pvscross.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; by Menno Knevel 2021, after an example by joachim heintz 2009

instr 1
  ipermut  = p4                                                  ; 1 = change order of soundfiles
  ifftsize = 1024
  ioverlap = ifftsize / 4
  iwinsize = ifftsize
  iwinshape = 1                                                  ; von-Hann window
  Sfile1 = "oboe.aiff"
  Sfile2 = "finneganswake1.flac"
  ain1   = diskin2:a(Sfile1, .5, 0, 1)
  ain2   = diskin2:a(Sfile2, 1, 0, 1)                             ; the wave plays 4 x faster and higher
  fftin1 = pvsanal(ain1, ifftsize, ioverlap, iwinsize, iwinshape) ; fft-analysis of file 1
  fftin2 = pvsanal(ain2, ifftsize, ioverlap, iwinsize, iwinshape) ; fft-analysis of file 2
  ktrans = linseg(0, p3*.2, 0, p3*.6, p5, p3*.2, p5)              ; transitions
  if ipermut == 1 then
    fcross = pvscross(fftin2, fftin1, ktrans, 1 - ktrans)
  else
    fcross = pvscross(fftin1, fftin2, ktrans, 1 - ktrans)
  endif
  aout = pvsynth(fcross)
  outs(aout, aout)
endin

</CsInstruments>
<CsScore>
; use only first portion of sample (=p5)
i 1 0 12.7   0    0     ; frequencies from the oboe, no transition
i 1 14 12.7  1    0     ; frequencies from the voice, no transition
; transition over total sample (=p5)
i 1 28 12.7  0    1    ; frequencies from the oboe, amplitude transition from voice to oboe
i 1 42 12.7  1    1    ; frequencies from the voice, amplitude transition from oboe to voice
e
</CsScore>
</CsoundSynthesizer>

See also

Tools for Real-time Spectral Processing (pvs opcodes)

Credits

Author: Richard Dobson
August 2001

November 2003. Thanks to Kanata Motohashi, fixed the link to the pvcross opcode.

New in version 4.13