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

wip: avoiding repeated copying of audio in speedup #746

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lumip
Copy link

@lumip lumip commented Jul 25, 2023

Issue #736 demonstrates that the speedup effect function becomes prohibitively slow for long audio segments. This is due to the loop in lines 90,91 of the speedup function ( pydub/effects.py ), where the shortened chunks are appended using AudioSegment.append, which result in repeated copying (and necessary memory allocations) of the already processed part for creating of a new immutable AudioSegment for each chunk.

This PR shows a much more performant way by essentially copying the byte logic of AudioSegment.append into speedup. For the example given in issue #736 , this completes in about 11 seconds. However, the current implementation does not currently deal with a variety of corner cases around the length of chunks and crossfading which was previously elegantly (but imperformantly) solved by abstracting through AudioSegment.append. Also, the introduced code duplication is not ideal.

Therefore, this PR draft is mostly meant to start a discussion on how to approach this best. The main problem of the old approach lies in the immutability and the corresponding copying of AudioSegments. Maybe seperating some of the composition routines (append, overlay, fade, etc) to work on preallocated low-level buffers could be a way to avoid duplication while still getting good performance?

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.

1 participant