Git Product home page Git Product logo

Comments (9)

genmeblog avatar genmeblog commented on August 22, 2024

Hi! Thanks for using a fastmath! Yeah, it's quite big bag of functions :)

I don't see an easy way to make this working as you described. Currently effect keeps only internal state not the configuration and allows to reset state.
The true is I created that for an image manipulation techniques (sonification for glitch art) rather than real DSP :)

If you wish we can try to refactor it and to enable more vst or ladspa way ie: input/output channels and state management. I believe it's doable.

from fastmath.

harold avatar harold commented on August 22, 2024

(:

I don't see an easy way to make this working as you described.

No worries! I saw the same, thank you for the confirmation.

The true is I created that for an image manipulation techniques (sonification for glitch art) rather than real DSP :)

Sounds fun! That makes sense.

If you wish we can try to refactor it and to enable more vst or ladspa way ie: input/output channels and state management. I believe it's doable.

I also believe it's doable, though it might require changes that touch a lot of the code in signal.clj.

This is not critical for me at the moment. I have other directions that I am going to take my audio project in first. I am grateful to you for fastmath and this signal code in particular. I am learning a lot by reading and using it.

Take care!

from fastmath.

genmeblog avatar genmeblog commented on August 22, 2024

Since you can build your own effects you can do the following:

(defn sweep-alpha
  [^double rate]
  (let [tinterval (/ rate)
        t (atom (long -1))]
    (fn []
      (let [cutoff (m/norm (m/cos (* 100.0 tinterval (swap! t clojure.core/inc))) 1.0 -1.0 500.0 5000.0)
            tau (/ (* cutoff m/TWO_PI))]
        (/ tinterval (+ tau tinterval))))))

(repeatedly 10 (sweep-alpha 44100.0))
;; => (0.06650056607164513
;;     0.06650128426969248
;;     0.06650343885351115
;;     0.06650702979213088
;;     0.06651205703393591
;;     0.06651852050666654
;;     0.06652642011742149
;;     0.06653575575266107
;;     0.06654652727821102
;;     0.06655873453926664)

(defmethod effect :simple-lowpass-sweep
  ([m] (effect m {}))
  ([m {:keys [rate]
       :or {rate 44100.0}}]
   (let [next-alpha (sweep-alpha rate)]
     (effect-node m (fn
                      ([^double sample ^double prev]
                       (let [alpha (next-alpha)
                             s1 (* sample alpha)
                             s2 (- prev (* prev alpha))
                             nprev (+ s1 s2)]
                         (SampleAndState. nprev nprev)))
                      ([] 0.0))))))

(apply-effects [0.1 0.2 0.3 0.4 0.5] (effect :simple-lowpass-sweep)) ;; dynamic cutoff
;; => (0.006650056607164514 0.019508076156260417 0.03816175366250626 0.06222654069160635 0.09134375398506965)
(apply-effects [0.1 0.2 0.3 0.4 0.5] (effect :simple-lowpass {:cutoff 500})) ;; static cutoff
;; => (0.006650056607164514 0.019507937292708617 0.03816081824134688 0.06222332865519821 0.09133572511258808)

cutoff is generated from sine and (in above example) bounces between 500.0 to 5000.0Hz 100 times per second.

from fastmath.

harold avatar harold commented on August 22, 2024

Ha! That's great.

audio output example: square-lowpass-sweep.wav.gz 😄

Spectrogram:
image

I am off and running.

One thing I encountered is that fastmath.signal/effect-node is a private function. This means that to define my effect in my own file I ended up writing this (note the #'signal/effect-node bit):

(defmethod signal/effect :simple-lowpass-sweep
  ([m] (signal/effect m {}))
  ([m {:keys [rate]
       :or {rate 44100.0}}]
   (let [alpha-fn (produce-alpha-fn rate)]
     (#'signal/effect-node
      m (fn
          ([^double sample ^double prev]
           (let [alpha (alpha-fn)
                 s1 (* sample alpha)
                 s2 (- prev (* prev alpha))
                 nprev (+ s1 s2)]
             (SampleAndState. nprev nprev)))
          ([] 0.0))))))

Maybe effect-node should be public? I don't know.

from fastmath.

genmeblog avatar genmeblog commented on August 22, 2024

Oh, that's cool! Glad it works. Actually this filter is really simple with quite flat slope. Anyway, it works :)
I can add state variable filter, which I have implemented elsewhere (https://github.com/genmeblog/soundsynth)
I will correct the visibility of crucial functions and publish a snapshot soon.

from fastmath.

harold avatar harold commented on August 22, 2024

Yup! A multipole filter (steeper slope) and/or one with resonance would be appreciated.

It appears we have overlapping interests. 😄

from fastmath.

genmeblog avatar genmeblog commented on August 22, 2024

Yeah :) However writing the software synthesizer was kind of a study to help with my son's project.

Eventually I've made effect-node as a public function. Sorry for delay.
No SVF yet. I have to figure out how to make parameters in terms of frequencies.

from fastmath.

harold avatar harold commented on August 22, 2024

Perhaps you son and I are the ones with overlapping interests then, ha!

Thanks for your thoughts here. I have finished the project I was working on in this area for now, but when I come back to it I will integrate fastmath deeper.

Take care.

from fastmath.

genmeblog avatar genmeblog commented on August 22, 2024

Closing, since it's nothing to do with this.

from fastmath.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.