Csound Csound-dev Csound-tekno Search About

[Csnd] realtime grain question...

Date2009-08-07 12:55
FromRory Walsh
Subject[Csnd] realtime grain question...
I've altered the grain example in the Csound ref. manual so that it
works in realtime. Everything works fine but I can't figure out why I
have to alter the volume of the incoming signal so radically in order
to prevent really bad amplitude distortion. I've been racking my brain
to figure it out but nothing's jumping out at me. I'm reducing the
incoming signal by a factor of 100 just because trial and error
suggests this is the best reduction value. Any ideas? The other thing
I can't figure out if why setting kamp to something really small like
0.00001 makes very little difference to the output level? Finally, why
does changing ksmps to 1 cause a completely different output? Here's
the code:



-odevaudio -b10 -idevaudio -g


sr      =     44100
kr      =     4410
ksmps   =     10
nchnls  =     1

instr 1

/* write incoming signal to table */
ain  inch  1
awp  phasor sr/ftlen(1)
awin tablei awp, 2, 1
     /* if I don't reduce the amplitude of the signal here I get crazy
distortion */
     tablew (ain*awin)/100, awp, 1, 1

/* let the granulation begin! */
insnd = 1
ibasfrq = 44100 / ftlen(insnd)
kamp   = 1
kpitch = 44100
kdens  = 10;
kaoff  = 100;
kpoff  = 0.8;
kgdur  = 0.8;
imaxgdur =  .5
ar  grain kamp, kpitch, kdens, kaoff, kpoff, kgdur, insnd, 3, imaxgdur, 0.0

outs ar
endin



f1 0 131072 7 0 131072 0
f2 0 131072 7 0 36 1 131000 1 36 0
f3 0 1024  -20  1
i1 0 100



regards,
Rory.