Module: Radio::Rig::Spectrum

Included in:
Radio::Rig
Defined in:
lib/radio/rig/spectrum.rb

Instance Method Summary collapse

Instance Method Details

#initializeObject



20
21
22
23
24
25
26
27
# File 'lib/radio/rig/spectrum.rb', line 20

def initialize
  @spectrum_buf = {}
  @spectrum_semaphore = Mutex.new
  @spectrum_pending = Hash.new {|h,k|h[k]=[]}
  register @spectrum_queue = Queue.new
  Thread.start &method(:spectrum_collector)
  super
end

#spectrum(size, frequency = 1.0, keep_alive = 2.0) ⇒ Object

Block until the next collection of data is ready (size*frequency samples). Result is NArray of floats suitable for display purposes. size must be a power of 2 for good performance (use GPU for visual scaling) frequency may be greater or less than 1.0 keep_alive in secs set high enough so intervals between results are accurate Results are not queued; missed processing is skipped. This is meant to be an ideal interface for Web UI work, not signal analysis.



36
37
38
39
40
41
42
# File 'lib/radio/rig/spectrum.rb', line 36

def spectrum size, frequency=1.0, keep_alive=2.0
  @spectrum_semaphore.synchronize do
    @spectrum_pending[[size, frequency, keep_alive]] << Thread.current
  end
  sleep
  @spectrum_buf[[size, frequency, keep_alive]][2]
end