zappa 0.0.1

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: 9023032146667f3a56103972668db8b509523a40
4
+ data.tar.gz: 0518855d8507741d5b9b46f294fcef41c74bb09e
5
+ SHA512:
6
+ metadata.gz: 15d39fad530e36503cd55f22c91293d01d68d67280bbe56c24095d76b5fba34de4bf4d429b265620cc7eabf0d082a7d8a32bc3544f80432ecf0f9bb817bb7ca3
7
+ data.tar.gz: 8cc0ff30f8583cdc5a0d917ea552183a71f4fd6df5fdedd85fc6c9b1d046672ae71f2dec33341668bbeef42b62438a774397f4b93b30d0fa8482878bd39ec072
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zappa.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Varun Srinivasan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Varun Srinivasan
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
+ # Zappa
2
+
3
+ Zappa is a high level audio manipulation library for Ruby, inspired by pydub.
4
+
5
+ ## Installation
6
+
7
+ First install ffmpeg:
8
+
9
+ brew install ffmpeg
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'zappa'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install zappa
22
+
23
+ ## Usage
24
+
25
+ You can open a wave file:
26
+
27
+ ```
28
+ include 'zappa'
29
+ s = Segment.from_file('this_is_a_song.wav')
30
+ ```
31
+
32
+ and then read any of its properties:
33
+
34
+ ```
35
+ puts s.format
36
+ ```
37
+
38
+ and save it to a different location:
39
+
40
+ ```
41
+ s.to_file('output.wav')
42
+ ```
43
+
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/zappa/fork )
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 a new Pull Request
data/ROADMAP.md ADDED
@@ -0,0 +1,62 @@
1
+ 0.0.1 - Basic editing
2
+ -------------------
3
+ - Install ffmpeg + dependencies on MacOS X
4
+ - Import: WAV
5
+ - Export: WAV
6
+
7
+
8
+ 0.0.2 - Slicing
9
+ -------------
10
+ - Slice segments into smaller parts (by time or samples)
11
+ - Join segments
12
+
13
+
14
+ 0.0.3 - DSP - Basic
15
+ ----------------
16
+ - Amplify signals by DB
17
+ - Calculate RMS
18
+ - Calculate Max
19
+ - Normalize
20
+ - Phase Invert
21
+
22
+
23
+ 0.0.4 - Multi Format Exporting
24
+ ----------------------------
25
+ - Import: MP3, OGG, M4A, FLAC, AIFF
26
+ - Export: MP3, OGG, M4A, FLAC, AIFF
27
+
28
+ 0.0.5 - OS Support
29
+ ----------------
30
+ - OS: Windows, Linux, Mac Support
31
+
32
+
33
+ Release - 0.1 Basic DSP Platform
34
+ ==============================
35
+
36
+
37
+ 0.1.1 - DSP - Filters - Basic
38
+ ---------------------------
39
+
40
+ - DSP: Low Pass Filter
41
+ - DSP: High Pass Filter
42
+ - DSP: Notch Filter
43
+
44
+
45
+ 0.1.2 DSP - Time Effects
46
+ ----------------------
47
+ - Speed Up / Down
48
+ - Reverse
49
+ - Fade In / Fade Out
50
+
51
+
52
+ 0.1.3 - DSP - Equalizer
53
+ ---------------------
54
+ - 8 Chan EQ
55
+
56
+
57
+ 0.1.4 - DSP - Dynamics
58
+ ----------------------
59
+
60
+ - DSP: Compressor
61
+ - DSP: Remove Silence
62
+ - DSP: Limiter
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,7 @@
1
+ module Zappa
2
+ class FileFormatError < StandardError
3
+ end
4
+
5
+ class FileError < StandardError
6
+ end
7
+ end
@@ -0,0 +1,40 @@
1
+ require 'tempfile'
2
+
3
+ module Zappa
4
+ class Segment
5
+ attr_reader :source
6
+
7
+ def initialize(path = nil)
8
+ if path
9
+ from_file(path)
10
+ else
11
+ @source = nil
12
+ end
13
+ end
14
+
15
+ def from_file(path)
16
+ @source = Wave.new(safe_copy(path))
17
+ end
18
+
19
+ def to_file(path, format = 'wav')
20
+ raise FileError.new('No data in Segment') if @source.nil?
21
+ out = system('ffmpeg', '-i', @source.file_path, '-y', '-f', format, path)
22
+ raise ('Cannot export to' + path ) if out == false
23
+ raise FileError.new('ffmpeg not installed') if out.nil?
24
+ end
25
+
26
+ def ==(other)
27
+ source == other.source
28
+ end
29
+
30
+ private
31
+
32
+ def safe_copy(path)
33
+ tmp = Tempfile.new('zappa')
34
+ out = system('ffmpeg', '-i', path, '-vn', '-y', '-f', 'wav', tmp.path)
35
+ raise 'Cannot open file' if out == false
36
+ raise 'ffmpeg not installed' if out.nil?
37
+ tmp.path
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Zappa
2
+ VERSION = '0.0.1'
3
+ end
data/lib/zappa/wave.rb ADDED
@@ -0,0 +1,73 @@
1
+ # http://soundfile.sapp.org/doc/WaveFormat/
2
+
3
+ module Zappa
4
+ class Wave
5
+ attr_accessor :format, :data, :data_size, :file_path
6
+ SUBCHUNKS = %w('fmt', 'data')
7
+ KNOWN_FMT_SIZE = 16
8
+
9
+ def initialize(path)
10
+ @format = {}
11
+ @data = {}
12
+
13
+ begin
14
+ @file = File.new(path, 'rb')
15
+ rescue
16
+ raise FileError.new('Could not find ' + path)
17
+ else
18
+ @file_path = @file.path
19
+ unpack_wav
20
+ end
21
+ end
22
+
23
+ def unpack_wav
24
+ unpack_riff_header
25
+ while @data[:data].nil?
26
+ unpack_subchunk
27
+ end
28
+ end
29
+
30
+ def unpack_riff_header
31
+ chunk_id = @file.read(4)
32
+ _ = @file.read(4).unpack('V').first # chunk_size
33
+ format = @file.read(4)
34
+ raise FileFormatError.new('Format is not WAVE') unless format == 'WAVE'
35
+ raise FileFormatError.new('ID is not RIFF') unless chunk_id == 'RIFF'
36
+ end
37
+
38
+ def unpack_subchunk
39
+ id = @file.read(4).strip
40
+ if SUBCHUNKS.include?(id)
41
+ send('unpack_' + id)
42
+ else
43
+ unpack_unknown
44
+ end
45
+ end
46
+
47
+ def unpack_fmt
48
+ size = @file.read(4).unpack('V').first
49
+ @format[:audio_format] = @file.read(2).unpack('v').first
50
+ @format[:channels] = @file.read(2).unpack('v').first
51
+ @format[:sample_rate] = @file.read(4).unpack('V').first
52
+ @format[:byte_rate] = @file.read(4).unpack('V').first
53
+ @format[:block_align] = @file.read(2).unpack('v').first
54
+ @format[:bits_per_sample] = @file.read(2).unpack('v').first
55
+ unread = size - KNOWN_FMT_SIZE
56
+ @format[:unknown] = @file.read(unread) if unread > 0
57
+ end
58
+
59
+ def unpack_data
60
+ @data[:size] = @file.read(4).unpack('V').first
61
+ @data[:data] = @file.read(@data_size)
62
+ end
63
+
64
+ def unpack_unknown
65
+ size = @file.read(4).unpack('V').first
66
+ @file.read(size)
67
+ end
68
+
69
+ def ==(other)
70
+ other.format == format && other.data == data
71
+ end
72
+ end
73
+ end
data/lib/zappa.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'zappa/version'
2
+ require 'zappa/segment'
3
+ require 'zappa/wave'
4
+ require 'zappa/errors'
Binary file
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ WAV_IN = 'spec/audio/basic-5s.wav'
5
+
6
+ describe Zappa::Segment do
7
+ before do
8
+ subject.from_file(WAV_IN)
9
+ end
10
+
11
+ describe '#from_file' do
12
+ it 'makes a safe copy of the source wav file' do
13
+ expect(Zappa::Wave.new(WAV_IN))
14
+ .to eq(Zappa::Wave.new(subject.source.file_path))
15
+ end
16
+
17
+ it 'raises error if file does not exist' do
18
+ expect { Zappa::Segment.new('some_foo') }.to raise_error(RuntimeError)
19
+ end
20
+
21
+ pending 'raises error if ffmpeg is not installed'
22
+ pending 'only permits wav files'
23
+ end
24
+
25
+ describe '#to_file' do
26
+ it 'exports the segment to a wav file' do
27
+ tmp = Tempfile.new('zappa-spec')
28
+ subject.to_file(tmp.path, 'wav')
29
+ expect(Zappa::Wave.new(WAV_IN)).to eq(Zappa::Wave.new(tmp.path))
30
+ end
31
+
32
+ it 'raises error if segment is empty' do
33
+ w = Zappa::Segment.new
34
+ expect { w.to_file('foo.wav') }.to raise_error(Zappa::FileError)
35
+ end
36
+
37
+ it 'raises error for invalid path' do
38
+ expect { subject.to_file('some:foo') }.to raise_error(RuntimeError)
39
+ end
40
+
41
+ pending 'raises error if ffmpeg is not installed'
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'zappa'
5
+
6
+ RSpec.configure do |config|
7
+ # config
8
+ end
9
+
10
+ def wav_data(encoded_wav)
11
+ encoded_wav.split('dataPu').last
12
+ end
data/spec/wave_spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'tempfile'
3
+
4
+ WAV_IN = 'spec/audio/basic-5s.wav'
5
+ WAV_EX = 'does-not-exist.wav'
6
+
7
+ describe Zappa::Wave do
8
+ it 'reads format headers correctly' do
9
+ fmt_header = { audio_format: 1,
10
+ channels: 2,
11
+ sample_rate: 44_100,
12
+ byte_rate: 176_400,
13
+ block_align: 4,
14
+ bits_per_sample: 16 }
15
+ w = Zappa::Wave.new(WAV_IN)
16
+ expect(w.format).to eq(fmt_header)
17
+ end
18
+
19
+ it 'raises error for incorrect path' do
20
+ expect { Zappa::Wave.new(WAV_EX) }.to raise_error(Zappa::FileError)
21
+ end
22
+
23
+ pending 'handles wave files with unknown subchunks'
24
+ pending 'handles wave files with optional tmp data'
25
+ end
data/zappa.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 'zappa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'zappa'
8
+ spec.version = Zappa::VERSION
9
+ spec.authors = ['Varun Srinivasan']
10
+ spec.email = ['varunsrin@gmail.com']
11
+ spec.summary = 'Ruby gem for manipulating audio files.'
12
+ spec.description = ''
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'pry'
25
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zappa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Varun Srinivasan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-17 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email:
71
+ - varunsrin@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - LICENSE
80
+ - LICENSE.txt
81
+ - README.md
82
+ - ROADMAP.md
83
+ - Rakefile
84
+ - lib/zappa.rb
85
+ - lib/zappa/errors.rb
86
+ - lib/zappa/segment.rb
87
+ - lib/zappa/version.rb
88
+ - lib/zappa/wave.rb
89
+ - spec/audio/basic-5s.wav
90
+ - spec/segment_spec.rb
91
+ - spec/spec_helper.rb
92
+ - spec/wave_spec.rb
93
+ - zappa.gemspec
94
+ homepage: ''
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby gem for manipulating audio files.
118
+ test_files:
119
+ - spec/audio/basic-5s.wav
120
+ - spec/segment_spec.rb
121
+ - spec/spec_helper.rb
122
+ - spec/wave_spec.rb