1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

al I see are latches in core

Discussion in 'Building With Reaktor' started by gentleclockdivider, Mar 5, 2013.

  1. gentleclockdivider

    gentleclockdivider NI Product Owner

    Messages:
    744
    Been trying to get into core , but why are there so many latches going on ...
    Even for the simple reciprocal 1/x , the division is latched.
    Can someon explain explain ?
     
  2. herw

    herw NI Product Owner

    Messages:
    6,421
    core is very careful with events and secure for users. The macro should only (!) work if there is an event at input. Perhaps there are several cases where this creates a conflict of audio, event and audio event signals and constant initialization at this universal module.
    It is typically for core to make it very careful.
    Try this (no event at initialization from constant 2):
    latch.jpg
    top structure sends 0 because here the memory (latch module) sends nothing at initialization but logic sends 1 because both inputs are 0 at initialization:
    the structure at bottom gets a 1 from constant. 1/0 is defined as „inf” so potentially you will get conflicts at initialization. logic module gets an inf-event (=! 0) so it sends a 0.
    The constant 2 never reaches the 1/x module, it is only for demonstration of initialization process.

    ciao herw
     
    Last edited: Mar 5, 2013
  3. colB

    colB NI Product Owner

    Messages:
    3,969
    In the 1/x example, the latch is used to prevent the initialization event created by the constant '1' from causing an output.
    (IMO, reaktor primary and core would be much improved if initialization behaviour was adjustable in the properties of each built-in module. This would remove the need for a latch in this case.)

    Latches are incredibly useful though!

    Think of a latch is as a nice way to package the concept of a 'variable' that provides a simplified interface that makes code more readable and easier to debug.
    One of the main differences between core and primary is that core gives you direct access to memory slots - the equivalent of variables in traditional programming languages. The raw read and write modules can be very useful, but they are so low level that they tend to quickly complicate the look of your core code. The latch is a nice simple package for some useful variable based functionality that tidies things up.

    As you would expect anything as powerful as an interface to a variable will have many uses, here are a few common ones

    * as a 'value' module.

    * to aid efficiency. look at the 'modulation' macros in the expert macros section. These use a latch to prevent needless calculations. e.g. division is an expensive operation. If you only need an output when there is an input at the numerator, you can latch the denominator (or vice versa). Read the manual for more info about 'modulation' macros.

    * To ensure correct operation!
    It is important that input events that are not part of the audio input stream do not generate events in the audio output stream.
    A simple example here would be something like the 'clip min' macro. Events at the signal input should generate events at the output, however if events at the threshold input were to generate output events, every time you tweaked the threshold with a gui knob, you would get horrible glitches in the sound as each control event also generated an output event in the audio stream. The Latch is used to prevent this problem, it ensures that only signal input events generate output events.

    I hope that helps to explain why there are so many Latches in core code

    Col
     
    Last edited: Mar 5, 2013
    • Like Like x 1