Prevent unnecessary memory copying in nvwave#19791
Conversation
SaschaCowley
left a comment
There was a problem hiding this comment.
This change would have been made due to a ctypes type incompatibility, but I don't remember the specific trigger. I'll see if I can find it, because I am reasonably sure I tried this and it didn't work.
|
I tried the launcher built by GitHub Actions. At least all the built-in synths work on my system. Before the 64-bit transition, After searching the codebase, I found those possible data types for the
And casting to I might need to dig deeper. |
|
@SaschaCowley Or what about changing the Using
Wave buffers can be an array of raw bytes, or an array of 16-bit samples, but actually we don't care about the exact "data type", we just want to send the raw bytes to the system. If we use |
This comment was marked as outdated.
This comment was marked as outdated.
|
@gexgd0419 - is this ready for review? |
|
I think this was waiting on me to try and find why we went with this approach in the first place. Unfortunately I've lost that branch, so I'm not sure. |
There was a problem hiding this comment.
Pull request overview
This PR aims to avoid unnecessary audio-buffer copying in WavePlayer.feed by removing the ctypes.string_at(...) conversion and instead passing a pointer directly to wasapi.wasPlay_feed.
Changes:
- Replace
string_at-based conversion with an explicit ctypes pointer cast before callingwasPlay_feed. - Update
ctypesimports accordingly (c_char_p,cast).
Link to issue number:
None
Summary of the issue:
#18207 introduced these two lines in
nvwave.py:string_atcreates another copy of the data buffer stored asbytes, which is not needed, since it will only be passed towasPlay_feed. As many built-in synths pass inc_void_por actypearray instead ofbytes, this would create a lot of unnecessary memory copies.datashould be passed towasPlay_feeddirectly if possible.As it turned out, those two lines were added because of the
argtypesset forwasPlay_feed:c_void_pcannot be implicitly converted toc_char_p, sostring_atwas added as a fix.Description of user facing changes:
None.
Description of developer facing changes:
None.
datastill accepts anything convertible toc_void_pandbytes.Description of development approach:
This PR chooses another way to fix that problem: cast
datatoc_char_pexplicitly. Anything that can be converted toc_void_pcan be converted toc_char_pthis way, includingc_void_p,bytes, andctypesarray.Testing strategy:
Tested manually.
Known issues with pull request:
None
Code Review Checklist: