rubberband-audio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Add dependencies to develop your gem here.
4
+ # Include everything needed to run rake, tests, features, etc.
5
+ group :development do
6
+ gem "rspec", "~> 2.3.0"
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "jeweler", "~> 1.6.4"
9
+ gem "pry"
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Francis Chong
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = rubberband-audio
2
+
3
+ Ruby interface for [Rubber Band Library](http://breakfastquay.com/rubberband/).
4
+
5
+ == Usage
6
+
7
+
8
+
9
+ == Reference
10
+
11
+ Rubber Band [Usage](http://breakfastquay.com/rubberband/usage.txt)
12
+
13
+ == Contributing to rubberband-audio
14
+
15
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
16
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
17
+ * Fork the project
18
+ * Start a feature/bugfix branch
19
+ * Commit and push until you are happy with your contribution
20
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2012 Francis Chong. See LICENSE.txt for
26
+ further details.
27
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rubberband-audio"
18
+ gem.homepage = "http://github.com/siuying/rubberband-audio"
19
+ gem.license = "GPL"
20
+ gem.summary = %Q{Wrapper for Rubber Band library}
21
+ gem.description = %Q{Ruby Wrapper for Rubber Band library for changing the speed and pitch of audio recordings.}
22
+ gem.email = "francis@ignition.hk"
23
+ gem.authors = ["Francis Chong"]
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+ require 'rspec/core'
28
+ require 'rspec/core/rake_task'
29
+ RSpec::Core::RakeTask.new(:spec) do |spec|
30
+ spec.pattern = FileList['spec/**/*_spec.rb']
31
+ end
32
+
33
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "rubberband-audio #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,2 @@
1
+ require 'rubberband/options'
2
+ require 'rubberband/processor'
@@ -0,0 +1,72 @@
1
+ module RubberBand
2
+ class Options < Hash
3
+ BINARY_OPTIONS = %w{formant precise realtime no_threads threads
4
+ no_transients bl_transients no_lamination
5
+ window_long window_short detector_perc
6
+ detector_soft pitch_hq}
7
+
8
+ def initialize(options={})
9
+ merge!(options)
10
+ end
11
+
12
+ def to_s
13
+ params = collect do |key, value|
14
+ send("convert_#{key}", value) if value && supports_option?(key)
15
+ end
16
+
17
+ params_string = params.join(" ")
18
+ params_string << " -q"
19
+ params_string
20
+ end
21
+
22
+ private
23
+ def supports_option?(option)
24
+ option = RUBY_VERSION < "1.9" ? "convert_#{option}" : "convert_#{option}".to_sym
25
+ private_methods.include?(option)
26
+ end
27
+
28
+ def convert_time(value)
29
+ "--time #{value}"
30
+ end
31
+
32
+ def convert_tempo(value)
33
+ "--tempo #{value}"
34
+ end
35
+
36
+ def convert_duration(value)
37
+ "--duration #{value}"
38
+ end
39
+
40
+ def convert_pitch(value)
41
+ "--pitch #{value}"
42
+ end
43
+
44
+ def convert_frequency(value)
45
+ "--frequency #{value}"
46
+ end
47
+
48
+ def convert_timemap(value)
49
+ "--timemap \"#{value}\""
50
+ end
51
+
52
+ def convert_crisp(value)
53
+ "--crisp #{value}"
54
+ end
55
+
56
+ def self.convert_binary_params(name)
57
+ class_eval "
58
+ private
59
+ def convert_#{name}(value)
60
+ if value
61
+ '--#{name}'
62
+ else
63
+ ''
64
+ end
65
+ end"
66
+ end
67
+
68
+ BINARY_OPTIONS.each do |name|
69
+ convert_binary_params name.to_sym
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,61 @@
1
+ require 'open3'
2
+ require 'shellwords'
3
+
4
+ module RubberBand
5
+ class Processor
6
+ def initialize(input_file, output_file, options = Options.new)
7
+ @input_file = input_file
8
+ @output_file = output_file
9
+
10
+ if options.is_a?(String) || options.is_a?(Options)
11
+ @raw_options = options
12
+ elsif options.is_a?(Hash)
13
+ @raw_options = Options.new(options)
14
+ else
15
+ raise ArgumentError, "Unknown options format '#{options.class}', should be either EncodingOptions, Hash or String."
16
+ end
17
+ end
18
+
19
+ def binary
20
+ binary_path = system("which rubberband")
21
+ if $? == 0
22
+ binary_path
23
+ else
24
+ raise "rubberband binary not found!"
25
+ end
26
+ end
27
+
28
+ def run
29
+ command = "#{binary} #{@raw_options} #{Shellwords.escape(@input_file.path)} '#{Shellwords.escape(@output_file)}'"
30
+
31
+ Open3.popen3(command) do |stdin, stdout, stderr|
32
+ yield(0.0) if block_given?
33
+
34
+ stderr.each("r") do |line|
35
+ output << line
36
+ if line =~ /(\d+)%/ # ffmpeg 0.8 and above style
37
+ progress = $1.to_f / 100.0
38
+ yield(progress)
39
+ end
40
+ end
41
+ end
42
+
43
+ if convert_succeeded?
44
+ yield(1.0)
45
+ true
46
+ else
47
+ errors = @errors.empty? ? "" : " Errors: #{@errors.join(", ")}. "
48
+ raise "Failed encoding.#{errors}Full output: #{output}"
49
+ end
50
+ end
51
+
52
+ def convert_succeeded?
53
+ unless File.exists?(@output_file)
54
+ @errors << "no output file created"
55
+ return false
56
+ end
57
+ true
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rubberband-audio"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Francis Chong"]
12
+ s.date = "2012-03-11"
13
+ s.description = "Ruby Wrapper for Rubber Band library for changing the speed and pitch of audio recordings."
14
+ s.email = "francis@ignition.hk"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/rubberband-audio.rb",
28
+ "lib/rubberband/options.rb",
29
+ "lib/rubberband/processor.rb",
30
+ "rubberband-audio.gemspec",
31
+ "spec/options_spec.rb",
32
+ "spec/processor_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/siuying/rubberband-audio"
36
+ s.licenses = ["GPL"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.15"
39
+ s.summary = "Wrapper for Rubber Band library"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
48
+ s.add_development_dependency(%q<pry>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
51
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
+ s.add_dependency(%q<pry>, [">= 0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
59
+ s.add_dependency(%q<pry>, [">= 0"])
60
+ end
61
+ end
62
+
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'rubberband-audio'
4
+
5
+ describe RubberBand::Options do
6
+ describe "basic" do
7
+ it "should use quite" do
8
+ RubberBand::Options.new.to_s.should =~ /-q/
9
+ end
10
+ end
11
+
12
+ describe "configurable parameters" do
13
+ it "should support time" do
14
+ o = RubberBand::Options.new(:time => "360")
15
+ o.to_s.should =~ /--time 360/
16
+ end
17
+
18
+ it "should support tempo" do
19
+ o = RubberBand::Options.new(:tempo => 360)
20
+ o.to_s.should =~ /--tempo 360/
21
+ end
22
+
23
+ it "should support duration" do
24
+ o = RubberBand::Options.new(:duration => 200)
25
+ o.to_s.should =~ /--duration 200/
26
+ end
27
+
28
+ it "should support pitch" do
29
+ o = RubberBand::Options.new(:pitch => 4)
30
+ o.to_s.should =~ /--pitch 4/
31
+ end
32
+
33
+ it "should support frequency" do
34
+ o = RubberBand::Options.new(:frequency => 4)
35
+ o.to_s.should =~ /--frequency 4/
36
+ end
37
+
38
+ it "should support timemap" do
39
+ o = RubberBand::Options.new(:timemap => "/tmp/file0123")
40
+ o.to_s.should =~ %r{--timemap "/tmp/file0123"}
41
+ end
42
+
43
+ context "should support crispness" do
44
+ it "should accept crisp params" do
45
+ o = RubberBand::Options.new(:crisp => 5)
46
+ o.to_s.should =~ %r{--crisp 5}
47
+ end
48
+ end
49
+
50
+ RubberBand::Options::BINARY_OPTIONS.each do |name|
51
+ it "should support #{name} mode" do
52
+ o = RubberBand::Options.new(name.to_sym => true)
53
+ o.to_s.should =~ /--#{name}/
54
+
55
+ o = RubberBand::Options.new(name.to_sym => false)
56
+ o.to_s.should_not =~ /--#{name}/
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'rubberband-audio'
4
+
5
+ describe RubberBand::Processor do
6
+ subject { RubberBand::Processor.new("a", "b") }
7
+
8
+ it "should return path" do
9
+ subject.binary.should =~ /rubberband/
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rubberband-audio'
5
+ require 'pry'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubberband-audio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Francis Chong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70113346520620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70113346520620
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &70113346520140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70113346520140
36
+ - !ruby/object:Gem::Dependency
37
+ name: jeweler
38
+ requirement: &70113346519480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.6.4
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70113346519480
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: &70113346719680 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70113346719680
58
+ description: Ruby Wrapper for Rubber Band library for changing the speed and pitch
59
+ of audio recordings.
60
+ email: francis@ignition.hk
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - .rspec
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.rdoc
72
+ - Rakefile
73
+ - VERSION
74
+ - lib/rubberband-audio.rb
75
+ - lib/rubberband/options.rb
76
+ - lib/rubberband/processor.rb
77
+ - rubberband-audio.gemspec
78
+ - spec/options_spec.rb
79
+ - spec/processor_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: http://github.com/siuying/rubberband-audio
82
+ licenses:
83
+ - GPL
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -4203669127066921999
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.15
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Wrapper for Rubber Band library
109
+ test_files: []