Make nightcore and vaporwave rate-independent - #17
Merged
Conversation
asetrate reinterprets a stream's declared sample rate rather than scaling it, so hardcoding 48000 made the speed factor 48000*N/<source rate> - different for every track. Measured with real FFmpeg: source before after intended 48000 Hz 1.250x 1.250x 1.250x 44100 Hz 1.361x 1.250x 1.250x 32000 Hz 1.875x 1.250x 1.250x 22050 Hz 2.721x 1.250x 1.250x 44.1 kHz is extremely common (CD-derived uploads, much of SoundCloud), so most tracks were running ~9% fast, and low-rate uploads were unrecognisable. Normalising to 48 kHz before asetrate makes the constant correct by construction. Adds tests that render a tone through each preset and measure the result, since a wrong filter string looks perfectly reasonable and only manifests as audio. They also assert every preset is valid FFmpeg and that the non-speed effects leave duration untouched. CI now installs FFmpeg so these run rather than skipping, and pytest -ra surfaces any skip that does happen. Closes #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8
The bug
asetratereinterprets a stream's declared sample rate rather than scaling it, so hardcoding48000made the actual speed factor48000 * N / <source rate>— different for every track.Measured with real FFmpeg, a 2-second tone through the nightcore preset:
44.1 kHz is extremely common — CD-derived uploads and much of SoundCloud — so most tracks were running about 9% too fast, and low-rate uploads (older or spoken-word content) came out unrecognisable.
vaporwavewas wrong in the same way in the opposite direction.The fix
Normalise to 48 kHz before
asetrate, which makes the hardcoded constant correct by construction:The leading
aresampleis load-bearing, so there is a comment on it explaining why — it looks redundant otherwise and is exactly the kind of thing that gets "cleaned up" later.Verification
A wrong filter string looks perfectly reasonable on inspection and only manifests as audio, so the tests render a real tone through FFmpeg and measure the output. Duration comes from a byte count of raw 16-bit mono at 48 kHz — no ffprobe needed.
tests/test_effect_filters.pyadds 31 tests:nightcoreholds 1.25x andvaporwaveholds 0.8x across 48/44.1/32/22.05 kHz sources.test_the_hardcoded_form_really_was_rate_dependentpins the old behaviour (1.25x / 1.36x / 2.72x), documenting why the fix exists rather than leaving it as a claim in a commit message.180 passedoverall.CI
The workflow now installs FFmpeg. Without it these tests
skipifthemselves, which would let a broken filter sail through green CI — the opposite of what the suite is for.pytest -rais also added so any skip that does occur is visible in the log instead of hiding in a dot.Notes for review
nightcoreandvaporwaveuseasetrate; the other six presets (EQ, echo, karaoke, 8D) are rate-independent already and are unchanged.rubberband, which is a heavier dependency and a separate decision.