Module: WavSpectrumAnalyzer::Common
- Included in:
- FFTApp, WaveLetApp
- Defined in:
- lib/wavspa/common.rb
Instance Method Summary collapse
- #down_step(freq) ⇒ Object
- #draw_freq_line(fb) ⇒ Object
- #draw_time_line(fb, wav, usize) ⇒ Object
- #fpos(r) ⇒ Object
- #linear_scaler(r) ⇒ Object
- #log_scaler(r) ⇒ Object
- #time_str(tm) ⇒ Object
- #up_step(freq) ⇒ Object
Instance Method Details
#down_step(freq) ⇒ Object
22 23 24 |
# File 'lib/wavspa/common.rb', line 22 def down_step(freq) return (@logscale)? (freq / @grid_step): (freq - @grid_step) end |
#draw_freq_line(fb) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wavspa/common.rb', line 26 def draw_freq_line(fb) # # 低周波方向 # frq = down_step(@basis_freq) loop { pos = fpos(frq) break if pos >= @output_width fb.hline(pos, "#{frq.to_i}Hz") if pos >= 0 frq = down_step(frq) } # # 高周波方向 # frq = @basis_freq; loop { pos = fpos(frq) break if pos <= 0 fb.hline(pos, "#{frq.to_i}Hz") if pos < @output_width frq = up_step(frq) } end |
#draw_time_line(fb, wav, usize) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/wavspa/common.rb', line 65 def draw_time_line(fb, wav, usize) tc = 0 tm = 0 n = (wav.data_size / (wav.sample_size / 8)) / usize fb.vline(0, time_str(tm)) n.times { |col| tc += usize; if tc >= wav.sample_rate tm += 1 tc %= wav.sample_rate fb.vline(col, time_str(tm)) if (tm % 10).zero? end } end |
#fpos(r) ⇒ Object
13 14 15 16 |
# File 'lib/wavspa/common.rb', line 13 def fpos(r) scale = (@logscale)? log_scaler(r): linear_scaler(r) return (scale * @output_width).round end |
#linear_scaler(r) ⇒ Object
9 10 11 |
# File 'lib/wavspa/common.rb', line 9 def linear_scaler(r) return 1.0 - ((r - @lo_freq) / @freq_width) end |
#log_scaler(r) ⇒ Object
5 6 7 |
# File 'lib/wavspa/common.rb', line 5 def log_scaler(r) return 1.0 - ((Math.log(r / @lo_freq) / @log_base) / @output_width) end |
#time_str(tm) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/wavspa/common.rb', line 52 def time_str(tm) m = tm / 60 s = tm % 60 if m.zero? ret = %q{%d"} % s else ret = %q{%d'%02d"} % [m, s] end return ret end |
#up_step(freq) ⇒ Object
18 19 20 |
# File 'lib/wavspa/common.rb', line 18 def up_step(freq) return (@logscale)? (freq * @grid_step): (freq + @grid_step) end |