[Csnd] A slider to control the phase shift

Hello to everyone, a newbie here,
With this code I’m trying to control the phase of a sine with a slider, but I’m stuck why it doesn’t update when Csound runs:

;-odac8 -B1024 -b1024

sr = 44100

ksmps = 64

nchnls = 2

0dbfs = 1

giSine ftgen 1, 0, 2^14, 10, 1

instr 1

kAmpLeft init 0.5

kAmpRight init 0.5

kFreqLeft invalue “freqmodLeft”

kFreqRight invalue “freqmodRight”

kPhaseLeft invalue “phaseLeft”

kMix invalue “mixPhase”

print i(kPhaseLeft)

aLeft oscili kAmpLeft, kFreqLeft, 1, i(kPhaseLeft)

aRight oscili kAmpRight, kFreqRight, 1, 0

outs aLeft + aRight * kMix, aLeft * kMix + aRight

endin

i1 0 1000

e

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Hi Ital,
I could be wrong but I think that as oscili will read the phase at i rate this won’t work.

You can instead read directly from the ftable using a table/tablei opcode. Here’s an example, in this case the phase of the right output is being modulated.

-odac ; -o phase_mod.wav

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

giSine = ftgen(1, 0, 2^14, 10, 1)

instr 1
kPhs = line(0, p3, 1) ; phase mod.
aIdx = phasor(220)
aL = tablei:a(aIdx, 1, 1, 0, 1)
aR = tablei:a(aIdx + kPhs, 1, 1, 0, 1)
iAmp = .8
outs aL * iAmp, aR * iAmp
endin

i1 0 16

Best,
Scott

I should have noted that the phasor value will determine the frequency of the oscillator. It can be varied at k or a rate.

This is because oscillator phase can’t be changed by a control signal. Try this

kph invalue “phase”
aph phasor ifreq ; oscillator phase
asig tablei aph + kph, -1, 1, 0, 1 ; oscillator output
asig *= iamp ; amplitude scaling

to replace

asig oscilli iamp, ifreq

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here