Csound Csound-dev Csound-tekno Search About

resetting global audio variable

Date2006-01-04 22:20
FromAtte André Jensen
Subjectresetting global audio variable
Hi

I have a strange problem that I had before, I even have a solution. 
Still I'd like to get clever heads opinion on the problem and my solution.

I have the following instrument. It's a global fx that does delay with 
delay time and feedback set from another instrument. I use macros for 
the global vars to not have to hardcode it into the instrument, in case 
you wonder why..

The problem is the final two lines, where the global arate vars are 
reset. They should be reset to 0, but this will make csound go crazy 
after a minute or so, using up 100% of cpu cycles. I wonder

1) why setting to zero doesn't work while a small number does?
2) if it's a bug in csound (behaviour was the same in 4.23) or in my 
handling of global vars?
3) how small the number should be not to be heard or interfer with audio 
(I guess it's actually introducing a small dc offset, right?)?
4) if there's a better solution to the problem than mine?

         instr +fake_ping_pong_delay_tap
adelaytime      =               $FX_TAP_DELAY_TIME
kfeedback       =               $FX_TAP_DELAY_FEEDBACK

adelayl         flanger         $FX_TAP_DELAY_L * kfeedback, adelaytime, 
kfeedback, 1
adelayr         flanger         $FX_TAP_DELAY_R * kfeedback, adelaytime, 
kfeedback, 1

                 outs            adelayl,adelayr
$FX_TAP_DELAY_L =               .001
$FX_TAP_DELAY_R =               .001
         endin

The macros are defined like this:

#define FX_TAP_DELAY_TIME #gk_fx_tap_delay_time#
#define FX_TAP_DELAY_FEEDBACK #gk_fx_tap_delay_feedback#
#define FX_TAP_DELAY_L  #ga_fx_tap_delay_l#
#define FX_TAP_DELAY_R  #ga_fx_tap_delay_r#
$FX_TAP_DELAY_TIME      init    .55
$FX_TAP_DELAY_FEEDBACK  init    .3
$FX_TAP_DELAY_L         init    0
$FX_TAP_DELAY_R         init    0

And I send audio to the fx by another macro:

#define GLOBAL_FX_TAP_DELAY(IN_L'IN_R'WET) #
$FX_TAP_DELAY_L =               $FX_TAP_DELAY_L + $IN_L * $WET
$FX_TAP_DELAY_R =               $FX_TAP_DELAY_R + $IN_R * $WET
$IN_L           =               $IN_L * (1 - $WET)
$IN_R           =               $IN_R * (1 - $WET)
#

Which is used like this in regular instruments:

$GLOBAL_FX_TAP_DELAY(aoutl'aoutr'i_delay)

-- 
peace, love & harmony
Atte

http://www.atte.dk

Date2006-01-05 10:56
FromIstvan Varga
SubjectRe: resetting global audio variable
AttachmentsNone  

Date2006-01-06 00:42
FromAtte André Jensen
SubjectRe: resetting global audio variable
Istvan Varga wrote:

> The slowdown is caused by denormals (very small non-zero numbers; for
> example, 1e-40 is a denormal with single precision) to which most
> feedback loops (reverbs, IIR filters, etc.) decay after a sufficiently
> long passage of zero input. The CPU performs operations on denormals
> slower by several orders of magnitude than on "normal" values.

This might explain a similar behaviour I noticed working with om, which 
uses LADSPA plugins for processing. Some plugins would eat almost all 
cpu if unconnected, some would go crazy at times when no sound was send 
to them...

> As a workaround, you can prevent the input signals from becoming zero
> for a long time by using the denorm opcode (this is in fact similar to
> resetting to 0.001 instead of 0):

Does that mean that my solution is as good as the denorm/clear solution?

-- 
peace, love & harmony
Atte

http://www.atte.dk