Skip to content

Instantly share code, notes, and snippets.

@neatonk
Created October 18, 2012 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neatonk/3909411 to your computer and use it in GitHub Desktop.
Save neatonk/3909411 to your computer and use it in GitHub Desktop.
ArrayMax Ugen metdadata for Overtone
;;; This is the metadata used to define the ArrayMax ugen spec.
{:name "ArrayMax",
:summary "detect the largest value (and its position) in an array of UGens",
:args
[{:name "array", :mode :append-sequence :doc "input ugens (channelArray)"}],
:rates #{:ar :kr},
:doc "Finds the maximum value in an Array of UGens, and outputs the value and the index. This is for use in a SynthDef. If you simply need to find out which is the maximum in an array of numbers, use the link::Overviews/Methods#maxIndex#maxIndex:: and/or link::Overviews/M\
ethods#maxItem#maxItem:: methods defined for any Collection."}
;;; This is the example form the scdoc for Help file
;; (
;; x = {
;; // A collection of different tones:
;; var son = SinOsc.ar((100, 100.3 .. 110));
;; var val = ArrayMax.ar(son).at(0);
;; val = LeakDC.ar(val); // the operation tends to induce DC offset
;; Pan2.ar(val)
;; }.play
;; )
;; x.free
;;; This is my translation to Overtone
(defsynth help-array-max []
(let [snd (sin-osc (range 100 110 0.3))
val (select (array-max snd))
val (leak-dc val)]
(out 0 (pan2 val))))
;; The synthdef succeeds, but cannot be instantiated.
(help-array-max) ; This crashes the scsynth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment