-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functions to change compression level and bitrate mode. #447
Conversation
Very cool, thank you very much! But I think the |
…ameter of SoundFile.
Thank you for the review. I've moved them to parameter of SoundFile. Is that what you meant? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes. This looks better already.
But I think there's still a misunderstanding. As far as I can tell, we can't change the bitrate or compression of an already-opened file. Thus, we should make these items constructor arguments, and otherwise read-only.
But please do correct me if I'm misunderstanding this.
Additionally, SoundFile is still predominantly used with uncompressed files, where these settings make no sense. They should probably be hidden from the repr
where they're not applicable.
ah I had just finally started implementing the bitrate in a branch myself, glad to see this is already nearing completion |
@bastibe @sammlapp |
This looks really good, thank you very much! Just one more comment: If I'm reading this correctly, the compression/bitrate information is only available if it was passed to the constructor. But it's Is there a reasonable way of populating the two properties automatically if they were not given by the user? (Or perhaps I'm misunderstanding the code?) |
Firstly, if no arguments are specified, this is the default behaviour of libsndfile. This is the same behaviour as the current soundfile, so there should be no problem. Secondly, if you open pre-existing file, I don't know how to set these parameters. The libsndfile does not have a GET_COMPRESSION_LEVEL command, so I can't get the compression level. There is a GET_BITRATE_MODE command, so I should be able to get it for bitrate mode, but getting just that is not very useful. The sound quality will deteriorate as the lossy compression is repeated, so I personally think that the case of saving a file with the same compression as the opened file is not important. This function should generally be used when converting formats, or when saving edited sound files as a last step. |
I see. Well, without a GET_COMPRESSION_LEVEL command, we can't really display anything. In that case, the current state is good. Thank you! Just one more note before we merge: the test is currently broken on Python < 3.9, because it's using numpy.concat, which was not yet available. Could you fix that test? |
Sorry, not enough testing. This should be fine now. |
Thank you very, very much for your contribution! |
|
It's the libmp3lame specification used by libsndfile. As reported here, setting compression_level=1 with VBR causes libsndfile to return an error. |
Ok, perhaps this could be clarified in the docstring. Also, I'm adding a separate PR that just provides a demo of this functionality in the readme, @bastibe feel free to accept or reject, no offense taken if you reject :) |
Added interface to change compression level and bitrate mode as described in #390.
I was able to test it on Windows, but not on other platforms.