Several changes to the read() and write() methods (alternative)#37
Several changes to the read() and write() methods (alternative)#37
Conversation
Replace ffi.new() with np.empty() and np.ascontiguousarray() Remove dicts for readers/writers read(): * reserve only as much memory as needed (if 'frames' is too large) * check return value of sf_readf_*() write(): * avoid copy if data has already the correct memory layout * check return value of sf_writef_*() * don't return the number of written frames! This is for symmetry with read() and it's redundant information anyway As the written frames are now checked in the write() method, the same check was removed from the write() *function*.
If less frames are left in the file than would fit into out and fill_value=None, a smaller view into out is returned that contains only the valid frames.
- pysoundfile is not imported into the global namespace any longer, since that would overwrite `open`. - Split the test class into subclasses
- removed `channels_first`. - split read into `read` and `readinto`. - removed many helper functions that were not needed any longer. - added tests for `fill_value` and EOF behavior.
readinto can thus be turned into a private method
These issues should be addressed now. This is a fork of #34, which does not need the Also, this fork is mostly tested. |
|
This is starting to get confusing ...
#34 is quite outdated, because I created #36 (following your suggestion, @bastibe). Currently it's hard to see the differences regarding the functions. |
pysoundfile.py
Outdated
There was a problem hiding this comment.
This is the third time that self.frames - current_frame is calculated (the others being in line 622 and 624). I guess this is a code smell.
There was a problem hiding this comment.
You said the same somewhere else. I'll amend it.
|
I fixed most of your comments. Thank you! BTW, that test suite is invaluable! |
|
Sorry about the confusion with #34, #36, and #37. This pull request was supposed to be for discussion purposes mostly. I think we did settle on an API for |
|
OK, I can ignore the functions. I found this quite interesting: |
|
Very interesting indeed. I missed the fact that there are many similarities between the error checking in Actually, this made |
|
This has been superceded by #36 |
This implements several changes to the
read()andwrite()methods.always_2dargument toread()outargument toread()fill_valueargument toread()read()andwrite()functions