Global var

Hello,

I’d like to send the output of an oscillator set in instr 1 to the input of a filter set in instr 2, using a global variable (orc. 1). It works but I hear some sidebands that don’t show up in orc. 2, where the oscillator goes in the input of the filter in the same instrument, without the use of any global variable.
So I did something wrong in orc. 1, but what?

;orc. 1
sr = 44100

ksmps = 32

nchnls = 2

0dbfs = 1

gasig init 0

instr 1

aout vco .3, 220, 1

gasig = gasig + aout

endin

instr 2

kfco line 200, p3, 2000 ; filter-cutoff frequency from .2 to 2 KHz

krez init p4

asig moogvcf gasig, kfco, krez

outs asig, asig

endin

gasig = 0

;a sine wave

f 1 0 16384 10 1

i1 0 10

i2 0 3 .1

i2 + 3 .7

i2 + 3 .95

e

================================

;orc. 2

sr = 44100

ksmps = 32

nchnls = 2

0dbfs = 1

instr 1

; iscale does not need to be set here because already 0dbfs = 1

aout vco .3, 220, 1 ; Use a nice sawtooth waveform.

kfco line 200, p3, 2000 ; filter-cutoff frequency from .2 to 2 KHz

krez init p4

asig moogvcf aout, kfco, krez

outs asig, asig

endin

;a sine wave

f 1 0 16384 10 1

i 1 0 3 .1

i 1 + 3 .7

i 1 + 3 .95

e

i guess it is because you use the statement
gasig = 0
outside any instrument. but it needs to be inside an instrument.

i think you have two options:

  1. you set the statement as last line in instr 2.
  2. actually you can simple set
    gasig vco .3, 220, 1
    because you have no addition to the global audio. then you can remove
    these lines:
    gasig init 0
    gasig = gasig + aout
    gasig = 0

best -
joachim

Thank you Joachim!