Class: Vizcore::Audio::FixtureInput

Inherits:
BaseInput
  • Object
show all
Defined in:
lib/vizcore/audio/fixture_input.rb

Overview

Deterministic sample-frame input for tests and repeatable development checks.

Instance Attribute Summary

Attributes inherited from BaseInput

#sample_rate

Instance Method Summary collapse

Methods inherited from BaseInput

#running?, #start, #stop

Constructor Details

#initialize(frames:, sample_rate: 44_100, loop: true) ⇒ FixtureInput

Returns a new instance of FixtureInput.

Parameters:

  • frames (Array<Array<Numeric>>)

    sample frames returned in order

  • sample_rate (Integer) (defaults to: 44_100)
  • loop (Boolean) (defaults to: true)

    whether to repeat frames after the last one



12
13
14
15
16
17
# File 'lib/vizcore/audio/fixture_input.rb', line 12

def initialize(frames:, sample_rate: 44_100, loop: true)
  super(sample_rate: sample_rate)
  @frames = normalize_frames(frames)
  @loop = !!loop
  @index = 0
end

Instance Method Details

#read(frame_size) ⇒ Array<Float>

Parameters:

  • frame_size (Integer)

Returns:

  • (Array<Float>)


21
22
23
24
25
26
27
28
29
# File 'lib/vizcore/audio/fixture_input.rb', line 21

def read(frame_size)
  count = Integer(frame_size)
  return Array.new(count, 0.0) unless running?

  frame = next_frame
  return Array.new(count, 0.0) unless frame

  normalize_frame_size(frame, count)
end

#resetvoid

This method returns an undefined value.



32
33
34
# File 'lib/vizcore/audio/fixture_input.rb', line 32

def reset
  @index = 0
end