omni icon indicating copy to clipboard operation
omni copied to clipboard

[RFC] process

Open vitreo12 opened this issue 4 years ago • 6 comments

Related to #107

vitreo12 avatar Jun 12 '20 11:06 vitreo12

struct will then become just a way to declare custom data types (like a Vector[T]).

process will become the standard way of defining re-usable DSP code.

vitreo12 avatar Sep 08 '20 15:09 vitreo12

Sine.omni

process Phasor:
    ins 1:
        freq

    outs 1

    init:
        phase = 0
    
    #internal def (can access ins)
    def updatePhase():
        freq_incr = freq / samplerate
        phase  = (phase + freq_incr) % 1     

    sample:
        updatePhase()
        out1 = phase
    
process Sine:
    ins 1:
        freq

    outs 1

    init:
        phasor = Phasor()

    sample:
        out1 = sin(phasor(freq))

process SineProc:
    ins 1:
        freq

    outs 1

    chain:
        freq -> Phasor -> sin

Then, there would be 2 approaches here to compile the final code:

The first one would be the standard Object Oriented, where a Sine instance is created in init and then used in sample:

OmniSineOOP.omni

require "Sine.omni"

init:
    sine = Sine()

sample:
    out1 = sine(in1)

The second one would be a more Functional approach, using the chain block, in which only special operations are permitted, and only processes can be used:

OmniSineFP.omni

require "Sine.omni"

chain:
    in1 -> Sine

vitreo12 avatar Sep 08 '20 15:09 vitreo12

chain could also be used inside process in place of sample.

chain and perform / sample are mutually exclusive.

vitreo12 avatar Sep 08 '20 16:09 vitreo12

What about writing a def with a process as argument?

  1. They must always be type declared (probably)
  2. Can only be called in sample (as they in turn call sample inside the process). Actually, this can be made true by making the inner function that the process generates for sample to only be called by sample either in global scope or in another process
require "Sine.omni"

def something(sine Sine, freq):
    return sine(freq)

init:
    sine = Sine()
    x = something(sine, freq) #This would error out: can't call a process in anything but sample
    
sample:
    out1 = something(sine, freq)

vitreo12 avatar Sep 08 '20 16:09 vitreo12

You could also compile process directly:

  1. If file contains multiple processes, they all will get compiled (if no perform / sample OR chain are provided):

    omni Sine.omni

  2. To compile a single process:

    omni Sine.omni --process Sine

vitreo12 avatar Sep 08 '20 18:09 vitreo12

What about Buffer as one of the ins? That will require to be passed in on creation?

process Something:
    ins 1:
       buf {Buffer}

   ...

ins 1:
    buf {Buffer}

init:
    something = Something(buf)  #This is required!

What about chain?

chain:
    buf -> Something

vitreo12 avatar Sep 10 '20 10:09 vitreo12