Fix delay caused by python I/O buffering#38
Conversation
There was a problem hiding this comment.
Thanks for your PR. Can you explain in detail what change addresses which issue? In particular, removing SETPIPE_SZ means that the pipe size is 65536 bytes, whereas before it was constrained to 4096 bytes, so this seems to add some buffering (hence latency that can build up over time until the pipe is full).
| echo '[+] Loading PulseAudio module' | ||
|
|
||
| pactl load-module module-pipe-source source_name="$AUDIOSOURCE_NAME" channels=1 format=s16 rate=44100 file="/tmp/$AUDIOSOURCE_NAME" | ||
| pactl load-module module-pipe-source source_name="$AUDIOSOURCE_NAME" channels=1 format=s16 rate=48000 file="/tmp/$AUDIOSOURCE_NAME" |
There was a problem hiding this comment.
Doesn't match what is requested by the app
There was a problem hiding this comment.
True I changed it back to the 44100 in the new PR update.
I tried to set it to 48000 since its the default Pipewire sample rate, though I noticed it was ruining the audio because I didn't change the app rate. thank you for pointing it out for me.
keeping it on 44100 is perfectly fine.
| except BlockingIOError: | ||
| pass | ||
| os.write(out_fd, data) | ||
| except (BlockingIOError, BrokenPipeError): |
There was a problem hiding this comment.
Is it to hide the exception when disconnecting?
| while True: | ||
| n = inp.recv_into(buf, BUF_SIZE, socket.MSG_WAITALL) | ||
| try: | ||
| data = inp.recv(BUF_SIZE) |
There was a problem hiding this comment.
I think this allocates a new buffer for each iteration.
|
Thank you for building this amazing project. There was roughly a one second input delay, likely caused by the internal python I/O buffering in the line |
Co-authored-by: Farsad <far.sad.shift@gmail.com>
|
@FarsadM Really appreciate you digging into this issue, great contribution, thanks! |
Fixes Issue #36