mml2wav 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 4cbdd2cc35197a65e4d8065938b269a33107958e
4
- data.tar.gz: a5520c6bab70019d406db2768480202c7a283b92
3
+ metadata.gz: f0b325f6a24997c7eb3e5809c9d88157e8a716c9
4
+ data.tar.gz: 988565abd717f2d4f0da47cbfcac11f9d4946420
5
5
  SHA512:
6
- metadata.gz: 6a4a662e1be6f29c0436fc9b4719497428f829be31f5ca88ba9fd94954bcfcc8c671a59563d375cde177e6c668709c8c647f04dfff7170dab80edddbaeb4018a
7
- data.tar.gz: 6948108039e53bb0c81bf7a596423fd38643983f8f69d3ecb22f553ab585e0b0bf5e82d26e70a2b438b8d1a0d6f79ff366f1824b5662c343b6f0e9e49e731ad7
6
+ metadata.gz: b36f80ab26a4485faee59d4314d12ee2d42e6e98dfd29bee78eef9abe1c8ab234d521665847a1f89b4e9ec9ab748ac152c3381cb6ee8d6c763e9690f96c2b7ce
7
+ data.tar.gz: ae63294edd22fa5b5b2c8525cd73eeed9deaf2ac24294f489a11056b6a9496bd00bb21edc39e74ec7d03d668245ae3e51dde89616bd6f09d71bb3a92152b2224
data/NEWS.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.0.6: 2016-04-14
4
+
5
+ ### Improvements
6
+
7
+ * Make Parser useful.
8
+
9
+ ### Fixes
10
+
11
+ * Added missing require.
12
+
3
13
  ## 0.0.5: 2015-05-03
4
14
 
5
15
  ### Improvements
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ task :test do
4
+ ruby("test/run-test.rb")
5
+ end
6
+
7
+ task :default => :test
@@ -1,3 +1,4 @@
1
+ require "mml2wav/parser"
1
2
  require "mml2wav/scale"
2
3
  require "mml2wav/version"
3
4
  require "mml2wav/wave"
@@ -11,12 +11,11 @@ module Mml2wav
11
11
  @octave = options[:octave] || 4
12
12
  @default_length = options[:default_length] || 4.0
13
13
  @octave_reverse = options[:octave_reverse] || false
14
- @cursor = 0
15
14
  end
16
15
 
17
- def wave!
18
- @cursor.upto(@sounds.size - 1) do |i|
19
- sound = @sounds[i]
16
+ def parse
17
+ infos = []
18
+ @sounds.each do |sound|
20
19
  base_sec = 60.0 * 4
21
20
  length = @default_length
22
21
  case sound
@@ -60,23 +59,15 @@ module Mml2wav
60
59
  frequency = Scale::FREQUENCIES[sound.downcase]
61
60
  next unless frequency
62
61
  frequency *= (2 ** @octave)
63
- wave = sine_wave(frequency, @sampling_rate, sec, amplitude)
64
- @cursor = i + 1
65
- return wave
66
- end
67
- nil
68
- end
69
-
70
- private
71
- def sine_wave(frequency, sampling_rate, sec, amplitude=0.5)
72
- max = sampling_rate * sec
73
- if frequency == 0
74
- return Array.new(max) { 0.0 }
75
- end
76
- base_x = 2.0 * Math::PI * frequency / sampling_rate
77
- 1.upto(max).collect do |n|
78
- amplitude * Math.sin(base_x * n)
62
+ infos << {
63
+ sound: sound.downcase,
64
+ frequency: frequency,
65
+ sampling_rate: @sampling_rate,
66
+ sec: sec,
67
+ amplitude: amplitude,
68
+ }
79
69
  end
70
+ infos
80
71
  end
81
72
  end
82
73
  end
@@ -1,3 +1,3 @@
1
1
  module Mml2wav
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -27,15 +27,19 @@ module Mml2wav
27
27
  format = Format.new(n_channels, :pcm_8, sampling_rate)
28
28
  Writer.new(output_path, format) do |writer|
29
29
  buffer_format = Format.new(n_channels, :float, sampling_rate)
30
- parsers = []
30
+ infoses = []
31
31
  soundses.each do |sounds|
32
- parsers << Parser.new(sounds, sampling_rate, options)
32
+ infoses << Parser.new(sounds, sampling_rate, options).parse
33
33
  end
34
- waves = Array.new(parsers.size) { [] }
35
- loop do
36
- parsers.each_with_index do |parser, i|
37
- wave = parser.wave!
38
- waves[i] += wave if wave
34
+ waves = Array.new(soundses.size) { [] }
35
+ 0.upto(infoses.collect {|info| info.size }.max) do |infos_index|
36
+ infoses.each_with_index do |infos, infoses_index|
37
+ next unless infos[infos_index]
38
+ wave = sine_wave(infos[infos_index][:frequency],
39
+ infos[infos_index][:sampling_rate],
40
+ infos[infos_index][:sec],
41
+ infos[infos_index][:amplitude])
42
+ waves[infoses_index] += wave
39
43
  end
40
44
  break if waves.all? {|wave| wave.empty? }
41
45
  buffer_size = waves.reject {|wave| wave.empty? }.collect(&:size).min
@@ -57,6 +61,17 @@ module Mml2wav
57
61
  end
58
62
  end
59
63
  end
64
+
65
+ def sine_wave(frequency, sampling_rate, sec, amplitude=0.5)
66
+ max = sampling_rate * sec
67
+ if frequency == 0
68
+ return Array.new(max) { 0.0 }
69
+ end
70
+ base_x = 2.0 * Math::PI * frequency / sampling_rate
71
+ 1.upto(max).collect do |n|
72
+ amplitude * Math.sin(base_x * n)
73
+ end
74
+ end
60
75
  end
61
76
  end
62
77
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency("wavefile")
22
22
 
23
+ spec.add_development_dependency("test-unit")
23
24
  spec.add_development_dependency("bundler")
24
25
  spec.add_development_dependency("rake")
25
26
  end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ base_dir = File.expand_path("..", File.dirname(__FILE__))
4
+ lib_dir = File.join(base_dir, "lib")
5
+ test_dir = File.join(base_dir, "test")
6
+ $LOAD_PATH.unshift(lib_dir)
7
+ $LOAD_PATH.unshift(test_dir)
8
+
9
+ require "test-unit"
10
+
11
+ exit Test::Unit::AutoRunner.run(true, test_dir)
@@ -0,0 +1,129 @@
1
+ require "mml2wav/parser"
2
+
3
+ class TestParser < Test::Unit::TestCase
4
+ def test_a_scale
5
+ parser = Mml2wav::Parser.new("c", 8000)
6
+ assert_equal([
7
+ {
8
+ sound: "c",
9
+ frequency: 523.252,
10
+ sampling_rate: 8000,
11
+ sec: 0.5,
12
+ amplitude: 0.5,
13
+ },
14
+ ],
15
+ parser.parse)
16
+ end
17
+
18
+ def test_length
19
+ parser = Mml2wav::Parser.new("c8", 8000)
20
+ assert_equal([
21
+ {
22
+ sound: "c",
23
+ frequency: 523.252,
24
+ sampling_rate: 8000,
25
+ sec: 0.25,
26
+ amplitude: 0.5,
27
+ },
28
+ ],
29
+ parser.parse)
30
+ end
31
+
32
+ def test_dot
33
+ parser = Mml2wav::Parser.new("c.", 8000)
34
+ assert_equal([
35
+ {
36
+ sound: "c",
37
+ frequency: 523.252,
38
+ sampling_rate: 8000,
39
+ sec: 0.75,
40
+ amplitude: 0.5,
41
+ },
42
+ ],
43
+ parser.parse)
44
+ end
45
+
46
+ def test_length_with_dot
47
+ parser = Mml2wav::Parser.new("c8.", 8000)
48
+ assert_equal([
49
+ {
50
+ sound: "c",
51
+ frequency: 523.252,
52
+ sampling_rate: 8000,
53
+ sec: 0.375,
54
+ amplitude: 0.5,
55
+ },
56
+ ],
57
+ parser.parse)
58
+ end
59
+
60
+ def test_a_tie
61
+ parser = Mml2wav::Parser.new("c&c", 8000, bpm: 60)
62
+ assert_equal([
63
+ {
64
+ sound: "c",
65
+ frequency: 523.252,
66
+ sampling_rate: 8000,
67
+ sec: 2.0,
68
+ amplitude: 0.5,
69
+ },
70
+ ],
71
+ parser.parse)
72
+ end
73
+
74
+ def test_a_tie_with_length
75
+ parser = Mml2wav::Parser.new("c&c16", 8000, bpm: 60)
76
+ assert_equal([
77
+ {
78
+ sound: "c",
79
+ frequency: 523.252,
80
+ sampling_rate: 8000,
81
+ sec: 1.25,
82
+ amplitude: 0.5,
83
+ },
84
+ ],
85
+ parser.parse)
86
+ end
87
+
88
+ def test_a_tie_with_dot
89
+ parser = Mml2wav::Parser.new("c&c.", 8000, bpm: 60)
90
+ assert_equal([
91
+ {
92
+ sound: "c",
93
+ frequency: 523.252,
94
+ sampling_rate: 8000,
95
+ sec: 2.5,
96
+ amplitude: 0.5,
97
+ },
98
+ ],
99
+ parser.parse)
100
+ end
101
+
102
+ def test_a_tie_with_length_with_dot
103
+ parser = Mml2wav::Parser.new("c&c2.", 8000, bpm: 60)
104
+ assert_equal([
105
+ {
106
+ sound: "c",
107
+ frequency: 523.252,
108
+ sampling_rate: 8000,
109
+ sec: 4.0,
110
+ amplitude: 0.5,
111
+ },
112
+ ],
113
+ parser.parse)
114
+ end
115
+
116
+ def test_ties
117
+ parser = Mml2wav::Parser.new("c&c&c", 8000, bpm: 60)
118
+ assert_equal([
119
+ {
120
+ sound: "c",
121
+ frequency: 523.252,
122
+ sampling_rate: 8000,
123
+ sec: 3.0,
124
+ amplitude: 0.5,
125
+ },
126
+ ],
127
+ parser.parse)
128
+ end
129
+ end
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.5
4
+ version: 0.0.6
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-05-03 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wavefile
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-unit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +89,8 @@ files:
75
89
  - lib/mml2wav/version.rb
76
90
  - lib/mml2wav/wave.rb
77
91
  - mml2wav.gemspec
92
+ - test/run-test.rb
93
+ - test/test-parser.rb
78
94
  homepage: https://github.com/myokoym/mml2wav
79
95
  licenses:
80
96
  - MIT
@@ -95,9 +111,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
111
  version: '0'
96
112
  requirements: []
97
113
  rubyforge_project:
98
- rubygems_version: 2.4.5
114
+ rubygems_version: 2.5.1
99
115
  signing_key:
100
116
  specification_version: 4
101
117
  summary: MML (Music Macro Language) to WAV audio converter by pure Ruby.
102
- test_files: []
118
+ test_files:
119
+ - test/run-test.rb
120
+ - test/test-parser.rb
103
121
  has_rdoc: