Skip to content

Commit bb040c5

Browse files
Merge pull request #181 from ClojureCivitas/dsp-wav-files-edit
Some editing on "Reading audio data from WAV-files"
2 parents c6133c9 + ad01bf0 commit bb040c5

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/dsp/wav.png

-5.19 KB
Loading

src/dsp/wav_files.clj

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ block
134134
end")
135135

136136
;; The header comprises of the **tag** `RIFF`, its **chunk** tagged
137-
;; with the specific format `WAVE` and a **subchunk** `fmt `, which
137+
;; with the specific format `WAVE` and a **subchunk** `fmt `, which
138138
;; describes the contained audio data. This represents some of the
139139
;; header information in a WAV file with a single, 16-bit mono sound
140140
;; channel and 44.100 samples per second.
@@ -189,10 +189,6 @@ block
189189
(def tuning-fork-url
190190
(str "https://github.com/AllenDowney/ThinkDSP/raw/master/code/" tuning-fork-file))
191191

192-
^:kindly/hide-code
193-
(def tuning-fork-file
194-
"18871__zippi1__sound-bell-440hz.wav")
195-
196192
^:kindly/hide-code
197193
(def tuning-fork-file-compressed
198194
"18871__zippi1__sound-bell-440hz-compressed.wav")
@@ -255,13 +251,16 @@ wav-format
255251
;; into the correct datatype for each frame manually. For now we just
256252
;; put the data for 16-bit mono WAV files into a short-array.
257253
(defn audio-data [^InputStream is]
258-
(let [{:keys [frame-length]} (audio-format is)
259-
format (-> (AudioSystem/getAudioFileFormat is)
260-
AudioFileFormat/.getFormat)
261-
^bytes audio-bytes (with-open [ais (AudioInputStream. is format frame-length)]
262-
(AudioInputStream/.readAllBytes ais))
263-
audio-shorts (short-array frame-length)
264-
bb (ByteBuffer/allocate 2)]
254+
(let [{:keys
255+
[frame-length]} (audio-format is)
256+
format (-> (AudioSystem/getAudioFileFormat is)
257+
AudioFileFormat/.getFormat)
258+
^bytes
259+
audio-bytes (with-open [ais (AudioInputStream. is format
260+
frame-length)]
261+
(AudioInputStream/.readAllBytes ais))
262+
audio-shorts (short-array frame-length)
263+
bb (ByteBuffer/allocate 2)]
265264
(dotimes [i frame-length]
266265
(ByteBuffer/.clear bb)
267266
(.order bb ByteOrder/LITTLE_ENDIAN)

0 commit comments

Comments
 (0)