-
Notifications
You must be signed in to change notification settings - Fork 85
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
Audio filter that changes track volume #193
Conversation
// replace sample at index with volume adjusted value | ||
buffer.put( | ||
index, | ||
(buffer.get(index) * (BASE.pow(volume) -1 ) / (BASE - 1)).toInt().toShort() |
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.
Is this based on a common gain calculation? Hope it won't create unexpected noise/distortion.
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.
Yes. Audio volume is exponential, so I took an exponential formula from here: https://stackoverflow.com/questions/1165026/what-algorithms-could-i-use-for-audio-volume-level which seems to work well.
Distortion can happen, I don't think there is a way to prevent that. Furthermore, sometimes it can be done on purpose.
* - value <1 will lower the volume | ||
* - value >1 will increase it. One has to be careful with these, since large values may result in distortion. | ||
*/ | ||
class VolumeFilter(@FloatRange(from = 0.0) private val volume: Double) : BufferFilter{ |
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.
Filter
doesn't seem associated with audio processing (thinking about sound effect, boost, mixer, etc). Possible better naming?
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.
I couldn't really come up with better common naming for audio and video frame modifications. I guess "filter" works better with video because it became a common term with video/photo filters in popular apps. With audio "filters" have more of a "signal processing" meaning low/high pass filter, etc. Maybe we can keep "filter" terminology within LiTr?
Our first audio filter. Simplest one, changes track volume: