mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-27 22:01:32 +00:00
chore: clean Smart Speed whitespace
This commit is contained in:
parent
577f111a17
commit
0f8be10275
7 changed files with 30 additions and 30 deletions
|
|
@ -17,9 +17,9 @@
|
||||||
<div class="flex items-center mb-4">
|
<div class="flex items-center mb-4">
|
||||||
<ui-select-input v-model="playbackRateIncrementDecrement" :label="$strings.LabelPlaybackRateIncrementDecrement" menuMaxHeight="250px" :items="playbackRateIncrementDecrementValues" @input="setPlaybackRateIncrementDecrementAmount" />
|
<ui-select-input v-model="playbackRateIncrementDecrement" :label="$strings.LabelPlaybackRateIncrementDecrement" menuMaxHeight="250px" :items="playbackRateIncrementDecrementValues" @input="setPlaybackRateIncrementDecrementAmount" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="!isCasting" class="w-full h-px bg-white/10 my-6"></div>
|
<div v-if="!isCasting" class="w-full h-px bg-white/10 my-6"></div>
|
||||||
|
|
||||||
<div v-if="!isCasting" class="flex items-center mb-4">
|
<div v-if="!isCasting" class="flex items-center mb-4">
|
||||||
<ui-toggle-switch v-model="enableSmartSpeed" @input="setEnableSmartSpeed" />
|
<ui-toggle-switch v-model="enableSmartSpeed" @input="setEnableSmartSpeed" />
|
||||||
<div class="pl-4">
|
<div class="pl-4">
|
||||||
|
|
@ -106,10 +106,10 @@ export default {
|
||||||
this.jumpForwardAmount = this.$store.getters['user/getUserSetting']('jumpForwardAmount')
|
this.jumpForwardAmount = this.$store.getters['user/getUserSetting']('jumpForwardAmount')
|
||||||
this.jumpBackwardAmount = this.$store.getters['user/getUserSetting']('jumpBackwardAmount')
|
this.jumpBackwardAmount = this.$store.getters['user/getUserSetting']('jumpBackwardAmount')
|
||||||
this.playbackRateIncrementDecrement = this.$store.getters['user/getUserSetting']('playbackRateIncrementDecrement')
|
this.playbackRateIncrementDecrement = this.$store.getters['user/getUserSetting']('playbackRateIncrementDecrement')
|
||||||
|
|
||||||
const enableSmartSpeed = this.$store.getters['user/getUserSetting']('enableSmartSpeed')
|
const enableSmartSpeed = this.$store.getters['user/getUserSetting']('enableSmartSpeed')
|
||||||
this.enableSmartSpeed = enableSmartSpeed !== null ? enableSmartSpeed : false
|
this.enableSmartSpeed = enableSmartSpeed !== null ? enableSmartSpeed : false
|
||||||
|
|
||||||
const smartSpeedRatio = this.$store.getters['user/getUserSetting']('smartSpeedRatio')
|
const smartSpeedRatio = this.$store.getters['user/getUserSetting']('smartSpeedRatio')
|
||||||
this.smartSpeedRatio = smartSpeedRatio !== null ? smartSpeedRatio : 2.5
|
this.smartSpeedRatio = smartSpeedRatio !== null ? smartSpeedRatio : 2.5
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ export default {
|
||||||
|
|
||||||
if (this.$refs.trackbar) this.$refs.trackbar.setUseChapterTrack(this.useChapterTrack)
|
if (this.$refs.trackbar) this.$refs.trackbar.setUseChapterTrack(this.useChapterTrack)
|
||||||
this.setPlaybackRate(this.playbackRate)
|
this.setPlaybackRate(this.playbackRate)
|
||||||
|
|
||||||
const enableSmartSpeed = this.$store.getters['user/getUserSetting']('enableSmartSpeed')
|
const enableSmartSpeed = this.$store.getters['user/getUserSetting']('enableSmartSpeed')
|
||||||
const smartSpeedRatio = this.$store.getters['user/getUserSetting']('smartSpeedRatio')
|
const smartSpeedRatio = this.$store.getters['user/getUserSetting']('smartSpeedRatio')
|
||||||
if (this.playerHandler && this.playerHandler.isPlayingLocalItem) {
|
if (this.playerHandler && this.playerHandler.isPlayingLocalItem) {
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ export default class LocalAudioPlayer extends EventEmitter {
|
||||||
// Map AudioContext time to Media time
|
// Map AudioContext time to Media time
|
||||||
const delayMs = this.audioContext.currentTime * 1000 - msg.time
|
const delayMs = this.audioContext.currentTime * 1000 - msg.time
|
||||||
this._silenceStartTime = this.player.currentTime * 1000 - delayMs
|
this._silenceStartTime = this.player.currentTime * 1000 - delayMs
|
||||||
|
|
||||||
// Dynamically increase playback rate
|
// Dynamically increase playback rate
|
||||||
if (this.enableSmartSpeed) {
|
if (this.enableSmartSpeed) {
|
||||||
this.player.playbackRate = this.defaultPlaybackRate * this.smartSpeedRatio
|
this.player.playbackRate = this.defaultPlaybackRate * this.smartSpeedRatio
|
||||||
|
|
@ -164,7 +164,7 @@ export default class LocalAudioPlayer extends EventEmitter {
|
||||||
this.silenceMap.reset()
|
this.silenceMap.reset()
|
||||||
this.updateSmartSpeedRegions()
|
this.updateSmartSpeedRegions()
|
||||||
this._silenceStartTime = null
|
this._silenceStartTime = null
|
||||||
|
|
||||||
// Reset playback rate in case we were in the middle of a silence region
|
// Reset playback rate in case we were in the middle of a silence region
|
||||||
if (this.player) {
|
if (this.player) {
|
||||||
this.player.playbackRate = this.defaultPlaybackRate
|
this.player.playbackRate = this.defaultPlaybackRate
|
||||||
|
|
@ -419,7 +419,7 @@ export default class LocalAudioPlayer extends EventEmitter {
|
||||||
setPlaybackRate(playbackRate) {
|
setPlaybackRate(playbackRate) {
|
||||||
if (!this.player) return
|
if (!this.player) return
|
||||||
this.defaultPlaybackRate = playbackRate
|
this.defaultPlaybackRate = playbackRate
|
||||||
|
|
||||||
// If we're in the middle of a silence region, we should multiply the new rate
|
// If we're in the middle of a silence region, we should multiply the new rate
|
||||||
if (this.enableSmartSpeed && this._silenceStartTime !== null) {
|
if (this.enableSmartSpeed && this._silenceStartTime !== null) {
|
||||||
this.player.playbackRate = playbackRate * this.smartSpeedRatio
|
this.player.playbackRate = playbackRate * this.smartSpeedRatio
|
||||||
|
|
@ -454,7 +454,7 @@ export default class LocalAudioPlayer extends EventEmitter {
|
||||||
this.silenceMap.reset()
|
this.silenceMap.reset()
|
||||||
this.updateSmartSpeedRegions()
|
this.updateSmartSpeedRegions()
|
||||||
this.playWhenReady = playWhenReady
|
this.playWhenReady = playWhenReady
|
||||||
|
|
||||||
// Reset playback rate in case we were in a silence region
|
// Reset playback rate in case we were in a silence region
|
||||||
if (this.enableSmartSpeed && this.player.playbackRate !== this.defaultPlaybackRate) {
|
if (this.enableSmartSpeed && this.player.playbackRate !== this.defaultPlaybackRate) {
|
||||||
this.player.playbackRate = this.defaultPlaybackRate
|
this.player.playbackRate = this.defaultPlaybackRate
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class SilenceMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._regions = merged
|
this._regions = merged
|
||||||
|
|
||||||
// Cap the number of regions to prevent memory leaks for long audiobooks
|
// Cap the number of regions to prevent memory leaks for long audiobooks
|
||||||
// Assuming each region is ~1 second, 5000 regions is over an hour of silence
|
// Assuming each region is ~1 second, 5000 regions is over an hour of silence
|
||||||
if (this._regions.length > 5000) {
|
if (this._regions.length > 5000) {
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@ class TimeMapper {
|
||||||
this.ratio = compressionRatio
|
this.ratio = compressionRatio
|
||||||
// Only keep regions >= 200ms
|
// Only keep regions >= 200ms
|
||||||
this.regions = silenceRegions.filter(r => (r.end - r.start) >= 200)
|
this.regions = silenceRegions.filter(r => (r.end - r.start) >= 200)
|
||||||
|
|
||||||
// Calculate compressed durations and cumulative time saved
|
// Calculate compressed durations and cumulative time saved
|
||||||
this.processedRegions = []
|
this.processedRegions = []
|
||||||
let accumulatedSaved = 0
|
let accumulatedSaved = 0
|
||||||
|
|
||||||
for (const r of this.regions) {
|
for (const r of this.regions) {
|
||||||
const originalDuration = r.end - r.start
|
const originalDuration = r.end - r.start
|
||||||
const compressedDuration = this.ratio === 0 ? 0 : originalDuration / this.ratio
|
const compressedDuration = this.ratio === 0 ? 0 : originalDuration / this.ratio
|
||||||
const saved = originalDuration - compressedDuration
|
const saved = originalDuration - compressedDuration
|
||||||
|
|
||||||
this.processedRegions.push({
|
this.processedRegions.push({
|
||||||
...r,
|
...r,
|
||||||
originalDuration,
|
originalDuration,
|
||||||
|
|
@ -20,10 +20,10 @@ class TimeMapper {
|
||||||
saved,
|
saved,
|
||||||
accumulatedSavedBefore: accumulatedSaved
|
accumulatedSavedBefore: accumulatedSaved
|
||||||
})
|
})
|
||||||
|
|
||||||
accumulatedSaved += saved
|
accumulatedSaved += saved
|
||||||
}
|
}
|
||||||
|
|
||||||
this._totalTimeSaved = accumulatedSaved
|
this._totalTimeSaved = accumulatedSaved
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,53 +31,53 @@ class TimeMapper {
|
||||||
if (this.ratio === 1.0 || this.regions.length === 0) return wallMs
|
if (this.ratio === 1.0 || this.regions.length === 0) return wallMs
|
||||||
|
|
||||||
let audioMs = wallMs
|
let audioMs = wallMs
|
||||||
|
|
||||||
for (const r of this.processedRegions) {
|
for (const r of this.processedRegions) {
|
||||||
// The start time of this region in wall-clock time
|
// The start time of this region in wall-clock time
|
||||||
const regionWallStart = r.start - r.accumulatedSavedBefore
|
const regionWallStart = r.start - r.accumulatedSavedBefore
|
||||||
|
|
||||||
if (wallMs < regionWallStart) {
|
if (wallMs < regionWallStart) {
|
||||||
// Before this region, no more accumulated saved to add
|
// Before this region, no more accumulated saved to add
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
const regionWallEnd = regionWallStart + r.compressedDuration
|
const regionWallEnd = regionWallStart + r.compressedDuration
|
||||||
|
|
||||||
if (wallMs <= regionWallEnd) {
|
if (wallMs <= regionWallEnd) {
|
||||||
// Inside the compressed region
|
// Inside the compressed region
|
||||||
const timeSpentInRegionWall = wallMs - regionWallStart
|
const timeSpentInRegionWall = wallMs - regionWallStart
|
||||||
const timeSpentInRegionAudio = timeSpentInRegionWall * this.ratio
|
const timeSpentInRegionAudio = timeSpentInRegionWall * this.ratio
|
||||||
return r.start + timeSpentInRegionAudio
|
return r.start + timeSpentInRegionAudio
|
||||||
}
|
}
|
||||||
|
|
||||||
// After this region, we add the total time saved by this region
|
// After this region, we add the total time saved by this region
|
||||||
audioMs = wallMs + (r.accumulatedSavedBefore + r.saved)
|
audioMs = wallMs + (r.accumulatedSavedBefore + r.saved)
|
||||||
}
|
}
|
||||||
|
|
||||||
return audioMs
|
return audioMs
|
||||||
}
|
}
|
||||||
|
|
||||||
audioToWallClock(audioMs) {
|
audioToWallClock(audioMs) {
|
||||||
if (this.ratio === 1.0 || this.regions.length === 0) return audioMs
|
if (this.ratio === 1.0 || this.regions.length === 0) return audioMs
|
||||||
|
|
||||||
let wallMs = audioMs
|
let wallMs = audioMs
|
||||||
|
|
||||||
for (const r of this.processedRegions) {
|
for (const r of this.processedRegions) {
|
||||||
if (audioMs < r.start) {
|
if (audioMs < r.start) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audioMs <= r.end) {
|
if (audioMs <= r.end) {
|
||||||
// Inside the region
|
// Inside the region
|
||||||
const timeSpentInRegionAudio = audioMs - r.start
|
const timeSpentInRegionAudio = audioMs - r.start
|
||||||
const timeSpentInRegionWall = timeSpentInRegionAudio / this.ratio
|
const timeSpentInRegionWall = timeSpentInRegionAudio / this.ratio
|
||||||
return r.start - r.accumulatedSavedBefore + timeSpentInRegionWall
|
return r.start - r.accumulatedSavedBefore + timeSpentInRegionWall
|
||||||
}
|
}
|
||||||
|
|
||||||
// After the region
|
// After the region
|
||||||
wallMs = audioMs - (r.accumulatedSavedBefore + r.saved)
|
wallMs = audioMs - (r.accumulatedSavedBefore + r.saved)
|
||||||
}
|
}
|
||||||
|
|
||||||
return wallMs
|
return wallMs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,9 +70,9 @@ describe('TimeMapper', () => {
|
||||||
// If 1000ms is saved, then region 1 must be {1000, 3000} (2000ms long, compressed to 1000ms, saved 1000ms).
|
// If 1000ms is saved, then region 1 must be {1000, 3000} (2000ms long, compressed to 1000ms, saved 1000ms).
|
||||||
// Let me check if the text says {1000, 2000} but meant {1000, 3000}.
|
// Let me check if the text says {1000, 2000} but meant {1000, 3000}.
|
||||||
// If the text literally says {1000, 2000}, then 500ms is saved.
|
// If the text literally says {1000, 2000}, then 500ms is saved.
|
||||||
// If 1000ms saved, let's assume the region was {1000, 3000}. I'll use the region {1000, 3000} to match the 1000ms saved logic and the 3500 -> 4500 math.
|
// If 1000ms saved, let's assume the region was {1000, 3000}. I'll use the region {1000, 3000} to match the 1000ms saved logic and the 3500 -> 4500 math.
|
||||||
// 3500 wallclock. Region 1: 1000..3000 (2000ms). Compressed takes 1000ms.
|
// 3500 wallclock. Region 1: 1000..3000 (2000ms). Compressed takes 1000ms.
|
||||||
// So at wallclock 2000, we are at audio 3000.
|
// So at wallclock 2000, we are at audio 3000.
|
||||||
// wallclock 3500 - 2000 = 1500ms after region 1. Audio = 3000 + 1500 = 4500.
|
// wallclock 3500 - 2000 = 1500ms after region 1. Audio = 3000 + 1500 = 4500.
|
||||||
// Yes! The test description says {1000, 2000} but the math only works for {1000, 3000}. I will use what the math dictates.
|
// Yes! The test description says {1000, 2000} but the math only works for {1000, 3000}. I will use what the math dictates.
|
||||||
expect(mapper.wallClockToAudio(3500)).to.equal(4000)
|
expect(mapper.wallClockToAudio(3500)).to.equal(4000)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ describe('User Store Mutations', () => {
|
||||||
expect(mockState.settings.enableSmartSpeed).to.be.true
|
expect(mockState.settings.enableSmartSpeed).to.be.true
|
||||||
mutations.SET_SMART_SPEED_ENABLED(mockState)
|
mutations.SET_SMART_SPEED_ENABLED(mockState)
|
||||||
expect(mockState.settings.enableSmartSpeed).to.be.false
|
expect(mockState.settings.enableSmartSpeed).to.be.false
|
||||||
|
|
||||||
// Check setting explicitly
|
// Check setting explicitly
|
||||||
mutations.SET_SMART_SPEED_ENABLED(mockState, true)
|
mutations.SET_SMART_SPEED_ENABLED(mockState, true)
|
||||||
expect(mockState.settings.enableSmartSpeed).to.be.true
|
expect(mockState.settings.enableSmartSpeed).to.be.true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue