module AudioStream module Fx class Tuner Tune = Struct.new("Tune", :freq, :note_num, :note, :octave, :diff, :gain, keyword_init: true) FREQ_TABLE = 10.times.map {|i| a = 13.75 * 2 ** i 12.times.map {|j| a * (2 ** (j / 12.0)) } }.flatten.freeze NOTE_TABLE = ["A", "A#/Bb", "B", "C", "C#/Db", "D", "D#/Eb", "E", "F", "F#/Gb", "G", "G#/Ab"].freeze def initialize(soundinfo, window: nil) @samplerate = soundinfo.samplerate.to_f @window = window || HanningWindow.instance end def process(input) window_size = input.window_size # mono window input = input.mono input = @window.process(input) stream = input.streams[0] gain = stream.map(&:abs).max freq = nil if 0.01=freq} if !index || FREQ_TABLE.length<=index+1 return Tune.new end if 0