Fork me on GitHub
#overtone
<
2024-04-24
>
plexus15:04:11

(synthdef-read (synthdef-bytes (:sdef my-synth)))

diego.videco17:04:06

Just testing this, getting some “interesting” results: With this:

(
SynthDef("dusty-test",
	{
		|in=0, replyRate=10, peakLag=3|
		SendPeakRMS.kr(Dust.ar(20))
	}
).store(dir: "my-dir")
)
There’s this:
{:ugens
 [{:name "Control",
   :rate 1,
   :n-inputs 0,
   :n-outputs 3,
   :special 0,
   :inputs [],
   :outputs [{:rate 1} {:rate 1} {:rate 1}]}
  {:name "Dust",
   :rate 2,
   :n-inputs 1,
   :n-outputs 1,
   :special 0,
   :inputs [{:src -1, :index 0}],
   :outputs [{:rate 2}]}
  {:name "SendPeakRMS",
   :rate 1,
   :n-inputs 12,
   :n-outputs 0,
   :special 0,
   :inputs
   [{:src -1, :index 0}
    {:src -1, :index 1}
    {:src -1, :index 2}
    {:src -1, :index 3}
    {:src 1, :index 0}
    {:src -1, :index 4}
    {:src -1, :index 5}
    {:src -1, :index 6}
    {:src -1, :index 7}
    {:src -1, :index 8}
    {:src -1, :index 9}
    {:src -1, :index 10}],
   :outputs []}],
 :variants [],
 :n-ugens 3,
 :n-variants 0,
 :pnames
 [{:name "in", :index 0}
  {:name "replyRate", :index 1}
  {:name "peakLag", :index 2}],
 :name "dusty-test",
 :n-constants 11,
 :params [0.0 10.0 3.0],
 :n-pnames 3,
 :n-params 3,
 :version 2,
 :constants [20.0 3.0 -1.0 1.0 6.0 47.0 114.0 101.0 112.0 108.0 121.0]}
VS:
// or clj
(o/defsynth peak-rms
    [in 0 reply-rate 10 peak-lag 3]
    (o/send-peak-rms (o/dust 20)))
This:
{:ugens
 [{:name "Control",
   :rate 1,
   :n-inputs 0,
   :n-outputs 3,
   :special 0,
   :inputs [],
   :outputs [{:rate 1} {:rate 1} {:rate 1}]}
  {:name "Dust",
   :rate 2,
   :n-inputs 3,
   :n-outputs 1,
   :special 0,
   :inputs [{:src -1, :index 4} {:src -1, :index 2} {:src -1, :index 0}],
   :outputs [{:rate 2}]}
  {:name "SendPeakRMS",
   :rate 1,
   :n-inputs 11,
   :n-outputs 1,
   :special 0,
   :inputs
   [{:src 1, :index 0}
    {:src -1, :index 4}
    {:src -1, :index 1}
    {:src -1, :index 3}
    {:src -1, :index 8}
    {:src -1, :index 9}
    {:src -1, :index 11}
    {:src -1, :index 6}
    {:src -1, :index 10}
    {:src -1, :index 7}
    {:src -1, :index 5}],
   :outputs [{:rate 1}]}],
 :variants [],
 :n-ugens 3,
 :n-variants 0,
 :pnames
 [{:name "in", :index 0}
  {:name "reply-rate", :index 1}
  {:name "peak-lag", :index 2}],
 :name "external.scratch/peak-rms",
 :n-constants 12,
 :params [0.0 10.0 3.0],
 :n-pnames 3,
 :n-params 3,
 :constants [0.0 3.0 1.0 -1.0 20.0 121.0 101.0 108.0 6.0 47.0 112.0 114.0]}

diego.videco17:04:11

However with something like this:

(
SynthDef("amp-regulator-replier",
	{
		|in=0, replyRate=10, peakLag=3|
		((in, 4), replyRate, peakLag, "/amp-regulator")
	}
).store(dir: "my-dir")
)
We get this:
{:ugens
 [{:name "Control",
   :rate 1,
   :n-inputs 0,
   :n-outputs 3,
   :special 0,
   :inputs [],
   :outputs [{:rate 1} {:rate 1} {:rate 1}]}
  {:name "In",
   :rate 2,
   :n-inputs 1,
   :n-outputs 4,
   :special 0,
   :inputs [{:src 0, :index 0}],
   :outputs [{:rate 2} {:rate 2} {:rate 2} {:rate 2}]}
  {:name "SendPeakRMS",
   :rate 1,
   :n-inputs 23,
   :n-outputs 0,
   :special 0,
   :inputs
   [{:src 0, :index 1}
    {:src 0, :index 2}
    {:src -1, :index 0}
    {:src -1, :index 1}
    {:src 1, :index 0}
    {:src 1, :index 1}
    {:src 1, :index 2}
    {:src 1, :index 3}
    {:src -1, :index 2}
    {:src -1, :index 3}
    {:src -1, :index 4}
    {:src -1, :index 5}
    {:src -1, :index 6}
    {:src -1, :index 7}
    {:src -1, :index 8}
    {:src -1, :index 9}
    {:src -1, :index 10}
    {:src -1, :index 11}
    {:src -1, :index 12}
    {:src -1, :index 4}
    {:src -1, :index 13}
    {:src -1, :index 14}
    {:src -1, :index 8}],
   :outputs []}],
 :variants [],
 :n-ugens 3,
 :n-variants 0,
 :pnames
 [{:name "in", :index 0}
  {:name "replyRate", :index 1}
  {:name "peakLag", :index 2}],
 :name "amp-regulator-replier",
 :n-constants 15,
 :params [0.0 10.0 3.0],
 :n-pnames 3,
 :n-params 3,
 :version 2,
 :constants
 [-1.0
  4.0
  14.0
  47.0
  97.0
  109.0
  112.0
  45.0
  114.0
  101.0
  103.0
  117.0
  108.0
  116.0
  111.0]}

diego.videco17:04:39

VS:

(o/defsynth peak-rms
    [in 0 reply-rate 10 peak-lag 3]
    (o/send-peak-rms (o/in in 4) reply-rate peak-lag "/amp-regulator"))
Where we get this (notice among other divergencies, the multichannel expansion of the SendPeakRMS ugen, which doesn’t happen on the SC version):
{:ugens
 [{:name "Control",
   :rate 1,
   :n-inputs 0,
   :n-outputs 3,
   :special 0,
   :inputs [],
   :outputs [{:rate 1} {:rate 1} {:rate 1}]}
  {:name "In",
   :rate 2,
   :n-inputs 1,
   :n-outputs 4,
   :special 0,
   :inputs [{:src 0, :index 0}],
   :outputs [{:rate 2} {:rate 2} {:rate 2} {:rate 2}]}
  {:name "SendPeakRMS",
   :rate 1,
   :n-inputs 19,
   :n-outputs 1,
   :special 0,
   :inputs
   [{:src 1, :index 3}
    {:src 0, :index 1}
    {:src 0, :index 2}
    {:src -1, :index 0}
    {:src -1, :index 11}
    {:src -1, :index 8}
    {:src -1, :index 9}
    {:src -1, :index 5}
    {:src -1, :index 10}
    {:src -1, :index 12}
    {:src -1, :index 13}
    {:src -1, :index 1}
    {:src -1, :index 7}
    {:src -1, :index 3}
    {:src -1, :index 4}
    {:src -1, :index 9}
    {:src -1, :index 2}
    {:src -1, :index 6}
    {:src -1, :index 13}],
   :outputs [{:rate 1}]}
  {:name "SendPeakRMS",
   :rate 1,
   :n-inputs 19,
   :n-outputs 1,
   :special 0,
   :inputs
   [{:src 1, :index 1}
    {:src 0, :index 1}
    {:src 0, :index 2}
    {:src -1, :index 0}
    {:src -1, :index 11}
    {:src -1, :index 8}
    {:src -1, :index 9}
    {:src -1, :index 5}
    {:src -1, :index 10}
    {:src -1, :index 12}
    {:src -1, :index 13}
    {:src -1, :index 1}
    {:src -1, :index 7}
    {:src -1, :index 3}
    {:src -1, :index 4}
    {:src -1, :index 9}
    {:src -1, :index 2}
    {:src -1, :index 6}
    {:src -1, :index 13}],
   :outputs [{:rate 1}]}
  {:name "SendPeakRMS",
   :rate 1,
   :n-inputs 19,
   :n-outputs 1,
   :special 0,
   :inputs
   [{:src 1, :index 2}
    {:src 0, :index 1}
    {:src 0, :index 2}
    {:src -1, :index 0}
    {:src -1, :index 11}
    {:src -1, :index 8}
    {:src -1, :index 9}
    {:src -1, :index 5}
    {:src -1, :index 10}
    {:src -1, :index 12}
    {:src -1, :index 13}
    {:src -1, :index 1}
    {:src -1, :index 7}
    {:src -1, :index 3}
    {:src -1, :index 4}
    {:src -1, :index 9}
    {:src -1, :index 2}
    {:src -1, :index 6}
    {:src -1, :index 13}],
   :outputs [{:rate 1}]}
  {:name "SendPeakRMS",
   :rate 1,
   :n-inputs 19,
   :n-outputs 1,
   :special 0,
   :inputs
   [{:src 1, :index 0}
    {:src 0, :index 1}
    {:src 0, :index 2}
    {:src -1, :index 0}
    {:src -1, :index 11}
    {:src -1, :index 8}
    {:src -1, :index 9}
    {:src -1, :index 5}
    {:src -1, :index 10}
    {:src -1, :index 12}
    {:src -1, :index 13}
    {:src -1, :index 1}
    {:src -1, :index 7}
    {:src -1, :index 3}
    {:src -1, :index 4}
    {:src -1, :index 9}
    {:src -1, :index 2}
    {:src -1, :index 6}
    {:src -1, :index 13}],
   :outputs [{:rate 1}]}],
 :variants [],
 :n-ugens 6,
 :n-variants 0,
 :pnames
 [{:name "in", :index 0}
  {:name "reply-rate", :index 1}
  {:name "peak-lag", :index 2}],
 :name "external.scratch/peak-rms",
 :n-constants 14,
 :params [0.0 10.0 3.0],
 :n-pnames 3,
 :n-params 3,
 :constants
 [-1.0
  101.0
  116.0
  117.0
  108.0
  109.0
  111.0
  103.0
  47.0
  97.0
  112.0
  14.0
  45.0
  114.0]}

diego.videco17:04:40

None of the two examples work on Overtone. Should we move this to a github issue @U07FP7QJ0?

diego.videco18:04:06

On the SC source code SendPeakRMS is quite similar to SendReply, however send-reply does work as expected.

plexus07:04:19

sure, always good to have an issue to track this and collect findings. My bandwidth for overtone is low at the moment, but maybe I'll have a chance to poke at things over the weekend

diego.videco20:04:26

BTW if you could review and merge #516 it would be much appreciated. Should be easy to test.

plexus15:04:09

@diego.vid.eco ^ this is what I use, make an overtone synth an a supercollider synth, and then compare the synthdef-read output of the overtone synth to this output

diego.videco15:04:00

Oh I see, makes sense

diego.videco15:04:07

I’ll try it later today

plexus15:04:42

would be really valuable to document that process somewhere 🙂

diego.videco15:04:53

i was exploring it a bit, and found that (into {} my-synth) also seemed to work

diego.videco15:04:12

in the end it’s just a map right?

diego.videco15:04:04

I’ve had similar errors trying to add other UGens (like the DX7 one), so I made this for such cases and for compatibility with other synths. I guess some people may find it useful:

(ns tieminos.sc-utils.synths.scsyndef
  "Generate synths from compiled SuperCollider scsyndef files."
  (:require [overtone.core :as o]
   [overtone.sc.machinery.synthdef :refer [load-synthdef synthdef-read]]))

(comment
  ;; Example
  (def sini (make-synth
              {:synthdef-path "/Users/diego/Music/code/tieminos/src/tieminos/sc_utils/synths/sini.scsyndef"
               :name "sini"
               :params {:freq 200}}))
  (sini)
  (o/stop))


(defn params->synth-params
  [params]
  (map (fn [[name* value]]
         (let [value* (float value)]
           {:name (name name*) :default value* :rate :kr :value (atom value*)}))
       params))

(defn synth-params->args
  [synth-params]
  (map :name synth-params))

(defn make-synth
  [{:keys [name
           synthdef-path
           params]}]
  (let [sdef (synthdef-read synthdef-path)
        params* (params->synth-params params)
        args (synth-params->args params*)
        smap (with-meta
               (o/map->Synth
                 {:name name
                  :sdef sdef
                  :args args
                  :params params*
                  :instance-fn identity})
               {:overtone.live/to-string #(str (name (:type %)) ":" (:name %))})]
    (load-synthdef sdef)
    (o/event :new-synth :synth smap)
    smap))
Just finished it but seems to work with my test synth:
(
SynthDef("sini",
	{
		|freq 0|
		Out.ar(0, (SinOsc.ar(freq)*0.2)!2)
	}
).store(dir: "/Users/diego/Music/code/tieminos/src/tieminos/habitat/extended_sections/hacia_un_nuevo_universo/scsynthdefs/")
)
It’s not perfect as the returned value for make-synth won’t show the param names on lsp or cider. Would need a macro for that I think, but it’s 90% of the way there.