+ Reply to Thread
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 29

Thread: Waveform Generator

  1. #11
    Wire Amateur yaworski's Avatar
    Join Date
    Feb 2007
    Location
    Poland
    Posts
    81

    Default

    sinr and sind both output -1 to 1

    and you would use CEILING on sin to get the square

    phoenix is right on basically all counts

    except triangle
    triangle is abs(2-(X%4))-1
    which is 5 gates: modulus, constant, subtract, absolute, decrement.

    edit: oops mistake

    edit2: i just noticed the 50 lines of code above me were for sawtooth...

    don't do the huge if statements and variables use this formula.

    edit3: NO WAIT MY FORMULAS TRIANGLE. wtf am i thinking.
    sawtooth formula (x%2)-1 and inverted sawtooth 1-(x%2)[/b]
    CEILING wouldn't help. ceil(-1) = -1, ceil(0) = 0, ceil(1) = 1 so you still have 3 values (yeah I know that -1 is so short that it probably will never show up ).

    The code above was written very quickly without even testing (actually I didn't play gmod for a while now ). I know that there are better ways to write this . I only wonder how the lua % operator works with non-integer numbers? I always thought that % is defined only for integers. That is why I didn't used the equations and used couple of ifs to control the output.

  2. #12
    Wirererer Qjet's Avatar
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    319

    Default

    Triangle: 1-abs(2-((x*2)%4))
    Square: ceil(1-(x%2))
    Saw: x%2-1
    InvSaw 1-X%2
    Sin: sind(x*180) OR sinr(x*pi)
    Pulse: floor(x%1)

    and waveforms range from -1 to 1
    this is what defines waveforms. They transform a translational variable into a repeating frequency.
    however you may be right Ceil isn't what i am looking for as it gives the opportunity for the number to be 0.
    Squarex%2-1)-((x+0.5)%2-1) That will work.

  3. #13
    Wire Amateur yaworski's Avatar
    Join Date
    Feb 2007
    Location
    Poland
    Posts
    81

    Default

    Triangle: 1-abs(2-((x*2)%4))
    Square: ceil(1-(x%2))
    Saw: x%2-1
    InvSaw 1-X%2
    Sin: sind(x*180) OR sinr(x*pi)
    Pulse: floor(x%1)

    and waveforms range from -1 to 1
    this is what defines waveforms. They transform a translational variable into a repeating frequency.
    however you may be right Ceil isn't what i am looking for as it gives the opportunity for the number to be 0.
    Squarex%2-1)-((x+0.5)%2-1) That will work.[/b]
    Your Pulse is probably wrong.
    Mod operator in lua is defined as a % b == a - math.floor(a/b)*b. When b = 1 you will get:
    a % 1 = a - math.floor(a/1)*1 = a - math.floor(a)

    0%1 = 0
    0.3%1 = 0.3
    0.5%1 = 0.5
    0.9%1 = 0.9
    1%1 = 0
    1.3%1 = 0.3
    1.5%1 = 0.5
    etc

    The only thing you get is a sawtooth.

    It would be probably good to give the user possibility to change the minimal value and amplitude scale. This would add 2 additional inputs: Min Value and Amplitude Scale. Lets start from 0 to 1. If user want from -1 to 1 then he/she connects -1 to Min Value and 2 to the scale and the gate outputs from -1 to 1. This can be used to output waves that are shifted vertically, for example from -1 to 3 or so.

    I would do every waveform into their own gates, because:
    1. This is easier to maintain (less code in every gate)
    2. Those gates needs to be timed, so they are recalculated every frame. It is better to do the calculation only for one output than for all of them (if all waveforms would be in a single gate with many outputs). This brings the idea of detecting if something is actually connected to specific gate output. For example it could be set by the gate sEnt when something is connected to the specific output then something is set in gate variable and could be checked with, for example:

    local square = 0
    local triangle = 0

    if (gate.outputs.Square) then square = [square calculation] end
    if (gate.outputs.Triangle) then triangle = [triangle calculation] end

    Of course Square and Triangle in outputs would be named exactly like the outputs. It should be easy to set and unset those checks when something connects or disconnects from the gate. This could also allow to create new kind of gates that behave in different way when disconnected. This would be also great to have the same checks for inputs.

  4. #14
    Wirererer Qjet's Avatar
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    319

    Default

    Amplitude would be managed by the delta of the input the user is giving to the waveform, however i could see a place for a min and max range in this. Thank you for catching the mistake in my pulse. Though in reality, pulse isnt a waveform .3 So no these gates are excruciatingly simple

    one gate with 3 inputs and 5 outputs.
    A, min, max
    and the 5 outputs
    sin
    saw
    invsaw
    square
    triangle

    Theirs no need for timers, no need for 5 whole new gates in wiremod, god knows we have enough. 1 gate ^.' (i like the min max idea of yours thats a good plan)

  5. #15
    Wire Amateur yaworski's Avatar
    Join Date
    Feb 2007
    Location
    Poland
    Posts
    81

    Default

    Amplitude would be managed by the delta of the input the user is giving to the waveform, however i could see a place for a min and max range in this. Thank you for catching the mistake in my pulse. Though in reality, pulse isnt a waveform .3 So no these gates are excruciatingly simple

    one gate with 3 inputs and 5 outputs.
    A, min, max
    and the 5 outputs
    sin
    saw
    invsaw
    square
    triangle

    Theirs no need for timers, no need for 5 whole new gates in wiremod, god knows we have enough. 1 gate ^.' (i like the min max idea of yours thats a good plan)[/b]
    Actually min and max is not a good idea as not connected inputs are defaulting to 0. So you can check if Scale = 0 and then set it to 1 (scale shouldn't be 0). But you don't need to do that to min value (0 as the default min value). You cannot check min if it is 0 because user maybe would like to have it as 0 .

    I didn't say that we need timers. I said that this gate needs to be timed. Timed gates don't require to be triggered by changing their inputs. They are recalculated every frame. I don't see a point in waveform generating gate that is not timed. This makes no sense to me. Waveforms should have their own group or go to the time gates category. As I said it is not a good idea to do many calculations for different waveforms in one gate that is timed. In most cases you probably won't use more than one wave form so this is waste of processing power.

    The way I see those gates:
    Inputs: Frequency, Run, Reset, MinValue, Scale
    Outputs: Out

    I think someone from wiremod team should point the direction in which the wiremod should go. Creating many smaller specialized gates like each waveform in its own gate, or create big specialized gates that do similar things with many outputs.

    One other thing. What will you do if you'll want to use 2 different waveforms but with different frequencies? It's even a bigger waste of processing power (one waveform from each gate).

  6. #16
    Wirererer Qjet's Avatar
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    319

    Default

    ok so yah generally we basically see waveforms being animated. cycled through some kind of timer, but just because thats how we display a waveform doesn't mean thats how we're always going to use it.
    Further more waveforms go from -1 to 1
    not 0 to 1
    -1 to 1
    not 0 to 1
    ill say this all day if i gotta... so we shouldn't have a min value defaulting to 0...
    Also how could you want 5 gates instead of 1. i mean it would save space (and wiremod uses toooooo much space)
    and it would be fairly simple to use, and its not unreasonable that a player would want access to more then one waveform based off the same input.

  7. #17
    Wire Amateur yaworski's Avatar
    Join Date
    Feb 2007
    Location
    Poland
    Posts
    81

    Default

    ok so yah generally we basically see waveforms being animated. cycled through some kind of timer, but just because thats how we display a waveform doesn't mean thats how we're always going to use it.
    Further more waveforms go from -1 to 1
    not 0 to 1
    -1 to 1
    not 0 to 1
    ill say this all day if i gotta... so we shouldn't have a min value defaulting to 0...
    Also how could you want 5 gates instead of 1. i mean it would save space (and wiremod uses toooooo much space)
    and it would be fairly simple to use, and its not unreasonable that a player would want access to more then one waveform based off the same input.[/b]
    Space optimizations always conflicts with speed optimizations. If we want more speed then we must sacrifice space. And full gate definition for gate like waveform takes about 200-400 bytes probably so you want to save for example 4*500 bytes and always calculate all waveforms even if user wants to use only one of them. So why calculate all waveforms? I already pointed that in my above post. If you want to have 2 independent waveforms (and all waveforms in one gate are dependent on each other, because they are triggered the same way) then you will need to spawn 2 gates anyway. Please tell me, how many contraptions can you build using different waveforms from one gate? Will you use for example 3 of them at once?

    There is a problem with default inputs in gates. AFAIK all not connected inputs have value 0 when they aren't connected. If you'll check if this value is equal to 0 and then change it to -1, you'll loose the ability to set the value to 0 anyway (because this will still be changed to -1). This is only possible on inputs where 0 is not a possible option. The Scale input is a good example because setting Scale to 0 makes no sense (the output would be flat line). So we can check if the input is 0 and change it to 1 (Scale = 1 means no change). That's why defaulting to 0 and 1 would be better in the case of current gates' architecture. If there would be possibility to specify default values for inputs if they aren't connected then I would agree with you. Anyway I agree with you in general that waveforms are in range [-1,1] but in wiremod's case we can close eyes on this.

    I rethought the way that the gate would be triggered and actually this could be useful to have this gate as not timed. To have it timed it would require to simply attach an accumulator gate to it. But this would make this gate recalculate every frame anyway as accumulator is timed and outputs different value every frame so waveform gate would be still triggered then.

    I'll reply this all day long too. I really don't see the point of sacrificing performance to save 2kB of disk space (which is cheaper every day). The only waveforms I could see in one gate are sawtooth and inversed sawtooth. Actually this can be achieved with only one output by setting the Scale to -1 .

  8. #18
    Wirererer Qjet's Avatar
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    319

    Default

    geeez man could you try to be concise with your posts? I mean i'm not here to read a book, and dealing with 50 angles at once gets us nowhere.

    im only going to deal with your first point, so lets get this under control ok?

    Space optimizations do not conflict with speed optimizations in this case. The fact that the formula for all 5 outputs will be run really doesn't equate to a hill of beans.

    edit: i had a thought

    two inputs one output
    A, Waveform

    Waveform runs from 0-5 round down.
    in this situation someone can change on the fly, you don't calculate all the gates, you don't further bloat wiremod, and we walk off with function of the gate still there. We save on speed, we save on space, and we accomplish the task.

    edit2: oh and another thing i wanted to be clear on, when i say space, i mean the interface in wiremod. Adding gates adds more items to the list, making other components harder to find.

  9. #19
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default

    I felt the urge to try them out!

    [attachment=240:waveform.JPG]

    EDIT: when are they going to fix the screens so they display all the way out :/
    Attached Thumbnails Attached Thumbnails Waveform Generator-waveform.jpg  

  10. #20
    Wirererer Qjet's Avatar
    Join Date
    Mar 2007
    Location
    Canada
    Posts
    319

    Default

    is that bottom right one pulse? crap i DID screw that up .S Ah well pulse isn't a real waveform anyway

+ Reply to Thread
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Wire - Field Generator(s)
    By AlgorithmX2 in forum Wiremod Addons & Coding
    Replies: 195
    Last Post: 01-10-2010, 09:38 AM
  2. Wired Random Number/Colour Generator
    By Snitchio in forum Ideas & Suggestions
    Replies: 2
    Last Post: 11-24-2008, 12:59 PM
  3. Wire + Life Support generator and motor...
    By Infinity in forum Ideas & Suggestions
    Replies: 16
    Last Post: 06-09-2007, 03:06 PM
  4. Need the pack that has the "Generator" and "Razor" models...
    By Mr. Brightside in forum Installation and Malfunctions Support
    Replies: 2
    Last Post: 06-06-2007, 11:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots