mml2wav 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -2
- data/examples/kaerunouta.sh +1 -1
- data/lib/mml2wav/command.rb +4 -0
- data/lib/mml2wav/scale.rb +18 -8
- data/lib/mml2wav/version.rb +1 -1
- data/lib/mml2wav/wave.rb +34 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd7a4796c9f409d00b80f36bab6500965ebfcccf
|
4
|
+
data.tar.gz: c07c86df8f9a0fe8121a2774a885d311548fab66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21edb3881d011862b646a69f32bfad62325c924e7be9daa30e5587be76f1050fcbd174cf2ae179e746ae4b0663d61838a014ba4e8e03d31a5ee92c2cbbe03dc
|
7
|
+
data.tar.gz: 7123c9626a12a1302ded2e1b26ce5eadc751860154567f15379c4de424b07e7ad127cfa687086c01849240e6e36328402216b27eecc533bc405b2fb3a2a11097
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# mml2wav
|
1
|
+
# mml2wav [![Gem Version](https://badge.fury.io/rb/mml2wav.svg)](http://badge.fury.io/rb/mml2wav)
|
2
2
|
|
3
3
|
MML (Music Macro Language) to WAV audio converter by Ruby.
|
4
4
|
|
@@ -32,11 +32,25 @@ g | so
|
|
32
32
|
a | la
|
33
33
|
b | si
|
34
34
|
|
35
|
+
### length
|
36
|
+
|
37
|
+
MML | length
|
38
|
+
--- | -----------------------------
|
39
|
+
c4 | 1/4 (default)
|
40
|
+
c8 | 1/8
|
41
|
+
c16 | 1/16
|
42
|
+
c. | 1.5 times longer than default
|
43
|
+
|
35
44
|
### signs
|
36
45
|
|
37
46
|
MML | mean
|
38
|
-
--- |
|
47
|
+
--- | --------------
|
39
48
|
r | rest
|
49
|
+
t90 | BPM
|
50
|
+
l4 | default length
|
51
|
+
o4 | octave
|
52
|
+
< | up octave
|
53
|
+
> | down octave
|
40
54
|
|
41
55
|
## License
|
42
56
|
|
data/examples/kaerunouta.sh
CHANGED
data/lib/mml2wav/command.rb
CHANGED
@@ -31,6 +31,10 @@ module Mml2wav
|
|
31
31
|
"Specify sampling rate", Integer) do |rate|
|
32
32
|
options[:sampling_rate] = rate
|
33
33
|
end
|
34
|
+
parser.on("--bpm=BPM",
|
35
|
+
"Specify BPM (beats per minute)", Integer) do |bpm|
|
36
|
+
options[:bpm] = bpm
|
37
|
+
end
|
34
38
|
parser.parse!(arguments)
|
35
39
|
|
36
40
|
unless File.pipe?('/dev/stdin') || IO.select([ARGF], nil, nil, 0)
|
data/lib/mml2wav/scale.rb
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
module Mml2wav
|
2
2
|
module Scale
|
3
3
|
FREQUENCIES = {
|
4
|
-
c
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
"c" => 32.70325 ,
|
5
|
+
"c#" => 34.647875,
|
6
|
+
"c+" => 34.647875,
|
7
|
+
"d" => 36.708125,
|
8
|
+
"d#" => 38.890875,
|
9
|
+
"d+" => 38.890875,
|
10
|
+
"e" => 41.2035 ,
|
11
|
+
"f" => 43.6535 ,
|
12
|
+
"f#" => 46.24925 ,
|
13
|
+
"f+" => 46.24925 ,
|
14
|
+
"g" => 48.999375,
|
15
|
+
"g#" => 51.913125,
|
16
|
+
"g+" => 51.913125,
|
17
|
+
"a" => 55.0 ,
|
18
|
+
"a#" => 58.2705 ,
|
19
|
+
"a+" => 58.2705 ,
|
20
|
+
"b" => 61.735375,
|
21
|
+
"r" => 0,
|
12
22
|
}
|
13
23
|
end
|
14
24
|
end
|
data/lib/mml2wav/version.rb
CHANGED
data/lib/mml2wav/wave.rb
CHANGED
@@ -8,17 +8,44 @@ module Mml2wav
|
|
8
8
|
|
9
9
|
def write(sounds, options={})
|
10
10
|
output_path = options[:output] || "doremi.wav"
|
11
|
-
sampling_rate = options[:sampling_rate] ||
|
11
|
+
sampling_rate = options[:sampling_rate] || 22050
|
12
|
+
bpm = options[:bpm] || 60
|
13
|
+
velocity = 5
|
14
|
+
octave = 4
|
15
|
+
default_length = 4.0
|
12
16
|
|
13
17
|
format = Format.new(:mono, :pcm_8, sampling_rate)
|
14
|
-
@sine_waves = {}
|
15
18
|
Writer.new(output_path, format) do |writer|
|
16
19
|
buffer_format = Format.new(:mono, :float, sampling_rate)
|
17
|
-
sounds.
|
18
|
-
|
20
|
+
sounds.scan(/T\d+|V\d+|L\d+|[A-G][#+]?(?:\d+|\.)?|O\d+|[><]|./i).each do |sound|
|
21
|
+
base_sec = 60.0
|
22
|
+
length = default_length
|
23
|
+
case sound
|
24
|
+
when /\AT(\d+)/i
|
25
|
+
bpm = $1.to_i
|
26
|
+
when /\AV(\d+)/i
|
27
|
+
velocity = $1.to_i
|
28
|
+
when /\AL(\d+)/i
|
29
|
+
default_length = $1.to_f
|
30
|
+
when /\A([A-G][#+]?)(\d+)/i
|
31
|
+
length = $2.to_f
|
32
|
+
sound = $1
|
33
|
+
when /\A([A-G][#+]?)(\.)/i
|
34
|
+
length = default_length / 1.5
|
35
|
+
sound = $1
|
36
|
+
when /\AO(\d+)/i
|
37
|
+
octave = $1.to_i
|
38
|
+
when "<"
|
39
|
+
octave += 1
|
40
|
+
when ">"
|
41
|
+
octave -= 1
|
42
|
+
end
|
43
|
+
sec = base_sec / length / bpm
|
44
|
+
amplitude = velocity.to_f / 10
|
45
|
+
frequency = Scale::FREQUENCIES[sound.downcase]
|
19
46
|
next unless frequency
|
20
|
-
|
21
|
-
samples =
|
47
|
+
frequency *= (2 ** octave)
|
48
|
+
samples = sine_wave(frequency, sampling_rate, sec, amplitude)
|
22
49
|
buffer = Buffer.new(samples, buffer_format)
|
23
50
|
writer.write(buffer)
|
24
51
|
end
|
@@ -26,7 +53,7 @@ module Mml2wav
|
|
26
53
|
end
|
27
54
|
|
28
55
|
private
|
29
|
-
def sine_wave(frequency, sampling_rate, sec
|
56
|
+
def sine_wave(frequency, sampling_rate, sec, amplitude=0.5)
|
30
57
|
max = sampling_rate * sec
|
31
58
|
if frequency == 0
|
32
59
|
return Array.new(max) { 0.0 }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mml2wav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masafumi Yokoyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wavefile
|