Class: Vizcore::Analysis::FeatureReplay
- Inherits:
-
Object
- Object
- Vizcore::Analysis::FeatureReplay
- Defined in:
- lib/vizcore/analysis/feature_replay.rb
Overview
Replays recorded analysis features as a pipeline-compatible source.
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#call(_samples = nil) ⇒ Hash<Symbol, Object>
Recorded audio analysis for the next frame.
-
#frame(index) ⇒ Hash<Symbol, Object>
Read a specific feature frame without changing the replay cursor.
- #frame_count ⇒ Object
-
#initialize(path:) ⇒ FeatureReplay
constructor
A new instance of FeatureReplay.
-
#seek(index) ⇒ Vizcore::Analysis::FeatureReplay
Move the replay cursor to a frame index.
-
#seek_seconds(seconds) ⇒ Vizcore::Analysis::FeatureReplay
Move the replay cursor to the frame nearest to the given timestamp.
Constructor Details
#initialize(path:) ⇒ FeatureReplay
Returns a new instance of FeatureReplay.
13 14 15 16 17 18 19 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 13 def initialize(path:) @path = Pathname.new(path.to_s). payload = load_payload @metadata = deep_symbolize(payload.fetch("metadata", {})) @features = load_features(payload) @cursor = 0 end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
11 12 13 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 11 def cursor @cursor end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 11 def @metadata end |
Instance Method Details
#call(_samples = nil) ⇒ Hash<Symbol, Object>
Returns recorded audio analysis for the next frame.
23 24 25 26 27 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 23 def call(_samples = nil) audio = @features.fetch(@cursor) @cursor = (@cursor + 1) % @features.length deep_dup(audio) end |
#frame(index) ⇒ Hash<Symbol, Object>
Read a specific feature frame without changing the replay cursor.
57 58 59 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 57 def frame(index) deep_dup(@features.fetch(normalize_index(index))) end |
#frame_count ⇒ Object
29 30 31 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 29 def frame_count @features.length end |
#seek(index) ⇒ Vizcore::Analysis::FeatureReplay
Move the replay cursor to a frame index.
37 38 39 40 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 37 def seek(index) @cursor = normalize_index(index) self end |
#seek_seconds(seconds) ⇒ Vizcore::Analysis::FeatureReplay
Move the replay cursor to the frame nearest to the given timestamp.
46 47 48 49 50 51 |
# File 'lib/vizcore/analysis/feature_replay.rb', line 46 def seek_seconds(seconds) fps = raise ArgumentError, "feature metadata fps must be positive to seek by seconds" unless fps.positive? seek((numeric_seconds(seconds) * fps).floor) end |