Skip to content

refactor: complex functions#1047

Open
closetcaiman wants to merge 28 commits intomainfrom
refactor/complex-functions
Open

refactor: complex functions#1047
closetcaiman wants to merge 28 commits intomainfrom
refactor/complex-functions

Conversation

@closetcaiman
Copy link
Copy Markdown
Contributor

Closes #

⚠️ Breaking changes ⚠️

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web
  • Updated old arch android spec file

@closetcaiman closetcaiman changed the title Refactor/complex functions refactor: complex functions May 4, 2026
Comment on lines +179 to +183
auto onBufferConsumed = [this, graphManager](
size_t bufferId,
std::shared_ptr<AudioBuffer> buffer,
bool isLastInQueue,
bool fireBufferEndedEvent) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use FatFunction here, because it will allocate on audio thread likely

Comment on lines +150 to +151
SingleBufferProcessor processor(
buffer_.get(), vReadIndex_, loop_, playbackRate, startFrame, endFrame);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i think there is no need to create a processor each render quantum, it can wrap some not frequently changed variables, such as buffer and loop

Comment on lines +46 to +47
[[nodiscard]] const AudioBuffer *getBuffer() const override;
[[nodiscard]] const AudioBuffer *getNextBuffer() const override;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's try to minimize the usage of raw ptrs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why still not shared_ptr?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auto framesNeededToStretch = std::abs(static_cast<int>(playbackRate * static_cast<float>(framesToProcess)));

has to be like that to allow negative playback rate values

@closetcaiman closetcaiman requested a review from mdydek May 5, 2026 18:29
Copy link
Copy Markdown
Collaborator

@mdydek mdydek left a comment

Choose a reason for hiding this comment

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

another argument against using #include <something> not #include "something" is that formatter is behaving differently when using "" and it looks very off


#include <cstddef>
#include <memory>
#include "audioapi/core/utils/buffer/SingleBufferProcessor.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "audioapi/core/utils/buffer/SingleBufferProcessor.h"
#include <audioapi/core/utils/buffer/SingleBufferProcessor.h>

const float currentSample = source[state.index];
const float nextSample = nextSource[state.nextIndex];
destination[writeIndex] = currentSample + state.factor * (nextSample - currentSample);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change

#include <algorithm>
#include <cstddef>
#include <memory>
#include "audioapi/core/utils/buffer/BufferProcessingDirection.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "audioapi/core/utils/buffer/BufferProcessingDirection.h"
#include <audioapi/core/utils/buffer/BufferProcessingDirection.h>

#include <list>
#include <memory>
#include <utility>
#include "audioapi/utils/FatFunction.hpp"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "audioapi/utils/FatFunction.hpp"
#include <audioapi/utils/FatFunction.hpp>

pls be aware of it

Comment on lines +46 to +47
[[nodiscard]] const AudioBuffer *getBuffer() const override;
[[nodiscard]] const AudioBuffer *getNextBuffer() const override;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why still not shared_ptr?

#include <audioapi/utils/Macros.h>
#include <cstddef>
#include <memory>
#include "audioapi/core/utils/buffer/BufferProcessingDirection.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "audioapi/core/utils/buffer/BufferProcessingDirection.h"
#include <audioapi/core/utils/buffer/BufferProcessingDirection.h>

Comment on lines +39 to +41
// queue buffer source
inline constexpr size_t ON_BUFFER_CONSUMED_CALLBACK_SIZE = 64;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think it can be safely moved to queue buffer source file, for sure it won't be used anywhere else and also is very "local"

#include <audioapi/core/utils/buffer/BufferProcessorBase.h>

#include <cstddef>
#include "audioapi/utils/AudioBuffer.hpp"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "audioapi/utils/AudioBuffer.hpp"
#include <audioapi/utils/AudioBuffer.hpp>

Comment on lines +155 to +156
processor_->setBuffer(buffer_.get());
processor_->setLoop(loop_);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

those values are not changing each render quantum, you can move those calls to appropriate node setters (f.e. update loop in processor only after setLoop is called on node)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants