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

Improve audio interleaving #100

Merged
merged 2 commits into from
Dec 18, 2023
Merged

Conversation

yudori
Copy link
Contributor

@yudori yudori commented Nov 22, 2023

I found a pretty difficult-to-reproduce scenario where the interleaving code would get 'stuck' following line

result[index++] = input.getChannelData(channelIdx)[inputIndex];
where we're repeatedly calling input.getChannelData() potentially for millions of data in each audio channel.

I made the change to make this call only N times where N = number of channels and store the channel data in an array instead.

This PR also includes an early return in the interleaving code for scenarios where there's a single channel buffer which saves some memory and improves performance.

Copy link
Owner

@jaggad jaggad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some very minor stylistic nitpick preferences, but the change to the logic itself looks very good so I won't get bogged into that. Clear performance win.

@jaggad jaggad merged commit 5c1ab66 into jaggad:master Dec 18, 2023
3 checks passed
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