mml2wav 0.0.1

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
+ SHA1:
3
+ metadata.gz: 05336b0d10a736402a502dfc2c1949e129e84377
4
+ data.tar.gz: 9341b84d926a6c3a120e775aac4ae1789358e9d4
5
+ SHA512:
6
+ metadata.gz: 3ab94e18b6ca8c6b8ba78d0a87f1397b4ed187b86073083cd57f4a0928fa87a3ba5545e02e1dabe9a0ffcb30772aba61e9eb9e5695ba07a6cb52f4cff89ee54a
7
+ data.tar.gz: 918b643d4a3809ab117beb2f3980d3c6e45ffeb9d1e11c26d5080d01d5942ca7545060068af2fa959a0615d1157a13aada3e69699289034a5d5ce5abe67e0f81
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ /.bundle/
2
+ /Gemfile.lock
3
+ /pkg/
4
+ /tmp/
5
+
6
+ *.wav
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mml2wav.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Masafumi Yokoyama <myokoym@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # mml2wav
2
+
3
+ MML (Music Macro Language) to WAV audio converter by Ruby.
4
+
5
+ ## Dependencies
6
+
7
+ * [jstrait/wavefile](https://github.com/jstrait/wavefile)
8
+
9
+ ## Installation
10
+
11
+ $ gem install mml2wav
12
+
13
+ ## Usage
14
+
15
+ $ mml2wav XXX.mml
16
+
17
+ Or
18
+
19
+ $ echo 'MML TEXT' | mml2wav
20
+
21
+ ## Suppoted MML features
22
+
23
+ ### do re mi...
24
+
25
+ MML | doremi
26
+ --- | ------
27
+ c | do
28
+ d | re
29
+ e | mi
30
+ f | fa
31
+ g | so
32
+ a | la
33
+ b | si
34
+
35
+ ### signs
36
+
37
+ MML | mean
38
+ --- | ------
39
+ r | rest
40
+
41
+ ## License
42
+
43
+ MIT License. See LICENSE.txt for details.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/mml2wav ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mml2wav/command"
4
+
5
+ Mml2wav::Command.run(ARGV)
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ echo 'cdefedcr efgagfer crcrcrcr ccddeefferdrc' | mml2wav --output=kaerunouta.wav
4
+ aplay kaerunouta.wav
data/lib/mml2wav.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "mml2wav/scale"
2
+ require "mml2wav/version"
3
+ require "mml2wav/wave"
@@ -0,0 +1,44 @@
1
+ require "optparse"
2
+ require "mml2wav/version"
3
+ require "mml2wav/wave"
4
+
5
+ module Mml2wav
6
+ class Command
7
+ def self.run(arguments)
8
+ new(arguments).run
9
+ end
10
+
11
+ def initialize(arguments)
12
+ @options = parse_options(arguments)
13
+ @sounds = ARGF.readlines.join(" ")
14
+ end
15
+
16
+ def run
17
+ Wave.write(@sounds, @options)
18
+ end
19
+
20
+ private
21
+ def parse_options(arguments)
22
+ options = {}
23
+
24
+ parser = OptionParser.new("#{$0} INPUT_FILE")
25
+ parser.version = VERSION
26
+
27
+ parser.on("--output=FILE", "Specify output file path") do |path|
28
+ options[:output] = path
29
+ end
30
+ parser.on("--sampling_rate=RATE",
31
+ "Specify sampling rate", Integer) do |rate|
32
+ options[:sampling_rate] = rate
33
+ end
34
+ parser.parse!(arguments)
35
+
36
+ unless File.pipe?('/dev/stdin') || IO.select([ARGF], nil, nil, 0)
37
+ puts(parser.help)
38
+ exit(true)
39
+ end
40
+
41
+ options
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ module Mml2wav
2
+ module Scale
3
+ FREQUENCIES = {
4
+ c: 261.626,
5
+ d: 293.665,
6
+ e: 329.628,
7
+ f: 349.228,
8
+ g: 391.995,
9
+ a: 440.000,
10
+ b: 493.883,
11
+ r: 0,
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Mml2wav
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ require "wavefile"
2
+ require "mml2wav/scale"
3
+
4
+ module Mml2wav
5
+ class Wave
6
+ class << self
7
+ include WaveFile
8
+
9
+ def write(sounds, options={})
10
+ output_path = options[:output] || "doremi.wav"
11
+ sampling_rate = options[:sampling_rate] || 8000
12
+
13
+ format = Format.new(:mono, :pcm_8, sampling_rate)
14
+ @sine_waves = {}
15
+ Writer.new(output_path, format) do |writer|
16
+ buffer_format = Format.new(:mono, :float, sampling_rate)
17
+ sounds.split(//).each do |sound|
18
+ frequency = Scale::FREQUENCIES[sound.downcase.to_sym]
19
+ next unless frequency
20
+ @sine_waves[sound] ||= sine_wave(frequency, sampling_rate)
21
+ samples = @sine_waves[sound]
22
+ buffer = Buffer.new(samples, buffer_format)
23
+ writer.write(buffer)
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+ def sine_wave(frequency, sampling_rate, sec=0.1, amplitude=0.5)
30
+ max = sampling_rate * sec
31
+ if frequency == 0
32
+ return Array.new(max) { 0.0 }
33
+ end
34
+ base_x = 2.0 * Math::PI * frequency / sampling_rate
35
+ 1.upto(max).collect do |n|
36
+ amplitude * Math.sin(base_x * n)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
data/mml2wav.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mml2wav/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mml2wav"
8
+ spec.version = Mml2wav::VERSION
9
+ spec.authors = ["Masafumi Yokoyama"]
10
+ spec.email = ["myokoym@gmail.com"]
11
+ spec.description = %q{MML (Music Macro Language) to WAV audio converter by Ruby.}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/myokoym/mml2wav"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency("wavefile")
22
+
23
+ spec.add_development_dependency("bundler")
24
+ spec.add_development_dependency("rake")
25
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mml2wav
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masafumi Yokoyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wavefile
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: MML (Music Macro Language) to WAV audio converter by Ruby.
56
+ email:
57
+ - myokoym@gmail.com
58
+ executables:
59
+ - mml2wav
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/mml2wav
69
+ - examples/kaerunouta.sh
70
+ - lib/mml2wav.rb
71
+ - lib/mml2wav/command.rb
72
+ - lib/mml2wav/scale.rb
73
+ - lib/mml2wav/version.rb
74
+ - lib/mml2wav/wave.rb
75
+ - mml2wav.gemspec
76
+ homepage: https://github.com/myokoym/mml2wav
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: MML (Music Macro Language) to WAV audio converter by Ruby.
100
+ test_files: []
101
+ has_rdoc: