Class: Vizcore::Analysis::FeatureRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/vizcore/analysis/feature_recorder.rb

Overview

Records deterministic audio analysis features from a file source.

Constant Summary collapse

VERSION =
"vizcore.features.v1"
DEFAULT_FRAME_COUNT =
300
DEFAULT_FRAME_RATE =
30.0

Instance Method Summary collapse

Constructor Details

#initialize(audio_file:, frames: DEFAULT_FRAME_COUNT, fps: DEFAULT_FRAME_RATE, noise_gate: Pipeline::DEFAULT_NOISE_GATE, audio_normalize: nil, bpm: nil, bpm_lock: false) ⇒ FeatureRecorder

Returns a new instance of FeatureRecorder.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vizcore/analysis/feature_recorder.rb', line 18

def initialize(
  audio_file:,
  frames: DEFAULT_FRAME_COUNT,
  fps: DEFAULT_FRAME_RATE,
  noise_gate: Pipeline::DEFAULT_NOISE_GATE,
  audio_normalize: nil,
  bpm: nil,
  bpm_lock: false
)
  @audio_file = Pathname.new(audio_file.to_s).expand_path
  @frames = normalize_frame_count(frames)
  @fps = normalize_frame_rate(fps)
  @noise_gate = Float(noise_gate)
  @audio_normalize = audio_normalize
  @bpm = bpm
  @bpm_lock = bpm_lock
end

Instance Method Details

#write(out:) ⇒ Hash

Returns recorder metadata.

Parameters:

  • out (String, Pathname)

    JSON output path

Returns:

  • (Hash)

    recorder metadata



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vizcore/analysis/feature_recorder.rb', line 38

def write(out:)
  output_path = Pathname.new(out.to_s).expand_path
  FileUtils.mkdir_p(output_path.dirname)
  payload = record
  output_path.write("#{JSON.pretty_generate(payload)}\n")
  {
    path: output_path,
    frames: @frames,
    fps: @fps,
    sample_rate: payload.fetch("metadata").fetch("sample_rate")
  }
end