Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent / Odd Behavior when trying to combine sound-waves via map in a definst #435

Open
Bmottomus opened this issue Jul 25, 2019 · 2 comments

Comments

@Bmottomus
Copy link

Bmottomus commented Jul 25, 2019

For context here, I am trying create a way to rapidly prototype new instruments by combining waves (as laid out below) using vectors as inputs. It seems that I can achieve defining instruments this way, but it only works as expected once I create a second instrument. The behavior seems inconsistent and rather odd - thanks for any help you can give!

(use 'overtone.live)

(defn linEnvelope [dur weights]
  (let [asd (map (partial * dur) weights)]
    (env-gen (apply lin asd) :action FREE )))

;; Trying to dynamically combine two different waves into a single instrument
;; However the below, when initially played, will only pick up on the first item in the vector
(definst onlyPlaysFirstVec [frequencies 0 amps 0 instruments 0 ]
   (map +
    (map 
      (fn [[fundamental-fq amp overtones weights envelope  waveT panT]]
        (let [fqs (map (partial * fundamental-fq) overtones)]
           (panT 
            (* (sum (map * (map waveT fqs) weights))
                envelope
                amp))))

       [[195.99772 0.5 [1 2 3 4]  [0.6 0.3 0.15 0.075] (linEnvelope (/ 3 5) [1/4 1/4 1/4 1/4]) (partial sync-saw) (partial pan2)]
       [329.62752 0.8 [1 2 3 4] [0.6 0.3 0.15 0.075] (linEnvelope (/ 3 5) [1/4 1/4 1/4 1/4]) (partial sin-osc) (partial pan2)]
       ]
     )
   )
 )

(onlyPlaysFirstVec)

;; For comparison, this is the above, but with the parameters manually placed where above they're generated in the map 
  (definst combinesAndWorksAsExpected []
      (map +
        (let [fqs (map (partial * 195.99772) [ 1 2 3 4])]
           (pan2 
            (* (sum (map * (map sync-saw fqs) [0.6 0.3 0.15 0.075]))
                (linEnvelope (/ 3 5) [1/4 1/4 1/4 1/4])
                0.5)))
        (let [fqs (map (partial * 329.62752) [1 2 3 4])]
           (pan2 
            (* (sum (map * (map  sin-osc fqs) [0.6 0.3 0.15 0.075]))
                (linEnvelope (/ 3 5) [1/4 1/4 1/4 1/4])
                0.8)))
        )
      )

(combinesAndWorksAsExpected)

;; Even stranger, when I play the map-generate instrument after creating *any* other instrument, it appears to work as expected
(onlyPlaysFirstVec)
@hlolli
Copy link
Member

hlolli commented Nov 2, 2019

I'm surprised that this even works :) because you seem to interchange overloaded functions */- from a ugen and clojure call. I would make sure that any list, vector or sequence is converted to a buffer before passing it to definst. And do any clojure side sequencing on the instrument instance itself.

@hlolli
Copy link
Member

hlolli commented Nov 2, 2019

For that matter, it would make sense to overload vectors too, just convert them to buffers, but that could still be a great source of headache since people would be likely to mix any type of data in them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants