audio_mixer-sox 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 233e6d2955b10fee2f0be11516a479315ba642b9
4
+ data.tar.gz: 410f039e661b7c0ab2a25cef98d3141fb9dca196
5
+ SHA512:
6
+ metadata.gz: 4fa980d8f0208f04b5b8696b7c3f3abc4b1b995f11ba7100f7c4cc6a67128806be279c6ed37bcb5610efa659d7580bfc56b03f0bdf3f2534d8397d05093e08ea
7
+ data.tar.gz: 00a1d80f541ed23e809656d7c28e057276dc4bceb3e18727e250d8cf9974b3aabf668e59faf0e18de7dfb9515709a02f864497aa4f7ab9064958d467faa76f85
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 2.0.0@audio_mixer-sox --create
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 kdunee
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,46 @@
1
+ # AudioMixer::Sox
2
+
3
+ Use AudioMixer::Sox to easily find and store the right balance of volume and panning for multiple sound files.
4
+
5
+ ## Installation
6
+
7
+ First make sure you have [SoX][sox] installed on your machine. On Debian-based Linux distribution try:
8
+
9
+ [sox]: http://sox.sourceforge.net/
10
+
11
+ $ sudo apt-get install sox
12
+
13
+ Then install this gem:
14
+
15
+ $ gem install audio_mixer-sox
16
+
17
+ ## Usage
18
+
19
+ $ audio_mixer-sox [FILE]
20
+
21
+ Where `[FILE]` is a _YAML_ file of the following structure (only the `url` property is really necessary):
22
+
23
+ # sample composition
24
+ ---
25
+ -
26
+ url: "~/workspace/sounds/door_open.ogg"
27
+ repeat: 1.2
28
+ panning: 0.0
29
+ volume: 1.0
30
+ mute: false
31
+ -
32
+ url: "~/workspace/sounds/disappear.ogg"
33
+ repeat: 1.5
34
+ panning: 0.8
35
+ volume: 1.0
36
+ mute: false
37
+
38
+ The mixer should now respond to the changes you make in `[FILE]` on the fly.
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'audio_mixer/sox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "audio_mixer-sox"
8
+ spec.version = AudioMixer::Sox::VERSION
9
+ spec.authors = ["kdunee"]
10
+ spec.email = ["kosmadunikowski@gmail.com"]
11
+ spec.description = "Use AudioMixer::Sox to easily find and store the right balance of volume and panning for multiple sound files."
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'audio_mixer/sox'
4
+
5
+ begin
6
+ abort("Usage audio_mixer-sox [FILE]") if ARGV.size > 1
7
+ abort("#{ARGV[0]} does not exist!") unless File.exists?(ARGV[0])
8
+
9
+ composition = AudioMixer::Sox::Composition.new(ARGV[0])
10
+ sound_server = AudioMixer::Sox::SoundServer.new(composition)
11
+
12
+ loop do
13
+ composition.update! if composition.has_changed?
14
+ sound_server.tick
15
+ sleep 0.01
16
+ end
17
+ rescue Interrupt
18
+ puts "Bye!"
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'audio_mixer/sox/version'
2
+ require 'audio_mixer/sox/composition'
3
+ require 'audio_mixer/sox/sound_server'
@@ -0,0 +1,44 @@
1
+ require 'yaml'
2
+
3
+ module AudioMixer
4
+ module Sox
5
+ class Composition
6
+ attr_reader :sounds
7
+
8
+ def initialize(filename)
9
+ @filename = filename
10
+ update!
11
+ end
12
+
13
+ def has_changed?
14
+ File.new(@filename, "r").mtime > @last_mtime
15
+ rescue Errno::ENOENT
16
+ puts "Composition file unavailable!"
17
+ end
18
+
19
+ def update!
20
+ YAML.load_file(@filename).tap do |collection|
21
+ if collection_is_valid?(collection)
22
+ @sounds = collection
23
+ puts "Composition file updated..."
24
+ end
25
+ end
26
+ rescue Psych::SyntaxError
27
+ puts "Composition file corrupted, ignoring..."
28
+ ensure
29
+ @last_mtime = Time.now
30
+ end
31
+
32
+ private
33
+
34
+ def collection_is_valid?(collection)
35
+ collection.is_a?(Enumerable) && collection.all? { |sound| sound_is_valid?(sound) }
36
+ end
37
+
38
+ def sound_is_valid?(sound)
39
+ sound.respond_to?(:[]) && sound["url"] != nil && File.exists?(File.expand_path(sound["url"]))
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,52 @@
1
+ module AudioMixer
2
+ module Sox
3
+ class SoundServer
4
+
5
+ def initialize(composition)
6
+ @composition = composition
7
+ @sound_buffers = {}
8
+ @timeouts = Hash.new(0)
9
+ end
10
+
11
+ def tick
12
+ cache_sounds
13
+ play_sounds
14
+ end
15
+
16
+ private
17
+
18
+ def play_sounds
19
+ Time.now.to_f.tap { |time| @delta_time, @last_time = time - (@last_time || time), time }
20
+
21
+ (0..@composition.sounds.size-1).each do |index|
22
+ sound = @composition.sounds[index]
23
+ if (@timeouts[index] -= @delta_time) < 0
24
+ @timeouts[index] = sound["repeat"] || 1.0
25
+ play_sound(sound) unless sound["mute"]
26
+ end
27
+ end
28
+ end
29
+
30
+ def cache_sounds
31
+ @composition.sounds.each do |sound|
32
+ @sound_buffers[sound["url"]] ||= load_raw_sound(sound["url"])
33
+ end
34
+ end
35
+
36
+ def load_raw_sound(url)
37
+ IO.popen("sox #{File.expand_path(url)} -p", "rb") do |io|
38
+ io.read
39
+ end
40
+ end
41
+
42
+ def play_sound(sound)
43
+ Thread.new do
44
+ IO.popen("sox -v #{sound["volume"] || 1.0} -p -d pan #{sound["panning"] || 0.0} > /dev/null 2>&1", "wb") do |io|
45
+ io.write(@sound_buffers[sound["url"]])
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module AudioMixer
2
+ module Sox
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: audio_mixer-sox
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - kdunee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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
+ description: Use AudioMixer::Sox to easily find and store the right balance of volume
42
+ and panning for multiple sound files.
43
+ email:
44
+ - kosmadunikowski@gmail.com
45
+ executables:
46
+ - audio_mixer-sox
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - .rvmrc
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - audio_mixer-sox.gemspec
57
+ - bin/audio_mixer-sox
58
+ - lib/audio_mixer/sox.rb
59
+ - lib/audio_mixer/sox/composition.rb
60
+ - lib/audio_mixer/sox/sound_server.rb
61
+ - lib/audio_mixer/sox/version.rb
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Use AudioMixer::Sox to easily find and store the right balance of volume
86
+ and panning for multiple sound files.
87
+ test_files: []