i'm making function generates .wav file. have header set, i'm running trouble data
itself. have function creating sine wave @ 880hz (at least think that's does, that's not question)--the question is, how convert collection of byte arrays 1 byte array contents? best try:
(defn lil-endian-bytes [i] (let [i (int i)] (byte-array (map #(.bytevalue %) [(bit-and 0x000000ff) (bit-shift-right (bit-and 0x0000ff00) 8) (bit-shift-right (bit-and 0x00ff0000) 16) (bit-shift-right (bit-and 0xff000000) 24)])))) (def leb lil-endian-bytes) (let [wr (io/output-stream (str name ".wav") :append true)] (.write wr (byte-array (flatten (concat (map (fn [sample] (leb (* 0xffff (math/sin (+ (* 2 3.14 880) sample))))) (range (* duration s-rate)) )))))
but doesn't want do: concat of byte-arrays 1 vector , single byte array. , makes sense me why can't: can't concat/flatten byte[] because it's not vector; it's byte[]. , can't cast byte[] byte. need working?
you might looking like:
(byte-array (mapcat seq my-sequence-of-byte-arrays))
Comments
Post a Comment