48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/wavspa/wavlet/main.rb', line 48
def main(input, param, output)
load_param(param)
wav = WavFile.open(input)
wl = Wavelet.new
wl.frequency = wav.sample_rate
wl.sigma = @sigma
wl.gabor_threshold = @threshold
wl.range = (@lo_freq .. @hi_freq)
wl.scale_mode = @scale_mode
wl.width = @output_width
wl.put_in("s%dle" % wav.sample_size, wav.read)
row = 0
usize = (wav.sample_rate * @unit_time) / 1000
nblk = (wav.data_size / wav.block_size) / usize
fb = FrameBuffer.new(nblk,
@output_width,
:column_step => @col_step,
:margin_x => ($draw_freq_line)? 50:0,
:margin_y => ($draw_time_line)? 30:0,
:ceil => @ceil,
:floor => @floor,
:luminance => @luminance)
if $verbose
STDERR.print <<~EOT
- input data
#{input}
data size: #{wav.data_size}
channel num: #{wav.channel_num}
sample rate: #{wav.sample_rate} Hz
sample size: #{wav.sample_size} bits
data rate: #{wav.bytes_per_sec} bytes/sec
- WAVELET parameter
sigma: #{@sigma}
gabor threshold: #{@threshold}
unit time: #{@unit_time} ms
- OUTPUT
width: #{fb.width}px
height: #{fb.height}px
freq range: #{@lo_freq} - #{@hi_freq}Hz
scale mode: #{@scale_mode}
plot mode : #{@transform_mode}
ceil: #{@ceil}
floor: #{@floor}
EOT
end
if wav.channel_num >= 2
error("error: multi chanel data is not supported " \
"(support only monoral data).")
end
until row >= nblk
STDERR.printf("\rtransform #{row + 1}/#{nblk}", row) if $verbose
wl.transform(row * usize)
if @transform_mode == :POWER
fb.draw_power(row, wl.power)
else
fb.draw_amplitude(row, wl.amplitude)
end
row += 1
end
STDERR.printf(" ... done\n") if $verbose
STDERR.printf("write to #{output} ... ") if $verbose
draw_freq_line(fb) if $draw_freq_line
draw_time_line(fb, wav, usize) if $draw_time_line
png = PNG.encode(fb.width, fb.height, fb.to_s, :pixel_format => :RGB)
IO.binwrite(output, png)
STDERR.printf("done\n") if $verbose
end
|