-
-
Notifications
You must be signed in to change notification settings - Fork 36
feat: audio node options in ctor #807
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for passing audio node options (channel configuration) in the GainNode constructor, aligning with the Web Audio API specification. The implementation spans TypeScript and C++ layers, introducing new type definitions and updating constructors to accept optional configuration parameters.
- Introduces
TAudioNodeOptionsandTGainOptionstypes for channel configuration - Updates
GainNodeconstructor to accept optional configuration parameters - Adds C++ parsing logic for audio node options from JavaScript
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-audio-api/src/types.ts | Adds new type definitions TAudioNodeOptions and TGainOptions for audio node configuration |
| packages/react-native-audio-api/src/interfaces.ts | Updates createGain method signature in IBaseAudioContext to accept TGainOptions parameter |
| packages/react-native-audio-api/src/defaults.ts | Defines default values for audio node and gain options |
| packages/react-native-audio-api/src/core/GainNode.ts | Refactors constructor to accept and merge options with defaults before creating the native node |
| packages/react-native-audio-api/src/core/BaseAudioContext.ts | Simplifies createGain method to delegate parameter handling to GainNode constructor |
| packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.h | Updates constructor signature to accept GainOptions parameter |
| packages/react-native-audio-api/common/cpp/audioapi/core/effects/GainNode.cpp | Updates constructor implementation to use options for initializing gain parameter and audio node properties |
| packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.h | Updates createGain method signature to accept GainOptions parameter |
| packages/react-native-audio-api/common/cpp/audioapi/core/BaseAudioContext.cpp | Updates createGain implementation to pass options to GainNode constructor |
| packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.h | Updates constructor to accept optional AudioNodeOptions parameter |
| packages/react-native-audio-api/common/cpp/audioapi/core/AudioNode.cpp | Implements conditional initialization of channel properties from options |
| packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h | Adds parsing functions to convert JavaScript option objects to C++ structs |
| packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptions.h | Defines C++ structs for AudioNodeOptions and GainOptions |
| packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp | Updates JSI binding to parse options from JavaScript before calling createGain |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/react-native-audio-api/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptionsParser.h
Outdated
Show resolved
Hide resolved
maciejmakowski2003
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks promising, @michalsek wdyt?
packages/react-native-audio-api/common/cpp/audioapi/core/effects/IIRFilterNode.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptions.h
Show resolved
Hide resolved
packages/react-native-audio-api/common/cpp/audioapi/HostObjects/utils/NodeOptions.h
Show resolved
Hide resolved
| explicit AudioBufferBaseSourceNode(BaseAudioContext *context, bool pitchCorrection); | ||
| explicit AudioBufferBaseSourceNode( | ||
| BaseAudioContext *context, | ||
| BaseAudioBufferSourceOptions options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here type gets sliced as explained before maybe const & ?
poneciak57
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job overall but i see some possible improvements
| class AudioNode : public std::enable_shared_from_this<AudioNode> { | ||
| public: | ||
| explicit AudioNode(BaseAudioContext *context); | ||
| // usually options are passed as derived class, keep in mind that object passed as options will be sliced |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is not entirely true, const AudioNodeOptions& is a reference type and it will not be sliced or copied or anything. But if someones defines
struct Base { int a; };
struct Derived : Base { int b; };
void fun1(Base b); // bad for bigger types
void fun2(const Base &b);
Derived d;
fun1(d); // it gets sliced and copied
fun2(d); // it does not get sliced or copied
Closes RNAA-297, RNAA-293
feedforward: number[], feedback: number[]instead of one object that encapsulated themnumberOfChannelspitchCorrectioninstread of optional one objectIntroduced changes
newkeyword with some possible option to manipulate its valuesLIST:
Checklist