Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

aubuf: preallocate mbuf frames to avoid malloc #55

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

Conversation

sreimers
Copy link
Member

@sreimers sreimers commented May 25, 2022

malloc and free calls should be avoided in realtime audio context as much as possible. this makes aubuf write/read calls ~1.8x times faster.

@@ -42,7 +40,14 @@ static inline int aubuf_write(struct aubuf *ab, const uint8_t *p, size_t sz)

static inline int aubuf_append(struct aubuf *ab, struct mbuf *mb)
Copy link
Contributor

Choose a reason for hiding this comment

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

this API should probably be removed.

it contains no Samplerate or Channels info, which is needed now

/* Values for startup preallocation, can be tuned if needed */
enum {
SRATE = 48000, /* Default sample rate in [Hz] */
CHANNELS = 2, /* Default number of channels */
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to avoid hardcoded samplerate values inside the library ?

struct frame *f = frame_alloc(ab, SAMPSZ);
if (!f)
return ENOMEM;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of pre-allocating, is it possible to reuse the buffer instead ?

@cspiel1
Copy link
Collaborator

cspiel1 commented Jan 10, 2023

I'd like to vote again for this improvement (maybe simplified somehow). After planned v2.11.0?

@sreimers
Copy link
Member Author

Yes, will take a look into this for next release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants