Skip to content

Commit 72c9246

Browse files
committed
Small updates
1 parent 14dcaa2 commit 72c9246

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/simulflow/transport.clj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[simulflow.transport.in :as in]
77
[simulflow.transport.out :as out]
88
[simulflow.utils.audio :as audio]
9-
[simulflow.utils.core :as u :refer [defaliases]]))
9+
[simulflow.utils.core :as u :refer [defaliases]]
10+
[taoensso.telemere :as t]))
1011

1112
;; =============================================================================
1213
;; Processors
@@ -68,6 +69,11 @@
6869
:channels 1 ; PCM is mono
6970
:sample-size-bits 16 ; PCM is 16-bit
7071
:duration-ms duration-ms})]
72+
(t/log! {:id :audio-splitter
73+
:msg "Received audio output. Splitting into chunks"
74+
:level :debug
75+
:data {:sample-rate sample-rate
76+
:chunk-size chunk-size}})
7177
(if-let [chunks (split-audio-into-chunks audio chunk-size)]
7278
;; Create new frames preserving the sample rate from original frame
7379
[state {:out (mapv (fn [chunk-audio]

src/simulflow/transport/in.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
(defn log-vad-state!
2727
[prev-vad-state vad-state]
28-
(when (not= prev-vad-state vad-state)
28+
(when (and prev-vad-state vad-state (not= prev-vad-state vad-state))
2929
(t/log! {:level :debug
3030
:id :transport-in
3131
:msg "Changed vad state"

src/simulflow/transport/out.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
;; Audio writer process - handles only audio I/O side effects and lazy line opening
5858
(vthread-loop []
5959
(when-let [audio-command (<!! audio-write-ch)]
60+
(t/log! {:level :debug :id :speakers-out :msg "Playing audio chunk" :data audio-command})
6061
(when (= (:command audio-command) :write-audio)
6162
(let [current-time (u/mono-time)
6263
delay-until (:delay-until audio-command 0)
@@ -70,6 +71,7 @@
7071
new-line))]
7172
(when (pos? wait-time)
7273
(<!! (timeout wait-time)))
74+
7375
(sound/write! (:data audio-command) line 0)))
7476
(recur)))
7577

@@ -163,6 +165,7 @@
163165
[{:keys [transport/serializer] :as state
164166
::keys [last-send-time sending-interval]
165167
:or {last-send-time 0}} frame now]
168+
(t/log! {:level :debug :id :speakers-out :sample 0.01 :msg "Received playback frame" :data (dissoc (:frame/data frame) :audio)})
166169
(let [should-emit-start? (not (::speaking? state))
167170
maybe-next-send (+ last-send-time sending-interval)
168171
next-send-time (if (>= now maybe-next-send) now maybe-next-send)
@@ -196,8 +199,7 @@
196199
:or {now (u/mono-time)}} input-port frame]
197200
(cond
198201
;; Handle incoming audio frames - core business logic moved here
199-
(and (= input-port :in)
200-
(frame/audio-output-raw? frame))
202+
(frame/audio-output-raw? frame)
201203
(process-realtime-out-audio-frame state frame now)
202204

203205
(and (= input-port :timer-out)

test/simulflow/transport/out_test.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@
2828
::sut/sending-interval 20}
2929
frame (frame/audio-output-raw {:audio (byte-array [1 2 3]) :sample-rate 24000})
3030
current-time 2000
31-
[new-state output] (sut/process-realtime-out-audio-frame state frame current-time)]
31+
[new-state output] (sut/process-realtime-out-audio-frame state frame current-time)
32+
command (first (:audio-write output))]
33+
(is (= (update command :data vec) {:command :write-audio
34+
:data [1, 2, 3]
35+
:delay-until 2000
36+
:sample-rate 24000}))
3237

3338
(is (true? (::sut/speaking? new-state)))
3439
(is (= 1 (count (:audio-write output))))

0 commit comments

Comments
 (0)