Csound Csound-dev Csound-tekno Search About

[Csnd] Why does this csd only echo once?

Date2012-03-10 04:54
FromForrest Cahoon
Subject[Csnd] Why does this csd only echo once?
Hey Csounders!  I'm being an idiot again, I can't figure out what's
wrong with my csd.

I'm using zak audio channels to implement an echo, and I can't figure
out why it's only echoing once.

instr 101 is the echo. It reads the source input from zak audio
channel 0, then writes it right out to zak audio channel 1, with
mixing.  Then the delay also writes to zak audio channel 1 with
mixing.  Then instr 999 writes channel 1 to audio out.

I'm only getting one echo, but if I'm writing my echoes back, with
mixing, to the same channel, shouldn't I also get an echo of the echo
(and an echo of the echo of the echo and ... ) ?

As usual, any help would be greatly appreciated.

-- Forrest




sr=44100
ksmps=1
nchnls=1

zakinit 1, 1

instr 1
; sound source, writes to zak channel 0
iDur = p3
iAmp = ampdbfs(p4)
iFreq = p5

aOut pluck iAmp, iFreq, iFreq, 0, 1
zawm aOut, 0
endin

instr 101
; echo reads from zak channel 0
; writes mixed source and echo to zak channel 1
aChan0 zar 0
zawm aChan0, 1
aChan1 zar 1
aEcho delay aChan1, 1
zawm aEcho * 0.9, 1
zacl 0, 0
endin

instr 999
; writes zak channel 1 to output
aChan1 zar 1
out aChan1
zacl 1, 1
endin




i101 0  -1
i999 0  -1

i1  0  .5   -1   256

e 10 ; time for echoes




Date2012-03-10 05:34
FromSteven Yi
SubjectRe: [Csnd] Why does this csd only echo once?
Hi Forrest,

The problem is that you're clearing out the channel in instr 999. I
modified instr 101 to use zaw when writing to zak 1, and commented out
the clear in instr 999:

instr 101
; echo reads from zak channel 0
; writes mixed source and echo to zak channel 1
aChan0 zar 0
zawm aChan0, 1
aChan1 zar 1
aEcho delay aChan1, 1
zaw aEcho * 0.9, 1
zacl 0, 0
endin

instr 999
; writes zak channel 1 to output
aChan1 zar 1
out aChan1
;zacl 1, 1
endin

Using zaw ensures you're not going to get an accumulated signal.  On
the other hand, if you're planning to mix other things into zak 1, you
can do all of the delay processing within instr 101, rather than using
the zak channel to store the delayed signal, and reinstate zacl in
instr 999:

instr 101
; echo reads from zak channel 0
; writes mixed source and echo to zak channel 1
aChan0 zar 0
adelay init 0

aEcho delay aChan0 + adelay, 1
adelay = aEcho * 0.9
zawm adelay, 1
zacl 0, 0
endin

instr 999
; writes zak channel 1 to output
aChan1 zar 1
out aChan1
zacl 1, 1
endin


So either of those should work for you.

Hope that helps!
steven



On Sat, Mar 10, 2012 at 4:54 AM, Forrest Cahoon
 wrote:
> Hey Csounders!  I'm being an idiot again, I can't figure out what's
> wrong with my csd.
>
> I'm using zak audio channels to implement an echo, and I can't figure
> out why it's only echoing once.
>
> instr 101 is the echo. It reads the source input from zak audio
> channel 0, then writes it right out to zak audio channel 1, with
> mixing.  Then the delay also writes to zak audio channel 1 with
> mixing.  Then instr 999 writes channel 1 to audio out.
>
> I'm only getting one echo, but if I'm writing my echoes back, with
> mixing, to the same channel, shouldn't I also get an echo of the echo
> (and an echo of the echo of the echo and ... ) ?
>
> As usual, any help would be greatly appreciated.
>
> -- Forrest
>
> 
>
> 
> sr=44100
> ksmps=1
> nchnls=1
>
> zakinit 1, 1
>
> instr 1
> ; sound source, writes to zak channel 0
> iDur = p3
> iAmp = ampdbfs(p4)
> iFreq = p5
>
> aOut pluck iAmp, iFreq, iFreq, 0, 1
> zawm aOut, 0
> endin
>
> instr 101
> ; echo reads from zak channel 0
> ; writes mixed source and echo to zak channel 1
> aChan0 zar 0
> zawm aChan0, 1
> aChan1 zar 1
> aEcho delay aChan1, 1
> zawm aEcho * 0.9, 1
> zacl 0, 0
> endin
>
> instr 999
> ; writes zak channel 1 to output
> aChan1 zar 1
> out aChan1
> zacl 1, 1
> endin
>
> 
>
> 
> i101 0  -1
> i999 0  -1
>
> i1  0  .5   -1   256
>
> e 10 ; time for echoes
> 
>
> 
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>


Date2012-03-10 19:10
FromForrest Cahoon
SubjectRe: [Csnd] Why does this csd only echo once?
Thanks as always for your elucidation, Steven. Both your examples work for me.


So, if I understand correctly, a sure-fire recipe for using zak audio
channels to tie together effects chains is this:

Each effect reads from one zak audio channel and writes to another.

Inside each effect:

Read from the input channel.

If this is the last effect which reads from this channel (i.e. the
highest numbered one if all effects are always-on instruments started
at time 0), clear the input channel.

Perform all mixing of signals for the effect using local a-rate
variables, DO NOT try to mix signals in the zak channel.

At the end of the effect when you have an a-rate variable containing
the final output, write that with mixing to the output zak audio
channel.



I'm pretty sure I can follow this and get some complex effects chains
working.  I'm still confused, though, about why mixing within the
effect using local a-rate variables and only writing the final result
out to the output zak channel is different from using zawm to the same
channel several times within the effect, trying to mix the different
components of the effect within the channel. Can anyone explain this
to me?

-- Forrest

Date2012-03-10 20:23
FromSteven Yi
SubjectRe: [Csnd] Why does this csd only echo once?
Hi Forrest,

Things tend to be clearer to me when only reading and writing out to
channels (whether it's zak, chnget/chnset, global vars, etc.) when
necessary.  To me, by only reading once and writing once there, it's
more encapsulated.

For mixer designs though, I did write an article for the Csound Journal:

http://www.csounds.com/journal/issue13/emulatingMidiBasedStudios.html

It uses UDO's as effects units and uses a single mixer instrument
where all of the mixing and effects processing is done.  I've found
this method to be very customizable and solves problems about reusing
multiple instances of a single effect anywhere in the signal chain.
If you use instruments, there's a lot of complications that can
happen, especially with processing order, and I've found this general
design to work very.  (I use this for effects and mixing in blue,
though I use global vars for routing signals). The example in that
article also shows how to do automation curves together with your
effects/mixer.

Let me know if you have any further questions!

steven

On Sat, Mar 10, 2012 at 7:10 PM, Forrest Cahoon
 wrote:
> Thanks as always for your elucidation, Steven. Both your examples work for me.
>
>
> So, if I understand correctly, a sure-fire recipe for using zak audio
> channels to tie together effects chains is this:
>
> Each effect reads from one zak audio channel and writes to another.
>
> Inside each effect:
>
> Read from the input channel.
>
> If this is the last effect which reads from this channel (i.e. the
> highest numbered one if all effects are always-on instruments started
> at time 0), clear the input channel.
>
> Perform all mixing of signals for the effect using local a-rate
> variables, DO NOT try to mix signals in the zak channel.
>
> At the end of the effect when you have an a-rate variable containing
> the final output, write that with mixing to the output zak audio
> channel.
>
>
>
> I'm pretty sure I can follow this and get some complex effects chains
> working.  I'm still confused, though, about why mixing within the
> effect using local a-rate variables and only writing the final result
> out to the output zak channel is different from using zawm to the same
> channel several times within the effect, trying to mix the different
> components of the effect within the channel. Can anyone explain this
> to me?
>
> -- Forrest
>
>
> Send bugs reports to the Sourceforge bug tracker
>            https://sourceforge.net/tracker/?group_id=81968&atid=564599
> Discussions of bugs and features can be posted here
> To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
>