Skip to content

feat(audiotrack): lockless buffer #656

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

anunaym14
Copy link
Member

Noticing some crackling noise, debugging that. The audio otherwise seems to be in the correct order.


import (
"runtime"
"sync/atomic"
Copy link
Contributor

Choose a reason for hiding this comment

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

We standardise on uber atomic. It is nicer to use.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha, will replace.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Comment on lines +28 to +34
capacity--
capacity |= capacity >> 1
capacity |= capacity >> 2
capacity |= capacity >> 4
capacity |= capacity >> 8
capacity |= capacity >> 16
capacity++
Copy link
Contributor

Choose a reason for hiding this comment

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

bits.Len32

Comment on lines +13 to +14
head *atomic.Uint32
tail *atomic.Uint32
Copy link
Contributor

@paulwe paulwe May 13, 2025

Choose a reason for hiding this comment

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

these are zero initialized automatically so you can avoid the extra indirection and skip initializing with New(0) if these are atomic.Uint32 instead of *atomic.Uint32

Comment on lines +265 to +268
for i := uint32(0); i < currentBatchSize; i++ {
slotIndex := (head + i) & cb.mask
result = append(result, cb.buffer[slotIndex])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be implemented in at most 2 copies? after head has been updated is the read range safe from concurrent writes?

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.

3 participants