Class: SPNet::Network
- Inherits:
-
Object
- Object
- SPNet::Network
- Includes:
- Hashmake::HashMakeable
- Defined in:
- lib/spnet/core/network.rb
Overview
A signal processing network, formed by connecting Block objects with Link objects.
Constant Summary collapse
- ARG_SPECS =
Define arg specs to use in processing hashed arguments during #initialize.
{ :sample_rate => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){a > 0.0}), :blocks => arg_spec_hash(:reqd => false, :type => Block), :links => arg_spec_array(:reqd => false, :type => Link), }
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Network
constructor
A new instance of Network.
-
#save_state ⇒ Object
Produce a NetworkState object from the current Network object.
Constructor Details
#initialize(args = {}) ⇒ Network
A new instance of Network. Changes all block sample rates (if necessary) to match the given sample rate. Activates links.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spnet/core/network.rb', line 22 def initialize args = {} hash_make args, Network::ARG_SPECS # ensure that all sample rates match given rate @blocks.each do |block_name, block| if block.sample_rate != @sample_rate raise ArgumentError, "block sample rate #{block.sample_rate} does not match network sample rate #{@sample_rate}" end end @links.each do |link| link.activate end end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
16 17 18 |
# File 'lib/spnet/core/network.rb', line 16 def blocks @blocks end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
16 17 18 |
# File 'lib/spnet/core/network.rb', line 16 def links @links end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
16 17 18 |
# File 'lib/spnet/core/network.rb', line 16 def sample_rate @sample_rate end |
Instance Method Details
#save_state ⇒ Object
Produce a NetworkState object from the current Network object.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/spnet/core/network.rb', line 38 def save_state block_states = {} @blocks.each do |block_name, block| block_states[block_name] = block.save_state end link_states = [] @links.each do |link| link_states.push link.save_state(@blocks) end return NetworkState.new(:block_states => block_states, :link_states => link_states) end |