Skip to content

Commit

Permalink
1.4.2 - construct AudioSegment from bytes,
Browse files Browse the repository at this point in the history
refactored from-byte-string to work with keyed args,
fixed tests in io and prop ns
  • Loading branch information
rybandrei2014 committed Mar 18, 2021
1 parent 468fe9a commit 6f72f77
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Expand Up @@ -47,4 +47,12 @@
## 1.4.1
### Changed
- reference TarsosTranscoder fork from maven central instead of local .jar
- fixed .gitignore to ignore calva related files
- fixed .gitignore to ignore calva related files

## 1.4.2
### Added
- from-bytes - create AudioSegment from bytes (array of uint8)
### Changed
- small refactor of from-byte-string to accept keyed args
- small refactor of tests
- fixed tests in io-test and prop-test namespaces
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject dragoon/cljdub-dsp "1.4.1"
(defproject dragoon/cljdub-dsp "1.4.2"
:description "Sound processing library that allows usage of pydub library's functionality in Clojure as well as provides interface for interaction between pydub and TarsosDSP libraries"
:url "https://github.com/dragoon000320/cljdub-dsp"
:license {:name "Eclipse Public License 2.0"
Expand Down
12 changes: 11 additions & 1 deletion src/cljdub_dsp/io.clj
Expand Up @@ -6,6 +6,7 @@
(:import (be.tarsos.transcoder Transcoder DefaultAttributes)))

(require-python '[pydub :bind-ns])
(require-python '[builtins :as bins])

(defn silent-seg
"Creates a silent audiosegment, which can be used as a placeholder,
Expand All @@ -18,12 +19,21 @@

(defn from-byte-string
"Creates AudioSegment from python byte string"
[byte-string sample-width sample-rate channels]
[byte-string & {:keys [sample-width sample-rate channels]}]
(py.. pydub (**AudioSegment byte-string
{:sample_width sample-width
:frame_rate sample-rate
:channels channels})))

(defn from-bytes
"Creates new AudioSegment from array of uint8 (unsigned bytes)"
[bytes & {:keys [sample-width sample-rate channels]}]
(-> bytes
bins/bytes
(from-byte-string :sample-width sample-width
:sample-rate sample-rate
:channels channels)))

(defn from-mono-segs
"Creates new AudioSegment from several mono AudioSegments"
[segs]
Expand Down
21 changes: 19 additions & 2 deletions test/cljdub_dsp/io_test.clj
Expand Up @@ -14,10 +14,27 @@
1))
(is (every? #(= % 0) (samples seg)))))

(deftest from-bytes-test
(let [byte-string (bins/bytes audio-data)
seg (from-bytes audio-data
:sample-width audio-sample-width
:sample-rate audio-frame-rate
:channels audio-channels)]
(is (= (raw-data seg)
byte-string))
(is (= (sample-width seg)
audio-sample-width))
(is (= (frame-rate seg)
audio-frame-rate))
(is (= (channels seg)
audio-channels))))

(deftest from-byte-string-test
(let [byte-string (bins/bytes audio-data)
seg (from-byte-string byte-string audio-sample-width
audio-frame-rate audio-channels)]
seg (from-byte-string byte-string
:sample-width audio-sample-width
:sample-rate audio-frame-rate
:channels audio-channels)]
(is (= (raw-data seg)
byte-string))
(is (= (sample-width seg)
Expand Down
9 changes: 5 additions & 4 deletions test/cljdub_dsp/prop_test.clj
@@ -1,7 +1,7 @@
(ns cljdub-dsp.prop-test
(:require [clojure.test :refer :all]
[cljdub-dsp.prop :refer :all]
[cljdub-dsp.io :refer [from-byte-string]]
[cljdub-dsp.io :refer [from-bytes]]
[libpython-clj.require :refer [require-python]]))

(require-python '[builtins :as bins])
Expand All @@ -17,9 +17,10 @@

(defn test-seg
[]
(-> audio-data bins/bytes (from-byte-string audio-sample-width
audio-frame-rate
audio-channels)))
(from-bytes audio-data
:sample-width audio-sample-width
:sample-rate audio-frame-rate
:channels audio-channels))

(def test-seg-props
{:max-possible-amp 32768.0,
Expand Down

0 comments on commit 6f72f77

Please sign in to comment.