Auto Mute plugin?

Discussion in 'Effects and the DSP' started by Maddogg6, Feb 21, 2007.

  1. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    Sorry Maddogg6, I do not know where my brain was. I did not even think about zero-crossings, etc.

    In any case, I hacked something together that might work a little better. I threw it togther quickly, so it is not optimized (at all) or anything, but I think it might work ok. It may not be the best implemention (it is 4:30 am), but maybe you can make use of it.

    Here is the code (hopefully it isn't t bad... I am starting to go cross-eyed):
    Code:
    input FXBInL, FXBInR, PLInL;
    input PLInR;
    output OutL, OutR;
    control FXB=1, PL=1;
    static abs=0, av=0, v1=0;
    static v2=0;
    temp t1, t2
    
    
    ; code
    interp v1, v1, 0.00001, 1;
    macs t1, 0, FXBInL, v1;
    macs t2, 0, FXBInR, v1;
    macs t1, 0, t1, FXB;
    macs t2, 0, t2, FXB;
    tstneg abs, t1, t1, 0;
    interp av, av, 0.0007, abs;
    skip ccr, ccr, 0x100, 7;
    interp v2, v2, 0.00001, 1;
    macs t1, 0, PLInL, v2;
    macs t2, 0, PLInR, v2;
    macs t1, 0, t1, PL;
    macs t2, 0, t2, PL;
    macs v1, 0, 0, 0;      
    skip ccr, ccr, 0x7fffffff, 1
    macs v2, 0, 0, 0;
    macs OutL, 0, t1, 1; 
    macs OutR, 0, t2, 1;  
    
    It currently only uses FXBInL for testing.

    In any case, it is still all Dane code, and what Lex is talking about most likley could be done all in Dane as well, without using too many resources.
     
    Last edited: Feb 21, 2007
  2. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    Oh - Hey Russ - you need not bothered - I have enough hehe...

    But I do appreciate - I will give it a go tomarrow (and maybe learn about the A/D gating too--- maybe not ??)

    Anyways -- thanks 1,000,000,004.4674 times. :D

    Get some sleep already....
     
  3. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    @Russ: thank you again - its working very well..

    I do have a question (or 2 or 3 or.... ):

    I see the static was used to 'sorta' do what I was thinking with the iTram delay - I get that, or understand why thats a better idea.

    But I was wondering if you could to write up psudo code for the logic you used here.? or maybe comment the code possibly...
    I think I could learn more that way... maybe not ??

    if its too much hassle, I completely understand if you think it will just go over my 'low flying' head. :D

    Again - thank you so much...

    edit: it seems to output a mono mix of FXBIns...
    (I sent a wide stereo signal into both, and enabled/disabled FXBIns and can hear stereo - mono... )
    I would like to understand why and if possible how to fix it myself - but I dont want to be that hemeroid that wont go away either...
     
    Last edited: Feb 21, 2007
  4. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    The mono problem was due to a typo (I corrected it) on the 5th instruction, that was causing it to only play the left side of that input.

    I will add an explanation as soon as I have a chance.
     
  5. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    The main thing to understand here is the 'interp' instruction. It basically does linear interpolation between 2 values. What this means, is that the result goes from the first value (the A parameter) toward the second value (the Y parameter) at a rate determined by the value of the X parameter.

    With 2 static (starting) values (where the first value is being updated by the result), it basically works like a ramp.
    With 2 dynamic values (where the first value is being updated by the result), it basically works like an averager/smoother.

    The code basically takes the absolute value of the input (currently only the left side of the input that we want to test), and uses the (2nd) interp instruction to smooth it out a bit, to try and get an average value. Additionally, when the input stops (becomes 0), the two values become static and then it works like a ramp (down), delaying the point where it reaches 0, which helps to keep it from tiggerring on short silences, etc.

    The other 2 interp instructions (1st and last) are used as a volume ramp (up). When either input is sent to the output, it sets the other input's starting ramp value to 0, so when it switches inputs, it basically climbs from 0 toward 1.

    Does that make sense?

    Here is the code with comments added, see if you can figure it out from the comments, and then ask about any part that you do not understand.
    Code:
    interp v1, v1, 0.00001, 1;  
    ; volume ramp for FXB inputs
    macs t1, 0, FXBInL, v1;
    ; t1 = input * value of volume ramp
    macs t2, 0, FXBInR, v1; 
    ; t2 = input * value of volume ramp
    macs t1, 0, t1, FXB;
    ; t1 = t1 * value of volume slider
    macs t2, 0, t2, FXB;
    ; t2 = t2 * value of volume slider
    tstneg abs, t1, t1, 0;
    ; abs = absolute value of t1
    interp av, av, 0.0007, abs;
    ; av is kind of the average level of FXBInL
    skip ccr, ccr, 0x100, 7; 
    ; skip 7 instructions if result of above != 0
    interp v2, v2, 0.00001, 1;
    ; volume ramp for PL inputs
    macs t1, 0, PLInL, v2;
    ; t1 = input * value of volume ramp
    macs t2, 0, PLInR, v2;
    ; t2 = input * value of volume ramp
    macs t1, 0, t1, PL;
    ; t1 = t1 * value of volume slider
    macs t2, 0, t2, PL;
    ; t2 = t2 * value of volume slider
    macs v1, 0, 0, 0;      
    ; set starting value of volume ramp for FXB inputs to 0
    skip ccr, ccr, 0x7fffffff, 1;
    ; always skip 1 instruction
    macs v2, 0, 0, 0;
    ; set starting value of volume ramp for PL inputs to 0
    macs OutL, 0, t1, 1; 
    ; OutL = t1
    macs OutR, 0, t2, 1;  
    ; OutR = t2
    
    <edit>
    BTW: 'abs' does not need to be static register (can be a temp).
    </edit>
     
    Last edited: Feb 21, 2007
  6. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    BTW: You can use the following in the MS PowerToy Calculator to simulate the interp instruction:

    interp(a, x, y) = (1-x)*a+x*y

    i.e.
    interp(0, .5, 1) = 0.5
    interp(answer, .5, 1) = 0.75
    interp(answer, .5, 1) = 0.875
    interp(answer, .5, 1) = 0.9375
    interp(answer, .5, 1) = 0.96875
    ...

    So you can see, with 0.5 as the interpolation factor, and Y being a constant value (1 in this case), and the A parameter (starting at 0) being continually updated by the result, the result is half the distance between A and Y each time.
     
    Last edited: Feb 22, 2007
  7. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    Dont let the fact this was your first sentance make you think its all I read btw..

    But to make sure Im crystal clear on this instruction:
    What 2 points - Y and A ? is what it looks like..
    At a step size per sample cycle of 'X'.

    How far off am I on this... ??

    edit: Doh - I spent an hour reading about that instruction while I was composing this...

    That sentence there should be in the Dane guide. That makes it much clearer - thank you.
     
  8. Max M.

    Max M. h/h member-shmember

    Joined:
    Dec 7, 2002
    Messages:
    2,690
    Likes Received:
    9
    Trophy Points:
    63

    >That sentence there should be in the Dane guide.

    The problem is that the "integrator" algorithm (what "interp av, av, 0.0007, abs" is) and the 'interp' instruction are not the same things (though the second is the best way to implement the first). The first is more to be a subject to some kind of "DSP Algorithms Guide". That's the hardest point in writing all those things like "guide to ..." - it is not always possible to find a good balance between "DSP Algorithms Guide with some examples of kX/dane programming" and 'kX/Dane Programming Guide with some examples of dsp algoritms " - you know... got more on first - lost something on second... got something on second - lost something on first... tried to fully cover both - failed to achive anything :)
     
  9. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    @Maddogg6,

    Something else that you might find useful (regarding the interp instruction) for Dane only plugins, is it's ability to rescale values (this is explained somewhat in the AS10k1 Online Manual).

    i.e.
    Using Dane only, you can change a slider's range from 0 to 1, to something else.

    i.e.
    Change the range to 0 to 0.25
    interp R, 0, slider_value, 0.25;

    Change the range to 0.25 to 1
    interp R, 0.25, slider_value, 1;

    Change the range to 0.25 to 0.50
    interp R, 0.25, slider_value, 0.50;

    ...etc.

    The A and Y parameters define the new range, and the X parameter is the actual slider value.

    (Note: the actual top value is 0x1 (1 bit (LSB)) less than the value you specify, due to the fact that fractional 1 is 0x1 less than 1, but hopefully you get the idea).

    Again using the PowerToy Calculator you can get an idea of what it is doing:
    (mapping a slider to a new range of 0 to 0.25)

    With an actual slider value of 0 (min value):
    interp(0, 0, 0.25) = 0 (new min value)

    With an actual slider value of 1 (max value):
    interp(0, 1, 0.25) = 0.25 (new max value)

    With an actual slider value of 0.5 (middle value):
    interp(0, 0.5, 0.25) = 0.125 (new middle value)
     
  10. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    Ahh yes - this is a spectacular reference too. Very good info.
     
  11. Lex Nahumury

    Lex Nahumury DH Senior Member

    Joined:
    Jan 5, 2003
    Messages:
    1,944
    Likes Received:
    6
    Trophy Points:
    0
    >>Ahh yes - this is a spectacular reference too. Very good info.

    I would like to point out that this is somewhat incomplete info/advice.

    Using interp for things like scaling slider values is a waste of dsp resources.
    Such non 'real time' stuff can and should be handled by host.

    This is one of the (many) downsides of writing "dane only" plugins.
     
  12. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    Yes, of course, this is true, but for some people, it may be there only choice.
    Also, it was meant to serve as another example (that I have not seen previously documented) that interp can be used for more than one purpose (to go along with what Max had said).

    In any case, I understand what you are saying, and agree with you.

    p.s.
    I did notice that you put "dane only" in quotes, and yes, I do realize that if it uses a slider, that it is not truly "dane only" (if that is what you were getting at). :D

    By "dane only", I only meant, without the user having to do any C++ programming (which is what Maddogg6 wanted).
     
  13. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    While I have no doubts this is true - but its seem like just 1 instruction and a couple registers in Russ' examples (or is that 'mis-leading' ??). Sure, I understand saving ANY resources is a 'good' thing. Learning how to program the DSP is even 'better' IMO... And, thankfully (or unfortunately..??) I have more DSP resources than patients for MS VC++... :D
     
  14. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    The examples I posted only use one instruction and one GPR (in addition to the slider register, which you would be using normally anyway), however, depending on the values used to re-define the range, it could (likely would) use two additional GPRs (the values I used in the examples are hardware constants, so they do not use a GPR).
     
  15. Lex Nahumury

    Lex Nahumury DH Senior Member

    Joined:
    Jan 5, 2003
    Messages:
    1,944
    Likes Received:
    6
    Trophy Points:
    0
    Sure Russ I know you know, but just as it appears to be usefull
    to tell one can use interp that way, it's equaly important to tell
    that it's actualy a workaround and as such bad practise.

    yep, that's what I meant (the host provided gui parts).
    yep, I understood that.
     
  16. Lex Nahumury

    Lex Nahumury DH Senior Member

    Joined:
    Jan 5, 2003
    Messages:
    1,944
    Likes Received:
    6
    Trophy Points:
    0
    So you keep mentioning.
    Still, writing an .kxl doesn't have to get more difficult then Copy&Paste and Search&Replace.
    In other words; It can be a total no-brainer. (I hope you know that?)
     
  17. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    That is what we have you for :rofl:.
    j/k

    That is good advice, and your input is always appreciated.
     
  18. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    Well, I think thats *assuming* I can get MSVC2003 to actually compile anything for KX... my attempts at copy / paste (from KX SDK examples) have failed too - its not just KX either - many tutorial examples I have tried don't compile as well - directx tuts that come with the DX SDK is an example.

    I also think maybe you don't give your self enough credit for how much you DO know. :cool:
     
  19. Lex Nahumury

    Lex Nahumury DH Senior Member

    Joined:
    Jan 5, 2003
    Messages:
    1,944
    Likes Received:
    6
    Trophy Points:
    0
    That's too weird.
    I mean, it shouldn't be too much of a problem to get you started with those newer free MS suites.
    Russ uses a licensed VC2003 IIRC, and I have tried the free VC2005 Express a while ago.
    Apart from the known 'kX MFC dependancy' (we can workaround that) it all really should work after some tweaks.

    If you are serious about this stuff, I don't see any reason why Russ or I couldn't help
    you to get it to work.
    You mean me?
    If so, nah,.. just a thing or two. Nothing fancy.
     
  20. Maddogg6

    Maddogg6 Tail Razer

    Joined:
    Jun 21, 2005
    Messages:
    4,027
    Likes Received:
    26
    Trophy Points:
    0
    I had an 'NFR' ('Not for Resale') version of VS2003 - with no docs - no help files - just messages telling me to get the MSDN disks (I assume it was supposed to come with.. ?? - but I didnt get)
    So after quite a few attempts at trying to learn C++ mostly - I just gave up on it and un-installed it, and never really looked at it again since (which was before the MFC thing was straighted out IIRC)


    Well, I guess thats the thing - 'worth the effort'. Im a pain in the ass enough as it is...

    Some people just naturally are better at some stuff - I seem to be naturally bad at programming in general - most likely because I 'sort of' learned BASIC - and some simple Assembly on the old 6502 and 6800 CPU's (probably formed strong yet 'wrong' habits/ways of thinking.. ??).

    Yeah YOU - and Russ and Max and E. and....Tiger, Eygos and Tril .... too

    Your too modest.. :D
     

Share This Page

visited