Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ad5dd9de3 | |||
| df8a33f456 | |||
| 1fffff87dd |
@@ -26,18 +26,6 @@ def playback_thread(file_path, state):
|
||||
stream = container.streams.audio[0]
|
||||
resampler = av.AudioResampler(format='s16', layout='stereo', rate=48000)
|
||||
|
||||
def build_graph(template_frame):
|
||||
graph = av.filter.Graph()
|
||||
src = graph.add_abuffer(template=template_frame)
|
||||
loudnorm = graph.add("loudnorm", "I=-16:TP=-1.5:LRA=11")
|
||||
sink = graph.add("abuffersink")
|
||||
src.link_to(loudnorm)
|
||||
loudnorm.link_to(sink)
|
||||
graph.configure()
|
||||
return graph
|
||||
|
||||
graph = None
|
||||
|
||||
with open(fifo_path, 'wb') as fifo:
|
||||
iterator = container.decode(stream)
|
||||
while state.running:
|
||||
@@ -53,7 +41,6 @@ def playback_thread(file_path, state):
|
||||
with state.lock:
|
||||
state.seek_request = None
|
||||
iterator = container.decode(stream)
|
||||
graph = None # Reset filter graph on seek
|
||||
continue
|
||||
|
||||
if paused:
|
||||
@@ -70,44 +57,17 @@ def playback_thread(file_path, state):
|
||||
with state.lock:
|
||||
state.time_pos = float(frame.pts * stream.time_base)
|
||||
|
||||
if graph is None:
|
||||
try:
|
||||
graph = build_graph(frame)
|
||||
except Exception as e:
|
||||
print(f"Filter graph error: {e}", file=sys.stderr)
|
||||
graph = "FAILED"
|
||||
resampled_frames = resampler.resample(frame)
|
||||
for r_frame in resampled_frames:
|
||||
arr = r_frame.to_ndarray()
|
||||
|
||||
# Apply volume
|
||||
if vol != 100.0:
|
||||
multiplier = max(0.0, vol / 100.0)
|
||||
arr = arr.astype(np.float32) * multiplier
|
||||
arr = np.clip(arr, -32768, 32767).astype(np.int16)
|
||||
|
||||
if graph == "FAILED":
|
||||
frames_to_process = [frame]
|
||||
else:
|
||||
try:
|
||||
graph.push(frame)
|
||||
except av.AVError:
|
||||
continue
|
||||
|
||||
frames_to_process = []
|
||||
while True:
|
||||
try:
|
||||
frames_to_process.append(graph.pull())
|
||||
except (av.AVError, BlockingIOError):
|
||||
break
|
||||
|
||||
for filtered_frame in frames_to_process:
|
||||
resampled_frames = resampler.resample(filtered_frame)
|
||||
for r_frame in resampled_frames:
|
||||
arr = r_frame.to_ndarray()
|
||||
|
||||
# Apply volume
|
||||
if vol != 100.0:
|
||||
multiplier = max(0.0, vol / 100.0)
|
||||
arr = arr.astype(np.float32) * multiplier
|
||||
arr = np.clip(arr, -32768, 32767).astype(np.int16)
|
||||
|
||||
try:
|
||||
fifo.write(arr.tobytes())
|
||||
except BrokenPipeError:
|
||||
state.running = False
|
||||
return
|
||||
fifo.write(arr.tobytes())
|
||||
|
||||
def handle_ipc_client(conn, state):
|
||||
buffer = ""
|
||||
@@ -208,9 +168,6 @@ def main():
|
||||
|
||||
try:
|
||||
playback_thread(args.file, state)
|
||||
# Keep the main thread alive until Navidrome explicitly sends 'quit'
|
||||
while state.running:
|
||||
time.sleep(0.1)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user