This particular case also looks easy parallelize. Using agents you can divide the execution time by number of available CPUs.
On Sun, May 10, 2009 at 9:35 AM, Julien <julien.ma...@gmail.com> wrote: > > here's a improved version of the byte-array-sound function which is > probably easier to understand. based upon a real mathematical formula. > > (defn byte-array-sound-2 [frequency sample-rate nb-frame] > (let [sample-array (make-array (. Byte TYPE) (* nb-frame 2)) > sample-interval (/ 1 (double sample-rate)) > limit (alength sample-array)] > (loop [sample-index 0 > t (double 0)] > (let [sample (short (* (int Short/MAX_VALUE) (Math/sin (* (* t > 2.0) (* Math/PI frequency)))))] > (aset-byte sample-array sample-index (byte > (bit-shift-right sample > 8))) > (aset-byte sample-array (+ sample-index 1) > (byte (bit-and (int > sample) (int 255))))) > (if (< (+ sample-index 2) limit) > (recur (inc (inc sample-index)) > (double (+ t sample-interval))) > sample-array)))) > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---