playback: use isactive in replaygain [#174]
Override isActive to control when the ReplayGain engine should manipulate audio. This makes the system much more efficient, as we can side-step a useless copy when ReplayGain shouldn't be applied.
This commit is contained in:
parent
efd24a4fee
commit
c3721266b5
3 changed files with 18 additions and 19 deletions
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#### What's Improved
|
#### What's Improved
|
||||||
- Made "timeline" elements (like playback controls) always left-to-right
|
- Made "timeline" elements (like playback controls) always left-to-right
|
||||||
|
- Improved performance when ReplayGain is not enabled
|
||||||
|
|
||||||
#### What's Fixed
|
#### What's Fixed
|
||||||
- Fixed broken tablet layouts
|
- Fixed broken tablet layouts
|
||||||
|
@ -16,6 +17,7 @@
|
||||||
- Fixed miscellanious startup issues
|
- Fixed miscellanious startup issues
|
||||||
- Fixed crash if settings was navigated away before playback state
|
- Fixed crash if settings was navigated away before playback state
|
||||||
finished saving
|
finished saving
|
||||||
|
- Fixed broken album menu
|
||||||
|
|
||||||
#### What's Changed
|
#### What's Changed
|
||||||
- Reworked typography and iconography to be more aligned with material
|
- Reworked typography and iconography to be more aligned with material
|
||||||
|
|
|
@ -218,29 +218,26 @@ class ReplayGainAudioProcessor(context: Context) : BaseAudioProcessor() {
|
||||||
throw AudioProcessor.UnhandledAudioFormatException(inputAudioFormat)
|
throw AudioProcessor.UnhandledAudioFormatException(inputAudioFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isActive() = super.isActive() && volume != 1f
|
||||||
|
|
||||||
override fun queueInput(inputBuffer: ByteBuffer) {
|
override fun queueInput(inputBuffer: ByteBuffer) {
|
||||||
val position = inputBuffer.position()
|
val position = inputBuffer.position()
|
||||||
val limit = inputBuffer.limit()
|
val limit = inputBuffer.limit()
|
||||||
val size = limit - position
|
val size = limit - position
|
||||||
val buffer = replaceOutputBuffer(size)
|
val buffer = replaceOutputBuffer(size)
|
||||||
|
|
||||||
if (volume == 1f) {
|
for (i in position until limit step 2) {
|
||||||
// No need to apply ReplayGain.
|
// Ensure we clamp the values to the minimum and maximum values possible
|
||||||
buffer.put(inputBuffer.slice())
|
// for the encoding. This prevents issues where samples amplified beyond
|
||||||
} else {
|
// 1 << 16 will end up becoming truncated during the conversion to a short,
|
||||||
for (i in position until limit step 2) {
|
// resulting in popping.
|
||||||
// Ensure we clamp the values to the minimum and maximum values possible
|
var sample = inputBuffer.getLeShort(i)
|
||||||
// for the encoding. This prevents issues where samples amplified beyond
|
sample =
|
||||||
// 1 << 16 will end up becoming truncated during the conversion to a short,
|
(sample * volume)
|
||||||
// resulting in popping.
|
.toInt()
|
||||||
var sample = inputBuffer.getLeShort(i)
|
.clamp(Short.MIN_VALUE.toInt(), Short.MAX_VALUE.toInt())
|
||||||
sample =
|
.toShort()
|
||||||
(sample * volume)
|
buffer.putLeShort(sample)
|
||||||
.toInt()
|
|
||||||
.clamp(Short.MIN_VALUE.toInt(), Short.MAX_VALUE.toInt())
|
|
||||||
.toShort()
|
|
||||||
buffer.putLeShort(sample)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inputBuffer.position(limit)
|
inputBuffer.position(limit)
|
||||||
|
|
|
@ -66,8 +66,8 @@
|
||||||
android:id="@+id/playback_seek_bar"
|
android:id="@+id/playback_seek_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="@dimen/spacing_medium"
|
android:layout_marginStart="@dimen/spacing_small"
|
||||||
android:layout_marginEnd="@dimen/spacing_medium"
|
android:layout_marginEnd="@dimen/spacing_small"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/playback_controls_container"
|
app:layout_constraintBottom_toTopOf="@+id/playback_controls_container"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0.0"
|
app:layout_constraintHorizontal_bias="0.0"
|
||||||
|
|
Loading…
Reference in a new issue