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

Audio filter that changes track volume #193

Merged
merged 3 commits into from
May 23, 2022

Conversation

izzytwosheds
Copy link
Contributor

Our first audio filter. Simplest one, changes track volume:

  • takes a non-negative double value
  • 0 volume silences the track
  • volume 1 doesn't really change anything
  • value <1 reduces the volume
  • value >1 increases the volume
  • actual sample value change is exponential, since volume perception is logarithmic

// replace sample at index with volume adjusted value
buffer.put(
index,
(buffer.get(index) * (BASE.pow(volume) -1 ) / (BASE - 1)).toInt().toShort()
Copy link
Collaborator

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.

Copy link
Contributor Author

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{
Copy link
Collaborator

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?

Copy link
Contributor Author

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?

@izzytwosheds izzytwosheds merged commit b91d1ce into linkedin:main May 23, 2022
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

Successfully merging this pull request may close these issues.

2 participants