class SPNet::Network

A signal processing network, formed by connecting Block objects with Link objects.

@author James Tunnell

Constants

ARG_SPECS

Define arg specs to use in processing hashed arguments during initialize.

Attributes

blocks[R]
sample_rate[R]

Public Class Methods

new(args = {}) click to toggle source

A new instance of Network. Changes all block sample rates (if necessary) to match the given sample rate. Activates links. @param [Hash] args Hashed arguments for initialization. See Network::ARG_SPECS

for details of which keys are required.
# 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

Public Instance Methods

save_state() click to toggle source

Produce a NetworkState object from the current Network object.

# 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