wavspa 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3619e3dfdcaa48cc41eb51037b91011391cafa4c7e2fe9aa066790bc271d73d7
4
+ data.tar.gz: 320b9f33e00b3f3b367cd265f04835702585c6a5aa8d2e4a610022930adbf1ac
5
+ SHA512:
6
+ metadata.gz: 5b3d0e69c4e5db5dc24d233769728e1bf30da2581ab2affbbf80eda56d495a554212aa84d70b76cffed0351572bf05ac2cb75b333eb3421ee624a01f7378adea
7
+ data.tar.gz: 747b1bd4ba30bab6543d5add4f4c2a6b3dbb9e6f3a0451d8e23ac1cf6db7256056b6d0a30e733295b95aa5a9b6b20dce41a10782ddbcd22ace64ca68b0fed77d
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in wavspa.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Hirosho Kuwagata
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,196 @@
1
+ # wavspa
2
+
3
+ "wavspa" is a WAV file spectrum analyzer. Includes FFT and wavelet analyzers.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'wavspa'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install wavspa
20
+
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
+
23
+ $ gem insatll wavspa -- --with-openomp ~/env/opts/lib --omp-name omp
24
+
25
+ ## Usage
26
+
27
+ ### FFT analyzer
28
+
29
+ ```
30
+ wavfft [options] WAV-FILE
31
+
32
+ options:
33
+ -o, --output=FILE
34
+ -p, --preset=NAME
35
+ -f, --fft-size=SIZE
36
+ -u, --unit-time=CS
37
+ -W, --output-width=SIZE
38
+ -w, --window-function=FUNCTION
39
+ -r, --frequency-range=LO,HI,
40
+ -m, --scale-mode=MODE
41
+ --show-params
42
+ -c, --col-steps=SIZE
43
+ -F, --draw-freq-line
44
+ -T, --draw-time-line
45
+ -v, --verbose
46
+ -h, --help
47
+ ```
48
+
49
+ #### options
50
+
51
+ <dl>
52
+ <dt>-o, --output</dt>
53
+ <dd>specify the output file name. by default, output to the file that extension of input file changed to ".png".</dd>
54
+
55
+ <dt>-p, --preset=NAME</dt>
56
+ <dd>specify preset settings. you can specify one of "default", "32k" or "cd".</dd>
57
+
58
+ <dt>-f, --fft-size=FFT</dt>
59
+ <dd>specify the FFT size (by number of samples, this value must spcify a power of 2).</dd>
60
+
61
+ <dt>-u, --unit-time=CS</dt>
62
+ <dd>specify the unit time of short time FFT in centiseconds (1/100 sec). This value is the time per pixel in horizontal direction of the output PNG.</dt>
63
+
64
+ <dt>-W, --output-width=SIZE</dt>
65
+ <dd>specify the hight of output PNG (by number of pixels).</dd>
66
+
67
+ <dt>-r, --frequency-range=LO,HI</dt>
68
+ <dd>specify the frequency band show on the output PNG (upper limit to "HI", and lower limit to "LO").<dd>
69
+
70
+ <dt>-m, --scale=mode</dt>
71
+ <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
+
73
+ <dt>-c, --col-steps=SIZE</dt>
74
+ <dd>specify the horizontal magnify ratio of th output file.</dd>
75
+
76
+ <dt>--show-params</dt>
77
+ <dd>show sumarry of settings.</dd>
78
+
79
+ <dt>-F, --draw-freq-line</dt>
80
+ <dd>enable frequency line (vertical grid).</dd>
81
+
82
+ <dt>-F, --draw-freq-line</dt>
83
+ <dd>enable time line (horizontal grid).</dd>
84
+
85
+ <dt>-v, --verbose</dt>
86
+ <dd>enable verbose mode</dd>
87
+
88
+ <dt>-h, --help</dt>
89
+ <dd>show help message</dd>
90
+ </dl>
91
+
92
+ ### Wavelet analyzer
93
+
94
+ ```
95
+ wavlet [options] WAV-FILE
96
+
97
+ options:
98
+ -o, --output=FILE
99
+ -p, --preset=NAME
100
+ -s, --sigma=NUMBER
101
+ -a, --amplitude-mode
102
+ -u, --unit-time=CENTISECOND
103
+ -W, --output-width=SIZE
104
+ -r, --frequency-range=LO,HI
105
+ --floor-gain=DB
106
+ --ceil-gain=DB
107
+ -m, --scale-mode=STRING
108
+ -c, --col-steps=SIZE
109
+ --show-params
110
+ -F, --draw-freq-line
111
+ -T, --draw-time-line
112
+ -v, --verbose
113
+ ```
114
+
115
+ <dl>
116
+ <dt>-o, --output</dt>
117
+ <dd>specify the output file name. by default, output to the file that extension of input file changed to ".png".</dd>
118
+
119
+ <dt>-p, --preset=NAME</dt>
120
+ <dd>specify preset settings. you can specify one of "default" or "cd".</dd>
121
+
122
+ <dt>-s, --sigma=FLOAT</dt>
123
+ <dd>specify the sigma value. Increasing this value improves the accuracy but increases the processing load.</dd>
124
+
125
+ <dt>-a, --amplitude-mode</dt>
126
+ <dd>When this option is specified, the amplitude spectrum is output (otherwise, the power spectrum is output).</dd>
127
+
128
+ <dt>-u, --unit-time=CS</dt>
129
+ <dd>specify the unit time of wavelet stransform in centiseconds (1/100 sec). This value is the time per pixel in horizontal direction of the output PNG.</dt>
130
+
131
+ <dt>-W, --output-width=SIZE</dt>
132
+ <dd>specify the hight of output PNG (by number of pixels).</dd>
133
+
134
+ <dt>-r, --frequency-range=LO,HI</dt>
135
+ <dd>specify the frequency band show on the output PNG (upper limit to "HI", and lower limit to "LO").<dd>
136
+
137
+ <dt>--floor-gain=DB</dt>
138
+ <dd>specify the upper limit value of the gain to be displayed. values exceeding this number are displayed as saturated.</dd>
139
+
140
+ <dt>--ceil-gain=DB</dt>
141
+ <dd>specify the lower limit value of the gain to be displayed. values less than this number will be masked.</dd>
142
+
143
+ <dt>-m, --scale=mode</dt>
144
+ <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
+
146
+ <dt>-c, --col-steps=SIZE</dt>
147
+ <dd>specify the horizontal magnify ratio of th output file.</dd>
148
+
149
+ <dt>--show-params</dt>
150
+ <dd>show sumarry of settings.</dd>
151
+
152
+ <dt>-F, --draw-freq-line</dt>
153
+ <dd>enable frequency line (vertical grid).</dd>
154
+
155
+ <dt>-F, --draw-freq-line</dt>
156
+ <dd>enable time line (horizontal grid).</dd>
157
+
158
+ <dt>-v, --verbose</dt>
159
+ <dd>enable verbose mode</dd>
160
+
161
+ <dt>-h, --help</dt>
162
+ <dd>show help message</dd>
163
+ </dl>
164
+
165
+ ## Output example
166
+ As a sample data, transformed from "Call to Quarters" (https://archive.org/details/CallToQuarters).
167
+
168
+ ### FFT
169
+ ```
170
+ wavfft -p cd -F -T -v -o Call_To_Quarters-fft.png Call_To_Quarters.wav
171
+ ```
172
+
173
+ ![FFT result](example/Call_To_Quarters-fft.png)
174
+
175
+
176
+ ### Wavelet
177
+ ```
178
+ wavlet -p cd -F -T -c 2 -v -o Call_To_Quarters-wavelet.png Call_To_Quarters.wav
179
+ ```
180
+
181
+ ![wavelet result](example/Call_To_Quarters-wavelet.png)
182
+
183
+
184
+ ## Contributing
185
+
186
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kwgt/wavspa.
187
+
188
+ ## その他
189
+ 以下のソースコード及びデータを流用しています。各々の開発者の方に感謝いたします。
190
+
191
+ * wavfftで使用しているFFT処理は大浦氏が配布されているコード(通称「大浦FFT」 http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html) を流用しています(ext/wavspa/fft/fftsg.c)。
192
+ * プロット時に使用しているフォントはM+ BITMAP (http://mplus-fonts.osdn.jp/mplus-bitmap-fonts/) で配布されているm+ gothic 10rを変換し使用しています(ext/wavspa/fb/rb_fb.c)。
193
+
194
+ ## License
195
+
196
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/wavfft ADDED
@@ -0,0 +1,167 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ #
5
+ # Spectrum analyzer for WAV file
6
+ #
7
+ # Copyright (C) 2019 Hiroshi Kuwagata <kgt9221@gmail.com>
8
+ #
9
+
10
+ require 'optparse'
11
+ require 'pathname'
12
+ require 'pp'
13
+
14
+ #
15
+ # パッケージ内で参照する定数の定義
16
+ #
17
+
18
+ TRADITIONAL_NAME = "Spectrum analyzer for WAV file"
19
+ APP_NAME = "wavfft"
20
+
21
+ BASE_DIR = Pathname.new(File.expand_path(__FILE__)).dirname.parent
22
+ LIB_DIR = BASE_DIR + "lib"
23
+ PKG_LIB_DIR = LIB_DIR + "wavspa"
24
+ APP_LIB_DIR = PKG_LIB_DIR + APP_NAME
25
+
26
+ #
27
+ # ライブラリロードパスの差し込み
28
+ #
29
+
30
+ $LOAD_PATH.unshift(LIB_DIR)
31
+
32
+ #
33
+ # アプリケーション本体の読み込み
34
+ #
35
+
36
+ require "#{PKG_LIB_DIR + "version"}"
37
+ require "#{PKG_LIB_DIR + "common"}"
38
+ require "#{APP_LIB_DIR + "preset"}"
39
+ require "#{APP_LIB_DIR + "main"}"
40
+
41
+ #
42
+ # デフォルトパラメータのセット
43
+ #
44
+
45
+ include WavSpectrumAnalyzer
46
+
47
+ params = FFTApp::PRESET_TABLE["default"]
48
+ output = nil
49
+
50
+ #
51
+ # コマンドラインオプションのパース
52
+ #
53
+
54
+ OptionParser.new {|opt|
55
+ window_funcs = %w{
56
+ RECTANGULAR HAMMING HANN BLACKMAN BLACKMAN_NUTTALL FLAT_TOP
57
+ }
58
+
59
+ opt.banner += " WAV-FILE"
60
+ opt.version = VERSION
61
+
62
+ opt.on("-o", "--output=FILE", String) { |name|
63
+ output = name
64
+ }
65
+
66
+ opt.on("-p", "--preset=NAME", String) { |name|
67
+ name.downcase!
68
+
69
+ if name == "help"
70
+ FFTApp::PRESET_TABLE.keys.each { |str|
71
+ printf(" %s\n", str)
72
+ }
73
+ exit
74
+ end
75
+
76
+ if FFTApp::PRESET_TABLE.include?(name)
77
+ params = FFTApp::PRESET_TABLE[name]
78
+ else
79
+ STDERR.print("error: unknown preset name.\n")
80
+ exit(1)
81
+ end
82
+ }
83
+
84
+ opt.on("-f", "--fft-size=SIZE", Integer) {|val|
85
+ params[:fft_size] = val
86
+ }
87
+
88
+ opt.on("-u", "--unit-time=MSEC", Integer) {|val|
89
+ params[:unit_time] = val
90
+ }
91
+
92
+ opt.on("-W", "--output-width=SIZE", Integer) {|val|
93
+ params[:output_width] = val
94
+ }
95
+
96
+ opt.on("-w", "--window-function=FUNCTION", String) {|name|
97
+ name.upcase!
98
+
99
+ if name == "HELP"
100
+ window_funcs.each {|func| printf(" %s\n", func)}
101
+ exit
102
+ end
103
+
104
+ if window_funcs.include?(name)
105
+ params[:window_function] = name
106
+ else
107
+ STDERR.print("unknown windows function.\n")
108
+ exit(1)
109
+ end
110
+ }
111
+
112
+ opt.on("-r", "--frequency-range=LO,HI", Array) { |val|
113
+ params[:range] = [val[0].to_f, val[1].to_f]
114
+ }
115
+
116
+ opt.on("-m", "--scale-mode=MODE", String) { |val|
117
+ name = name.upcase.to_sym
118
+ if not ["LINEAR", "LOGSCALE"].include?(name)
119
+ STDERR.print("error: unknown scale mode.\n")
120
+ exit(1)
121
+ end
122
+
123
+ params[:scale_mode] = name
124
+ }
125
+
126
+ opt.on("-c", "--col-steps=SIZE", Integer) {|val|
127
+ params[:col_step] = val
128
+ }
129
+
130
+ opt.on("--show-params") {
131
+ printf("FFT size %20d entries\n", params[:fft_size])
132
+ printf("unit time %20d msec\n", params[:unit_time])
133
+ printf("window function %20s\n", params[:window_function].to_s)
134
+ printf("scale mode %20s\n", params[:scale_mode].to_s)
135
+ printf("frequency range %20s Hz\n",
136
+ ("%.0f - %.0f" % [params[:range][0], params[:range][1]]))
137
+ printf("column steps %20d pixels\n", params[:col_step])
138
+ exit
139
+ }
140
+
141
+ opt.on("-F", "--draw-freq-line") {
142
+ $draw_freq_line = true
143
+ }
144
+
145
+ opt.on("-T", "--draw-time-line") {
146
+ $draw_time_line = true
147
+ }
148
+
149
+ opt.on('-v', "--verbose") {
150
+ $verbose = true
151
+ }
152
+
153
+ opt.parse!(ARGV)
154
+
155
+ if ARGV.empty?
156
+ STDERR.print("error: target file not specified.\n")
157
+ exit(1)
158
+ end
159
+
160
+ output ||= File.basename(ARGV[0], ".wav") + ".png"
161
+ }
162
+
163
+ #
164
+ # アプリケーションの起動
165
+ #
166
+
167
+ FFTApp.main(ARGV[0], params, output)
data/bin/wavlet ADDED
@@ -0,0 +1,160 @@
1
+ #! /usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ #
5
+ # Spectrum analyzer for WAV file
6
+ #
7
+ # Copyright (C) 2019 Hiroshi Kuwagata <kgt9221@gmail.com>
8
+ #
9
+
10
+ require 'optparse'
11
+ require 'pathname'
12
+ require 'pp'
13
+
14
+ #
15
+ # パッケージ内で参照する定数の定義
16
+ #
17
+
18
+ TRADITIONAL_NAME = "Spectrum analyzer for WAV file"
19
+ APP_NAME = "wavlet"
20
+
21
+ BASE_DIR = Pathname.new(File.expand_path(__FILE__)).dirname.parent
22
+ LIB_DIR = BASE_DIR + "lib"
23
+ PKG_LIB_DIR = LIB_DIR + "wavspa"
24
+ APP_LIB_DIR = PKG_LIB_DIR + APP_NAME
25
+
26
+ #
27
+ # ライブラリロードパスの差し込み
28
+ #
29
+
30
+ $LOAD_PATH.unshift(LIB_DIR)
31
+
32
+ #
33
+ # アプリケーション本体の読み込み
34
+ #
35
+
36
+ require "#{PKG_LIB_DIR + "version"}"
37
+ require "#{PKG_LIB_DIR + "common"}"
38
+ require "#{APP_LIB_DIR + "preset"}"
39
+ require "#{APP_LIB_DIR + "main"}"
40
+
41
+ #
42
+ # デフォルトパラメータのセット
43
+ #
44
+
45
+ include WavSpectrumAnalyzer
46
+
47
+ params = WaveLetApp::PRESET_TABLE["default"]
48
+ output = nil
49
+
50
+ #
51
+ # コマンドラインオプションのパース
52
+ #
53
+
54
+ OptionParser.new {|opt|
55
+ opt.banner += " WAV-FILE"
56
+ opt.version = VERSION
57
+
58
+ opt.on("-o", "--output=FILE", String) { |name|
59
+ output = name
60
+ }
61
+
62
+ opt.on("-p", "--preset=NAME", String) { |name|
63
+ name.downcase!
64
+
65
+ if name == "help"
66
+ FFTApp::PRESET_TABLE.keys.each { |str|
67
+ printf(" %s\n", str)
68
+ }
69
+ exit
70
+ end
71
+
72
+ if WaveLetApp::PRESET_TABLE.include?(name)
73
+ params = WaveLetApp::PRESET_TABLE[name]
74
+ else
75
+ STDERR.print("error: unknown preset name.\n")
76
+ exit(1)
77
+ end
78
+ }
79
+
80
+ opt.on("-s", "--sigma=NUMBER", Float) {|val|
81
+ params[:sigma] = val
82
+ }
83
+
84
+ opt.on("-a", "--amplitude-mode", Integer) {|val|
85
+ params[:transform_mode] = :AMPLITUDE
86
+ }
87
+
88
+ opt.on("-u", "--unit-time=CENTISECOND", Integer) {|val|
89
+ params[:unit_time] = val * 10
90
+ }
91
+
92
+ opt.on("-W", "--output-width=SIZE", Integer) {|val|
93
+ params[:output_width] = val
94
+ }
95
+
96
+ opt.on("-r", "--frequency-range=LO,HI", Array) { |val|
97
+ params[:range] = [val[0].to_f, val[1].to_f]
98
+ }
99
+
100
+ opt.on("--floor-gain=DB", Float) {|val|
101
+ params[:floor] = val
102
+ }
103
+
104
+ opt.on("--ceil-gain=DB", Float) {|val|
105
+ params[:ceil] = val
106
+ }
107
+
108
+ opt.on("-m", "--scale-mode=STRING", String) {|name|
109
+ name = name.upcase.to_sym
110
+ if not ["LINEAR", "LOGSCALE"].include?(name)
111
+ STDERR.print("error: unknown scale mode.\n")
112
+ exit(1)
113
+ end
114
+
115
+ params[:scale_mode] = name
116
+ }
117
+
118
+ opt.on("-c", "--col-steps=SIZE", Integer) {|val|
119
+ params[:col_step] = val
120
+ }
121
+
122
+ opt.on("--show-params") {
123
+ printf("sigma %20f\n", params[:sigma])
124
+ printf("unit time %20d msec\n", params[:unit_time])
125
+ printf("scale mode %20s\n", params[:scale_mode].to_s)
126
+ printf("ceiling %20d\n", params[:ceiling].to_s)
127
+ printf("floor %20d\n", params[:floor].to_s)
128
+ printf("frequency range %20s Hz\n",
129
+ ("%.0f - %.0f" % [params[:range][0], params[:range][1]]))
130
+ printf("column steps %20d pixels\n", params[:col_step])
131
+ exit
132
+ }
133
+
134
+ opt.on("-F", "--draw-freq-line") {
135
+ $draw_freq_line = true
136
+ }
137
+
138
+ opt.on("-T", "--draw-time-line") {
139
+ $draw_time_line = true
140
+ }
141
+
142
+ opt.on('-v', "--verbose") {
143
+ $verbose = true
144
+ }
145
+
146
+ opt.parse!(ARGV)
147
+
148
+ if ARGV.empty?
149
+ STDERR.print("error: target file not specified.\n")
150
+ exit(1)
151
+ end
152
+
153
+ output ||= File.basename(ARGV[0], ".wav") + ".png"
154
+ }
155
+
156
+ #
157
+ # アプリケーションの起動
158
+ #
159
+
160
+ WaveLetApp.main(ARGV[0], params, output)
Binary file
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile( "wavspa/fb")