Last active
May 19, 2016 20:44
-
-
Save Jannis/78d58c53f82a5e886e0145aba3c31e33 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ~/W/v/cljs-audio-utils (jannis/mp3-encoder) $ git diff | |
| diff --git a/src/devcards/audio_utils/devcards/mp3_encoder.cljs b/src/devcards/audio_utils/devcards/mp3_encoder.cljs | |
| index 5a5813f..121651a 100644 | |
| --- a/src/devcards/audio_utils/devcards/mp3_encoder.cljs | |
| +++ b/src/devcards/audio_utils/devcards/mp3_encoder.cljs | |
| @@ -72,11 +72,15 @@ | |
| (reduce (fn [length-so-far buf] | |
| (doseq [channel (range 0 (.-numberOfChannels buffer))] | |
| (let [in-chan (.getChannelData buf channel) | |
| - out-chan (.getChannelData buffer channel)] | |
| - (doseq [n (range 0 (.-length in-chan))] | |
| - (aset out-chan (+ length-so-far n) | |
| + out-chan (.getChannelData buffer channel) | |
| + padding 4410] | |
| + (doseq [n (range padding (- (.-length in-chan) | |
| + (* 2 padding)))] | |
| + (aset out-chan (+ length-so-far (- n padding)) | |
| (aget in-chan n))))) | |
| - (+ length-so-far (.-length buf))) | |
| + (+ length-so-far | |
| + (- (.-length buf) | |
| + (* 2 padding)))) | |
| 0 buffers) | |
| buffer)) | |
| diff --git a/src/main/audio_utils/mp3_encoder.cljs b/src/main/audio_utils/mp3_encoder.cljs | |
| index 97b80c3..9b41d4b 100644 | |
| --- a/src/main/audio_utils/mp3_encoder.cljs | |
| +++ b/src/main/audio_utils/mp3_encoder.cljs | |
| @@ -11,8 +11,11 @@ | |
| (reset! next nil)) | |
| (process-audio [this data] | |
| - (let [int-data (mapv (fn [samples] | |
| - (into-array (map #(* 32768 %) samples))) | |
| + (let [padding 4410 | |
| + int-data (mapv (fn [samples] | |
| + (into-array (concat (repeat padding 0) | |
| + (map #(* 32768 %) samples) | |
| + (repeat padding 0)))) | |
| data) | |
| encoder (js/lamejs.Mp3Encoder. 2 sample-rate bit-rate) | |
| encoded #js []] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment