pvscale for pitch shift

pvscale
pvscale — pv stream의 frequency components를 scale한다.

Description
pitch shift의 결과가 되는 pv stream의 frequency components를 scale한다. 출력의 amplitudes는 선택적으로 수정되어 formant를 보존하도록 할수 있다.

Syntax
fsig pvscale fsigin, kscal[, ikeepform, igain]]

Performance
fsig — 출력pv stream

fsigin  — 입력pv stream

kscal  — scaling비율.

ikeepform — 입력 시그널을 유지하도록 하기 위해서 — — formants; 0: formants를 유지하지 말 것; 1: formant를 유지할 것(원래의 amplitude를 그대로 가지고 들어옴); 2: 원래의 spectrum envelope를 사용하여 filtering하여 formant를 유지할 것.(기본값 : 0)

igain  — amplitude scaling (기본값: 1).
Pvoc abalysis에서 Hanning window를 사용하면 pitch shift의 질이 향상될 수 있다. Formant의 보존은 강한 formant를 가진 소리(목소리, 악기소리와 같은 것)에서만 성공적으로 나타날 수 있으며, 흥미로운 소리 변화를 줄 수 있다.

Examples
Example 287. Example
asig  in                                 ; get the signal in

fsig  pvsanal   asig, 1024, 256, 1024, 1 ; analyse it
ftps  pvscale   fsig, 1.5, 1, 2          ; transpose it keeping formants
atps  pvsynth  ftps                      ; synthesise it

adp   delayr .1                          ; delay original signal
adel  deltapn 1024                         ; by 1024 samples
      delayw  asig                      
      
       out atps+adel                     ; add tranposed and original
        
위의 보여진 것은 vocal harmoniser이다. Delay는 소리의 time-align에 필요하다. 따라서 analysis-synthesis process 가 analysis input 과synthesis output 사이에 1024 샘플의 Delay를 포함한다.

pvshift

**pvshift이외에 pv stream 관련 opcode들을 다음에도 몇개 더 소개하겠습니다

pvshift

Description
pv stream 의frequency components가 spectrum을 stretching또는 compressing하면서 이동.

Syntax
fsig pvshift fsigin, kshift, klowest[, ikeepform, igain]

Performance
fsig —  pv stream 출력

fsigin — pv stream 입력

kshift — frequency의 이동 량 (Hz, 양수/음수).

klowest — 이동 될frequency의 최하지점

ikeepform — input signal formants를 지속시킴;
0:formants를 지속시키지 않음;
1:원래 amps을 사용하면서 formants 지속
2:원래의 spec envelope을 사용하여0 filtering하면서 formants지속
(기본값: 0).

igain — amplitude scaling (기본값 1).

이 옵코드는 pv stream의 구성요소를 특정 frequency에서부터 일정한 양(Hz)만큼 위아래로 이동시킨다. 이 옵코드는 harmonic spectrum을 inharmonic spectrum으로 전환하는데 사용되면 좋다. ikeepform flag는 가능한 흥미롭고 비범한 spectrum의 변화를 위해 시도되고 formant를 유지하는데 사용할 수 있다.

Examples
Example 288. Example
asig  in                                 ; 이 부분에 시그널을 넣는다.

fsig  pvsanal   asig, 1024, 256, 1024, 1 ; 시그널 분석
ftps  pvshift   fsig, 100, 0             ; 각 성분에 100 Hz를 더함
atps  pvsynth   ftps                     ; 합성
        
입력 시그널에 따라서 음정있는 소리가 inharmonic하게 변경될 수 있다.(벨소리와 같은)
———————————————————————————–

다음은 Matt J. Ingalls이 만든 pvs streams을 사용한 pitch shift예제 입니다.

다음은 채널 하나를 real time으로 사용하였음.
-m

nchnls = 2

opcode pvshift, 0, kkiiiii

; 입력값은 다음과 같다:
; kpitch – pitch shift 의 양[.5=한 옥타브 내림 1=이동없음, 2=옥타브 올림, etc]
; kstretch – spectral shift의 양 [일반적으로; .99-1.01, 1=no stretch]
; inumbins – fft bins의 수 [table의 size]
; iampin – amp data를 포함하고있는 table
; iampout – 수정된 amp data를 쓸 table
; ifreqin – freq data를 포함하는 table
; ifreqout – 수정된freq data 를 쓸 table

kpitch, kstretch, inumbins, iampin, iampout, ifreqin, ifreqout xin

; 반드시 빈 table로 시작해야 한다
iclear ftgen 0, 0, inumbins, 2, 0
tablecopy iampout, iclear
tablecopy ifreqout, iclear

; do-while loop, table들과 이동하는 pitch의 순환(cycling)
kcount = 0
loop:
kindex = kcount/kpitch
if (kindex < inumbins) then
kval table kindex, iampin
kamp table kcount, iampout
tablew kval+kamp, kcount, iampout

kval table kindex, ifreqin
tablew kval*kpitch, kcount, ifreqout
endif

kcount = kcount + 1
kpitch = kpitch * kstretch

if (kcount < inumbins) kgoto loop endop instr 2 ; pvshift opcode 의 test ; 입력을 넣고 pv anal 을 실행
ifftsize = 1024
iNumBins = ifftsize/2 + 1

ainl, ainr ins
fsigl pvsanal ainl, ifftsize, ifftsize/4, ifftsize*2, 0
; [ 또는 pvoc-ex file와 함께 pvsfread를 대신 사용할수있음 ]

; make ftables
iampin ftgen 0,0,iNumBins,2,0
iampout ftgen 0,0,iNumBins,2,0
ifreqin ftgen 0,0,iNumBins,2,0
ifreqout ftgen 0,0,iNumBins,2,0

; gui controls
kfiltl invalue “filtl”
kfilth invalue “filth”
kpitch invalue “pitch”
kstretch invalue “stretch”

; fsig 를 tables로 내보냄
kflag pvsftw fsigl, iampin, ifreqin
if (kflag > 0) then ; frame이 준비되었을때만

; pitch shift/stretch
pvshift kpitch, kstretch, iNumBins, iampin, iampout, ifreqin, ifreqout

; 다시 fsrc로 수정된 data를 읽는다read modified data back to fsrc
pvsftr fsigl, iampout, ifreqout

endif

; 재합성, 출력 – 건드리지 않은 오른쪽 채널과 비교
aoutl pvsynth fsigl

outs aoutl, ainr

endin

fof

fof
fof — Produces sinusoid bursts useful for formant and granular synthesis.

Description
오디오 출력은 사인곡선 파열의 연속으로서 xform에서 스펙트럼의 peak와 함께 xfund frequency에서 초기화된다. 25 Hz 이상의xfund에서 이런 파열들은 k-input 파라메터에 의해 결정되는 스펙트럼의 특성과 함께 말하는 것과 같은 formant를 생성한다.  더 낮은 기본음에서 이generator는 granular synthesis 의 특별한 형태를 보여준다.

Syntax
ares fof xamp, xfund, xform, koct, kband, kris, kdur, kdec, iolaps, ifna, ifnb, itotdur [, iphs] [, ifmode] [, iskip]

Initialization
iolaps — 파열 overlap되는 data를 가지고 있을, 미리 할당된 공간의 수. Overlaps 는 frequency에 따라 결정되며, 그 공간은 xfund * kdur의 최대값에 달려있다. 계산값이 주어지지 않으면 과대평가 될수 있다. iolaps — 당 메모리의 50 bytes 이하로 설정해야한다.

ifna, ifnb — 2개 저장 f-table 번호. 첫번째는 sine table-sineburst synthesis(최소 4096이 좋음). 두번째 값은 Sineburst 앞, 뒤의 rise, decay 의 모양에 사용될 곡선; 주로 선형에는 (GEN07)이, s자 모양은(GEN19).

itotdur — fof에 할당될 전체시간. 주로 p3로 설정. itotdur 남아있는 totdur 이내에서 kdur가 끝나지 않는다면, 새로운sineburst는 생성되지 않는다.

iphs (optional, default=0) – 기본배음fundamental의 초기 phase, 한 주기(0~1)의 부분

ifmode (optional, default=0) — formant frequency mode. 0이면 각각의 sineburst 는 계속 처음에 xform 값이 지속. 0이 아니면 각각은 계속해서xform 에 영향을 받음.

iskip (optional, default=0) – 0이 아니면 초기화를 skip (legato사용을 허용).

Performance
xamp — 각각 싸인 파열의peak amplitude, envelope의rise 패턴에서 가장 끝부분에 있을 꼭대기 값. 이 rise는 큰 bandwidth에 주어진 값을 초과하게 될 수 있다. (파열들이 overlapping될 때에도)(역주-그림을 그려 표현하면 좋은데, amp값이 bandwidth에 따라서 겹쳐지는 부분이 생기게 되면 peak을 넘어가는 일이 생길 수 있습니다. 파열들이 서로 겹쳐지기 때문이에요. 따라서 overlapping의 양과 bandwidth의 값을 적절하게 주어야 합니다. 아니면 밀도가 지나치게 높아져서 소리가 찢어지게 되지요.)

xfund — 새로운 싸인 파열을 만드는 impulse의 fundamental frequency (Hertz

xform — formant frequency 각 xfund impulse 에 의해서 도입되는 싸인 파열의 freq. 이frequency는 각각 파열에 고정될수도, 계속 변화할수도 있다. (ifmode참고).
koct — octaviation index, (주로 0의 값 사용). 0보다 큰 값은 홀수번호의 싸인 파열이 약화되면서 xfund frequency를 낮춘다. 전체 숫자는 full octaves

kband — formant bandwidth (-6dB에서), Hz단위. 이 bandwidth는 싸인 파열 전체에 적용될 지수곡선의 decay비율을 결정한다.(아래에 있는 enveloping이 적용되기 이전에)
kris, kdur, kdec — 파열의 rise, 전체duration, decay times (초단위).이 값은 각 파열에 envelope되는 duration에 사용. linen generator와 비슷하지만rise와 decay 모양들은 ifnb input로부터 적용된다. kris 는 반대로 도입되는 formant 영역의 skirtwidth (-40 dB에서)를 결정한다. kdur 는 sineburst overlaps의 밀도에 영향을 끼치므로 이는 직접적으로 계산속도에도 영향을 끼친다. vocal소리를 만드는데 전형적인 값 .003,.02,.007.
Csound의 fof generator는 막연하게는Michael Clarke의 C-coding ( IRCAM’s CHANT program (Xavier Rodet et al.))을 기반으로 한다. 각각 fof는 하나의 formant를 생성하고, 4개 이상의 출력은 풍성한 vocal소리를 만들어 낸다. fof synthesis 는 granular synthesis중에서 특별한 하나의 형태이며 이것은 vocal모방과 granulay texture간의 변형을 가능하게 한다. 계산속도는 kdur, xfund, 와overlaps의 밀도에 따라 결정된다.

Example 146. Example of the fof opcode.
/* fof.orc */
/* Adapted from 1401.orc by Michael Clarke */
; Initialize the global variables.
sr = 44100
kr = 4410
ksmps = 10
nchnls = 1

; Instrument #1.
instr 1
  ; Combine five formants together to create
  ; an alto-“a” sound.

  ; Values common to all of the formants.
  kfund init 261.659
  koct init 0
  kris init 0.003
  kdur init 0.02
  kdec init 0.007
  iolaps = 14850
  ifna = 1
  ifnb = 2
  itotdur = p3

  ; First formant.
  k1amp = ampdb(0)
  k1form init 800
  k1band init 80

  ; Second formant.
  k2amp = ampdb(-4)
  k2form init 1150
  k2band init 90

  ; Third formant.
  k3amp = ampdb(-20)
  k3form init 2800
  k3band init 120

  ; Fourth formant.
  k4amp = ampdb(-36)
  k4form init 3500
  k4band init 130

  ; Fifth formant.
  k5amp = ampdb(-60)
  k5form init 4950
  k5band init 140

  a1 fof k1amp, kfund, k1form, koct, k1band, kris,
         kdur, kdec, iolaps, ifna, ifnb, itotdur
  a2 fof k2amp, kfund, k2form, koct, k2band, kris,
         kdur, kdec, iolaps, ifna, ifnb, itotdur
  a3 fof k3amp, kfund, k3form, koct, k3band, kris,
         kdur, kdec, iolaps, ifna, ifnb, itotdur
  a4 fof k4amp, kfund, k4form, koct, k4band, kris,
         kdur, kdec, iolaps, ifna, ifnb, itotdur
  a5 fof k5amp, kfund, k5form, koct, k5band, kris,
         kdur, kdec, iolaps, ifna, ifnb, itotdur

  ; Combine all of the formants together.
  out (a1+a2+a3+a4+a5) * 16384
endin
/* fof.orc */

        
/* fof.sco */
/* Adapted from 1401.sco by Michael Clarke */
; Table #1, a sine wave.
f 1 0 4096 10 1
; Table #2.
f 2 0 1024 19 0.5 0.5 270 0.5

; Play Instrument #1 for three seconds.
i 1 0 3
e
/* fof.sco */