omni
omni copied to clipboard
[RFC] process
Related to #107
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.
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
chain
could also be used inside process
in place of sample
.
chain
and perform
/ sample
are mutually exclusive.
What about writing a def
with a process
as argument?
- They must always be type declared (probably)
- Can only be called in
sample
(as they in turn callsample
inside theprocess
). Actually, this can be made true by making the inner function that theprocess
generates forsample
to only be called bysample
either in global scope or in anotherprocess
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)
You could also compile process
directly:
-
If file contains multiple processes, they all will get compiled (if no
perform
/sample
ORchain
are provided):omni Sine.omni
-
To compile a single
process
:omni Sine.omni --process Sine
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