Skip to content
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

vol() method of the Transformer class should be able to handle negative gain values #133

Open
semins opened this issue Feb 11, 2021 · 1 comment

Comments

@semins
Copy link

semins commented Feb 11, 2021

Python package: sox==1.4.1
Python version: 3.6
OS: Windows 10
sox cmd line utility version: 14.4.2

The current implementation of the vol() method from the Transformer class throws an exception if the gain argument is set to a negative value. According to sox documentation from https://linux.die.net/man/1/sox it should be possible to set a negative gain value when is the gain type is selected as "amplitude" or "power".

One useful application of using a negative gain value is signal inversion. When I changed line 3558 as below and set the gain argument to -1 I was able to invert the input audio signal:

if gain_type in ['amplitude', 'power'] and gain < 0 and gain != -1:
raise ValueError(
"If gain_type = amplitude or power, gain must be positive."
)

Unless there is another way of performing signal inversion using another Transformer method, the above conditional statement can be modified to accept negative values.

@rabitt
Copy link
Collaborator

rabitt commented Feb 18, 2021

@semins Yep, you're right, it should accept negative values. Feel free to make a PR if you'd like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants