|
MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
|
A one dimensional acoustic duct of any bore shape, solved by finite differences, with a termination at each end. More...
#include <DuctNetwork.hpp>
Classes | |
| struct | Losses |
| struct | Prepared |
| struct | Profile |
Public Types | |
| using | Controls = DuctControls |
| enum class | Output : uint8_t { RADIATED , PICKUP } |
| What the network publishes. More... | |
Public Member Functions | |
| DuctNetwork (const DuctNetwork &)=delete | |
| DuctNetwork (double length, const std::vector< double > &radii, double sample_rate=48000.0) | |
| A duct from radii sampled evenly along its length. | |
| DuctNetwork (double length, double radius, double sample_rate=48000.0) | |
| A cylinder. | |
| DuctNetwork (double length, std::function< double(double)> radius, double sample_rate=48000.0) | |
| A duct from a radius function. | |
| DuctNetwork (DuctNetwork &&)=delete | |
| std::shared_ptr< TerminationOperator > | get_bell () const |
| std::unordered_map< std::string, std::string > | get_metadata () const override |
| Get network metadata for debugging/visualization. | |
| std::shared_ptr< TerminationOperator > | get_mouth () const |
| std::optional< std::span< const double > > | get_node_audio_buffer (size_t index) const override |
| Get output of specific internal node as audio buffer (for ONE_TO_ONE mapping). | |
| size_t | get_node_count () const override |
| Number of pressure points along the duct. | |
| std::optional< double > | get_node_output (size_t index) const override |
| Pressure at one point along the duct, from the last block. | |
| void | initialize () override |
| Called once before first process_batch(). | |
| void | map_parameter (const std::string ¶m_name, const std::shared_ptr< Node > &source, MappingMode mode=MappingMode::BROADCAST) override |
| Map external node output to network parameter. | |
| void | map_parameter (const std::string ¶m_name, const std::shared_ptr< NodeNetwork > &source) override |
| Map external node network to network parameters (ONE_TO_ONE). | |
| DuctNetwork & | operator= (const DuctNetwork &)=delete |
| DuctNetwork & | operator= (DuctNetwork &&)=delete |
| std::vector< double > | pressure_field () const |
| Copy of the pressures along the duct from the last block. | |
| void | process_batch (unsigned int num_samples) override |
| Process the network for the given number of samples. | |
| void | read_controls (DuctControls &controls) const |
| Fills the controls whose value the network holds outside the struct. | |
| void | reset () override |
| Return the duct to rest, installed at the next block. | |
| bool | set_bell (std::shared_ptr< TerminationOperator > termination) |
| Replace the termination at the bell. | |
| bool | set_length (double length) |
| Change the length in metres, keeping the profile. | |
| bool | set_mouth (std::shared_ptr< TerminationOperator > termination) |
| Replace the termination at the mouth. | |
| bool | set_mouth_volume (double volume) |
| Add air behind the mouth end, in cubic metres. | |
| bool | set_profile (const std::vector< double > &radii) |
| Replace the profile with radii sampled evenly from mouth to bell. | |
| bool | set_profile (std::function< double(double)> radius) |
| Replace the profile with a radius function of distance from the mouth. | |
| bool | set_radius (double radius) |
| Make the duct a cylinder of this radius in metres. | |
| bool | set_wall_losses (double friction, double viscosity) |
| Set the wall losses by hand. | |
| void | unmap_parameter (const std::string ¶m_name) override |
| Remove parameter mapping. | |
| bool | use_viscothermal_losses () |
| Take the wall losses from the duct's mean radius, fitted to the viscothermal attenuation of a tube at 150 Hz and 3 kHz. | |
| ~DuctNetwork () override | |
| Public Member Functions inherited from MayaFlux::Nodes::Network::NodeNetwork | |
| template<typename Op, typename Self, typename... Args> | |
| std::shared_ptr< Op > | add (this Self &self, Args &&... args) |
| Construct an operator, append it to this network's chain and return it. | |
| void | add_channel_usage (uint32_t channel_id) |
| Register network usage on a specific channel. | |
| void | clear_timestep () |
| Return to the frame period. | |
| template<typename Self> | |
| Self::Controls | get (this const Self &self) |
| The controls with the values the network holds now. | |
| virtual std::optional< std::vector< double > > | get_audio_buffer () const |
| Get cached audio buffer from last process_batch(). | |
| uint32_t | get_block_size () const |
| uint32_t | get_channel_mask () const |
| Get channel mask (bitfield of registered channels). | |
| uint32_t | get_frame_rate () const |
| virtual NetworkOperator * | get_operator () |
| virtual const NetworkOperator * | get_operator () const |
| std::shared_ptr< OperatorChain > | get_operator_chain () const |
| Access this network's operator chain. | |
| OutputMode | get_output_mode () const |
| Get the current output routing mode. | |
| double | get_output_scale () const |
| Get the current output scale factor. | |
| std::vector< uint32_t > | get_registered_channels () const |
| Get all channels this network is registered on. | |
| RoutingState & | get_routing_state () |
| Retrieves the current routing state of the network (non-const). | |
| const RoutingState & | get_routing_state () const |
| Retrieves the current routing state of the network. | |
| uint32_t | get_sample_rate () const |
| float | get_timestep () const |
| Seconds one visual frame advances this network. | |
| Topology | get_topology () const |
| Get the current topology. | |
| virtual bool | has_operator () const |
| bool | is_enabled () const |
| Check if network is enabled. | |
| bool | is_processed_this_cycle () const |
| Check if network has been processed this cycle (lock-free). | |
| bool | is_processing () const |
| Check if network is currently processing (lock-free). | |
| bool | is_registered_on_channel (uint32_t channel_id) const |
| Check if network is registered on a channel. | |
| void | mark_processed (bool processed) |
| Mark network as processed this cycle (lock-free). | |
| void | mark_processing (bool processing) |
| Mark network as processing or not (lock-free). | |
| bool | needs_channel_routing () const |
| Checks if the network is currently in a routing transition phase. | |
| void | remove_channel_usage (uint32_t channel_id) |
| Unregister network from a specific channel. | |
| void | request_reset_from_channel (uint32_t channel_id) |
| Request a reset from a specific channel. | |
| template<typename Self> | |
| void | set (this Self &self, const typename Self::Controls &incoming) |
| Apply the members of this network's Controls struct that hold a value. | |
| void | set_block_size (uint32_t block_size) |
| void | set_channel_mask (uint32_t mask) |
| Set channel mask directly. | |
| void | set_enabled (bool enabled) |
| Enable/disable the network. | |
| void | set_frame_rate (uint32_t frame_rate) |
| Frame rate the owning manager runs visual processing at. | |
| void | set_output_mode (OutputMode mode) |
| Set the network's output routing mode. | |
| void | set_output_scale (double scale) |
| Set the scalar multiplier applied to the network's output buffer after processing. | |
| void | set_sample_rate (uint32_t sample_rate) |
| void | set_timestep (float dt) |
| Advance this network by a fixed number of seconds per frame instead of the frame period. | |
| virtual void | set_topology (Topology topology) |
| Set the network's topology. | |
| virtual | ~NodeNetwork ()=default |
Private Member Functions | |
| void | apply_controls () |
| void | apply_pickup_position (double position) |
| void | bind (Prepared &prepared, bool keep) |
| std::shared_ptr< Prepared > | build (double length, const Profile &profile, const Losses &losses, double mouth_volume, const std::shared_ptr< TerminationOperator > &mouth, const std::shared_ptr< TerminationOperator > &bell) const |
| void | install_pending () |
| void | publish (std::shared_ptr< Prepared > next) |
| void | publish_block (std::span< const double > block) |
| void | setup (double length, Profile profile, double sample_rate) |
| void | update_mapped_parameters () |
Private Attributes | |
| std::shared_ptr< Prepared > | m_active |
| double | m_applied_friction {} |
| double | m_applied_viscosity {} |
| double | m_bandwidth {} |
| std::shared_ptr< TerminationOperator > | m_bell |
| DuctControls & | m_controls |
| double | m_courant {} |
| std::vector< double > | m_field |
| std::atomic< size_t > | m_field_points { 0 } |
| std::atomic< uint8_t > | m_handoff { 0 } |
| size_t | m_intervals {} |
| double | m_last_output {} |
| double | m_length {} |
| Losses | m_losses |
| std::shared_ptr< TerminationOperator > | m_mouth |
| double | m_mouth_volume {} |
| std::atomic< Output > | m_output { Output::RADIATED } |
| std::atomic< double > | m_pickup { 0.5 } |
| double | m_previous_outflow {} |
| std::mutex | m_producer_mutex |
| Profile | m_profile |
| double | m_rate {} |
| std::vector< double > | m_scratch |
| std::shared_ptr< Prepared > | m_slot |
Additional Inherited Members | |
| Protected Member Functions inherited from MayaFlux::Nodes::Network::NodeNetwork | |
| void | apply_output_scale () |
| Apply m_output_scale to m_last_audio_buffer. | |
| template<typename C> | |
| C & | declare_controls () |
| Create the network's controls struct and keep it alive. | |
| void | ensure_initialized () |
| Ensure initialize() is called exactly once. | |
| void | refresh_controls () |
| Read node sources and apply the shared scale. | |
| Static Protected Member Functions inherited from MayaFlux::Nodes::Network::NodeNetwork | |
| static std::unordered_map< size_t, std::vector< size_t > > | build_chain_neighbors (size_t count) |
| Build neighbor map for CHAIN topology. | |
| static std::unordered_map< size_t, std::vector< size_t > > | build_grid_2d_neighbors (size_t width, size_t height) |
| Build neighbor map for GRID_2D topology. | |
| static std::unordered_map< size_t, std::vector< size_t > > | build_grid_3d_neighbors (size_t width, size_t height, size_t depth) |
| Build neighbor map for GRID_3D topology. | |
| static std::unordered_map< size_t, std::vector< size_t > > | build_ring_neighbors (size_t count) |
| Build neighbor map for RING topology. | |
| Protected Attributes inherited from MayaFlux::Nodes::Network::NodeNetwork | |
| std::atomic_flag | m_audio_buffer_lock = ATOMIC_FLAG_INIT |
| Spinlock guarding m_last_audio_buffer. | |
| uint32_t | m_block_size { 512 } |
| std::atomic< uint32_t > | m_channel_mask { 0 } |
| Bitfield of channels this network is registered on. | |
| bool | m_enabled = true |
| uint32_t | m_frame_rate { 60 } |
| bool | m_initialized = false |
| std::vector< double > | m_last_audio_buffer |
| std::shared_ptr< OperatorChain > | m_operator_chain = std::make_shared<OperatorChain>() |
| OutputMode | m_output_mode = OutputMode::NONE |
| double | m_output_scale { 1.0 } |
| Post-processing scalar applied to m_last_audio_buffer each batch. | |
| std::vector< ParameterMapping > | m_parameter_mappings |
| std::atomic< uint32_t > | m_pending_reset_mask { 0 } |
| std::atomic< bool > | m_processed_this_cycle { false } |
| std::atomic< bool > | m_processing_state { false } |
| Per-channel processing state (lock-free atomic flags). | |
| uint32_t | m_sample_rate { 48000 } |
| std::optional< float > | m_timestep |
| Topology | m_topology = Topology::INDEPENDENT |
A one dimensional acoustic duct of any bore shape, solved by finite differences, with a termination at each end.
Pressure and volume velocity sit on an interleaved grid along the duct, one sample per step, with the cross section read from a radius profile. A cylinder, a cone and any other shape differ only in the profile. Each end is a TerminationOperator: by default a ReedOperator at the mouth, so the duct sounds when blown, and a RadiationOperator at the bell, so it radiates. A WallOperator closes an end, and a JunctionOperator takes any pressure dependent flow.
The output is the pressure radiated at one metre in pascals, or the pressure at a pickup position. Pascals are small as audio, so scale it with set_output_scale.
Mapped parameters (BROADCAST): "pickup" (0 to 1 along the duct), "scale", and anything else is offered to both terminations, so "pressure", "closing_pressure" and "opening" reach the reed.
Changing the length, the profile or a termination builds the new grid on the calling thread and installs it at a block boundary without waiting, so none of that touches the audio path. The state restarts from rest when it is installed. These calls come from one thread at a time, not from the audio thread, and return false, leaving the duct as it was, when the new grid or a termination cannot be built.
The sample rate is fixed at construction and sets the grid.
Definition at line 76 of file DuctNetwork.hpp.