wavspa 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3619e3dfdcaa48cc41eb51037b91011391cafa4c7e2fe9aa066790bc271d73d7
4
- data.tar.gz: 320b9f33e00b3f3b367cd265f04835702585c6a5aa8d2e4a610022930adbf1ac
3
+ metadata.gz: cd2d32dcf12a061f9555e5cd32be4e6f9623e45622f838614077d03a13f1c625
4
+ data.tar.gz: '0906de0b8e96773d3e61a73fada4b1675a1925a44b6234d9db144b69524cf931'
5
5
  SHA512:
6
- metadata.gz: 5b3d0e69c4e5db5dc24d233769728e1bf30da2581ab2affbbf80eda56d495a554212aa84d70b76cffed0351572bf05ac2cb75b333eb3421ee624a01f7378adea
7
- data.tar.gz: 747b1bd4ba30bab6543d5add4f4c2a6b3dbb9e6f3a0451d8e23ac1cf6db7256056b6d0a30e733295b95aa5a9b6b20dce41a10782ddbcd22ace64ca68b0fed77d
6
+ metadata.gz: 7654f8485ac753d0691029422ff367c469c7597577865fda342da8ae923c96587447db33a47332a815b27c5e473bdb8235951ab4ffe1f2f1a7c76f81cd79ed8b
7
+ data.tar.gz: 5f35c4b6845fc6827314f9f5038a831db73f8a60aeb4519c258cfaefa18fa9c4b6d9f0a6610d6e4a9daa8059c476e1aeb2e8722716c2a53eacdd9f4fd0ff5bb2
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  This application uses OpenMP, but by default tries to link the libgomp. When using another implementation (such as intel OpenMP) with macOS etc, specify the libary path and library name by command line options as follows:
22
22
 
23
- $ gem insatll wavspa -- --with-openomp ~/env/opts/lib --omp-name omp
23
+ $ gem insatll wavspa -- --with-openmp ~/env/opts/lib --omp-name omp
24
24
 
25
25
  ## Usage
26
26
 
@@ -36,7 +36,8 @@ options:
36
36
  -u, --unit-time=CS
37
37
  -W, --output-width=SIZE
38
38
  -w, --window-function=FUNCTION
39
- -r, --frequency-range=LO,HI,
39
+ -r, --frequency-range=LO,HI
40
+ -g, --frequnecy-grid=BASIS,STEP
40
41
  -m, --scale-mode=MODE
41
42
  --show-params
42
43
  -c, --col-steps=SIZE
@@ -67,6 +68,9 @@ options:
67
68
  <dt>-r, --frequency-range=LO,HI</dt>
68
69
  <dd>specify the frequency band show on the output PNG (upper limit to "HI", and lower limit to "LO").<dd>
69
70
 
71
+ <dt>-g, --frequency-grid=BASIS,STEP</dt>
72
+ <dd>specify frequency grid settings. basis frequency to "BASIS" and step value to "STEP". "STEP" is evaluated as a ratio for neighbor grid when the scale mode is LOGSCALE, and as a difference for neighbor grid when LINEARSCALE.</dd>
73
+
70
74
  <dt>-m, --scale=mode</dt>
71
75
  <dd>specify the mode of grid scale in vertical direction of th output PNG. you can specify one of "LOGSCALE" or "LINEARSCALE" (default is "LOGSCALE").</dd>
72
76
 
@@ -104,6 +108,7 @@ options:
104
108
  -r, --frequency-range=LO,HI
105
109
  --floor-gain=DB
106
110
  --ceil-gain=DB
111
+ -g, --frequnecy-grid=BASIS,STEP
107
112
  -m, --scale-mode=STRING
108
113
  -c, --col-steps=SIZE
109
114
  --show-params
@@ -140,6 +145,10 @@ options:
140
145
  <dt>--ceil-gain=DB</dt>
141
146
  <dd>specify the lower limit value of the gain to be displayed. values less than this number will be masked.</dd>
142
147
 
148
+ <dt>-g, --frequency-grid=BASIS,STEP</dt>
149
+ <dd>specify frequency grid settings. basis frequency to "BASIS" and step value to "STEP". "STEP" is evaluated as a ratio for neighbor grid when the scale mode is LOGSCALE, and as a difference for neighbor grid when LINEARSCALE.</dd>
150
+
151
+
143
152
  <dt>-m, --scale=mode</dt>
144
153
  <dd>specify the mode of grid scale in vertical direction of th output PNG. you can specify one of "LOGSCALE" or "LINEARSCALE" (default is "LOGSCALE").</dd>
145
154
 
@@ -177,9 +186,12 @@ As a sample data, transformed from "Call to Quarters" (https://archive.org/detai
177
186
  ```
178
187
  wavlet -p cd -F -T -c 2 -v -o Call_To_Quarters-wavelet.png Call_To_Quarters.wav
179
188
  ```
180
-
181
189
  ![wavelet result](example/Call_To_Quarters-wavelet.png)
182
190
 
191
+ ```
192
+ wavlet -p cd -F -T -c 2 --floor-gain -110 -v -o Call_To_Quarters-wavelet2.png Call_To_Quarters.wav
193
+ ```
194
+ ![wavelet result](example/Call_To_Quarters-wavelet2.png)
183
195
 
184
196
  ## Contributing
185
197
 
data/bin/wavfft CHANGED
@@ -76,8 +76,7 @@ OptionParser.new {|opt|
76
76
  if FFTApp::PRESET_TABLE.include?(name)
77
77
  params = FFTApp::PRESET_TABLE[name]
78
78
  else
79
- STDERR.print("error: unknown preset name.\n")
80
- exit(1)
79
+ error("unknown preset name.\n")
81
80
  end
82
81
  }
83
82
 
@@ -104,8 +103,7 @@ OptionParser.new {|opt|
104
103
  if window_funcs.include?(name)
105
104
  params[:window_function] = name
106
105
  else
107
- STDERR.print("unknown windows function.\n")
108
- exit(1)
106
+ error("unknown windows function.")
109
107
  end
110
108
  }
111
109
 
@@ -113,11 +111,15 @@ OptionParser.new {|opt|
113
111
  params[:range] = [val[0].to_f, val[1].to_f]
114
112
  }
115
113
 
116
- opt.on("-m", "--scale-mode=MODE", String) { |val|
114
+ opt.on("-g", "--frequency-grid=BASIS,STEP", Array) { |val|
115
+ params[:basis_freq] = val[0].to_f
116
+ params[:grid_step] = val[1].to_f
117
+ }
118
+
119
+ opt.on("-m", "--scale-mode=MODE", String) { |name|
117
120
  name = name.upcase.to_sym
118
- if not ["LINEAR", "LOGSCALE"].include?(name)
119
- STDERR.print("error: unknown scale mode.\n")
120
- exit(1)
121
+ if not [:LINEARSCALE, :LOGSCALE].include?(name)
122
+ error("unknown scale mode.")
121
123
  end
122
124
 
123
125
  params[:scale_mode] = name
@@ -152,9 +154,19 @@ OptionParser.new {|opt|
152
154
 
153
155
  opt.parse!(ARGV)
154
156
 
157
+ if params[:scale_mode] == :LOGSCALE
158
+ if params[:basis_freq]&.<=(1.0) || params[:grid_step]&.<=(1.0)
159
+ error("illeagal frequency grid.")
160
+ end
161
+
162
+ else
163
+ if params[:basis_freq]&.<=(0.0) || params[:grid_step]&.<=(0.0)
164
+ error("illeagal frequency grid.")
165
+ end
166
+ end
167
+
155
168
  if ARGV.empty?
156
- STDERR.print("error: target file not specified.\n")
157
- exit(1)
169
+ error("target file not specified.")
158
170
  end
159
171
 
160
172
  output ||= File.basename(ARGV[0], ".wav") + ".png"
data/bin/wavlet CHANGED
@@ -105,9 +105,14 @@ OptionParser.new {|opt|
105
105
  params[:ceil] = val
106
106
  }
107
107
 
108
+ opt.on("-g", "--frequency-grid=BASIS,STEP", Array) { |val|
109
+ params[:basis_freq] = val[0].to_f
110
+ params[:grid_step] = val[1].to_f
111
+ }
112
+
108
113
  opt.on("-m", "--scale-mode=STRING", String) {|name|
109
114
  name = name.upcase.to_sym
110
- if not ["LINEAR", "LOGSCALE"].include?(name)
115
+ if not [:LINEARSCALE, :LOGSCALE].include?(name)
111
116
  STDERR.print("error: unknown scale mode.\n")
112
117
  exit(1)
113
118
  end
@@ -145,6 +150,17 @@ OptionParser.new {|opt|
145
150
 
146
151
  opt.parse!(ARGV)
147
152
 
153
+ if params[:scale_mode] == :LOGSCALE
154
+ if params[:basis_freq]&.<=(1.0) || params[:grid_step]&.<=(1.0)
155
+ error("illeagal frequency grid.")
156
+ end
157
+
158
+ else
159
+ if params[:basis_freq]&.<=(0.0) || params[:grid_step]&.<=(0.0)
160
+ error("illeagal frequency grid.")
161
+ end
162
+ end
163
+
148
164
  if ARGV.empty?
149
165
  STDERR.print("error: target file not specified.\n")
150
166
  exit(1)
data/lib/wavspa/common.rb CHANGED
@@ -15,17 +15,25 @@ module WavSpectrumAnalyzer
15
15
  return (scale * @output_width).round
16
16
  end
17
17
 
18
+ def up_step(freq)
19
+ return (@logscale)? (freq * @grid_step): (freq + @grid_step)
20
+ end
21
+
22
+ def down_step(freq)
23
+ return (@logscale)? (freq / @grid_step): (freq - @grid_step)
24
+ end
25
+
18
26
  def draw_freq_line(fb)
19
27
  #
20
28
  # 低周波方向
21
29
  #
22
- frq = @basis_freq / 2
30
+ frq = down_step(@basis_freq)
23
31
  loop {
24
32
  pos = fpos(frq)
25
- break if pos > @output_width
33
+ break if pos >= @output_width
26
34
 
27
35
  fb.hline(pos, "#{frq.to_i}Hz")
28
- frq /= 2
36
+ frq = down_step(frq)
29
37
  }
30
38
 
31
39
  #
@@ -37,7 +45,7 @@ module WavSpectrumAnalyzer
37
45
  break if pos <= 0
38
46
 
39
47
  fb.hline(pos, "#{frq.to_i}Hz")
40
- frq *= 2
48
+ frq = up_step(frq)
41
49
  }
42
50
  end
43
51
 
@@ -70,5 +78,12 @@ module WavSpectrumAnalyzer
70
78
  end
71
79
  }
72
80
  end
81
+
73
82
  end
74
83
  end
84
+
85
+ def error(msg)
86
+ STDERR.printf("error: %s\n", msg)
87
+ abort()
88
+ end
89
+
@@ -1,3 +1,3 @@
1
1
  module WavSpectrumAnalyzer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -22,19 +22,22 @@ module WavSpectrumAnalyzer
22
22
  @unit_time = param[:unit_time]
23
23
  @fft_size = param[:fft_size]
24
24
  @output_width = param[:output_width]
25
- @logscale = (param[:scale_mode] == :LOGSCALE)
26
25
  @win_func = param[:window_function]
26
+
27
+ @freq_range = param[:range]
27
28
  @scale_mode = param[:scale_mode]
29
+ @logscale = (param[:scale_mode] == :LOGSCALE)
28
30
  @col_step = param[:col_step]
29
31
 
30
- @freq_range = param[:range]
32
+ @basis_freq = param[:basis_freq] || 440.0
33
+ @grid_step = param[:grid_step] || ((@logscale)? 2.0: 2000.0)
34
+
31
35
  @lo_freq = @freq_range[0]
32
36
  @hi_freq = @freq_range[1]
33
37
  @freq_width = (@hi_freq - @lo_freq)
34
38
 
35
39
  @log_step = (@hi_freq / @lo_freq) ** (1.0 / @output_width)
36
40
  @log_base = Math.log(@log_step)
37
- @basis_freq = 440.0
38
41
  end
39
42
  private :load_param
40
43
 
@@ -85,9 +88,8 @@ module WavSpectrumAnalyzer
85
88
  end
86
89
 
87
90
  if wav.channel_num >= 2
88
- STDERR.print("error: multi chanel data is not supported " \
89
- "(support only monoral data).\n")
90
- exit(1)
91
+ error("error: multi chanel data is not supported " \
92
+ "(support only monoral data).")
91
93
  end
92
94
 
93
95
  until rows >= nblk
@@ -25,18 +25,21 @@ module WavSpectrumAnalyzer
25
25
  @floor = param[:floor]
26
26
  @tran_mode = param[:transform_mode]
27
27
  @output_width = param[:output_width]
28
- @logscale = (param[:scale_mode] == :LOGSCALE)
28
+
29
+ @freq_range = param[:range]
29
30
  @scale_mode = param[:scale_mode]
31
+ @logscale = (param[:scale_mode] == :LOGSCALE)
30
32
  @col_step = param[:col_step]
31
33
 
32
- @freq_range = param[:range]
34
+ @basis_freq = param[:basis_freq] || 440.0
35
+ @grid_step = param[:grid_step] || ((@logscale)? 2.0: 2000.0)
36
+
33
37
  @lo_freq = @freq_range[0]
34
38
  @hi_freq = @freq_range[1]
35
39
  @freq_width = (@hi_freq - @lo_freq)
36
40
 
37
41
  @log_step = (@hi_freq / @lo_freq) ** (1.0 / @output_width)
38
42
  @log_base = Math.log(@log_step)
39
- @basis_freq = 440.0
40
43
  end
41
44
  private :load_param
42
45
 
@@ -93,9 +96,8 @@ module WavSpectrumAnalyzer
93
96
  end
94
97
 
95
98
  if wav.channel_num >= 2
96
- STDERR.print("error: multi chanel data is not supported " \
97
- "(support only monoral data).\n")
98
- exit(1)
99
+ error("error: multi chanel data is not supported " \
100
+ "(support only monoral data).")
99
101
  end
100
102
 
101
103
  until rows >= nblk
@@ -17,8 +17,8 @@ module WavSpectrumAnalyzer
17
17
  :transform_mode => :POWER,
18
18
  :output_width => 240,
19
19
  :range => [200.0, 8000.0],
20
- :ceil => -10,
21
- :floor => -90,
20
+ :ceil => -10.0,
21
+ :floor => -90.0,
22
22
  :col_step => 1,
23
23
  },
24
24
 
@@ -29,8 +29,8 @@ module WavSpectrumAnalyzer
29
29
  :transform_mode => :POWER,
30
30
  :output_width => 480,
31
31
  :range => [50.0, 22050.0],
32
- :ceil => -10,
33
- :floor => -90,
32
+ :ceil => -10.0,
33
+ :floor => -90.0,
34
34
  :col_step => 1,
35
35
  },
36
36
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavspa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hirosho Kuwagata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-01 00:00:00.000000000 Z
11
+ date: 2019-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,6 +73,7 @@ files:
73
73
  - bin/wavlet
74
74
  - example/Call_To_Quarters-fft.png
75
75
  - example/Call_To_Quarters-wavelet.png
76
+ - example/Call_To_Quarters-wavelet2.png
76
77
  - ext/wavspa/fb/extconf.rb
77
78
  - ext/wavspa/fb/rb_fb.c
78
79
  - ext/wavspa/fft/extconf.rb