scissor 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -79,6 +79,12 @@ supported file format:
79
79
 
80
80
  foo.stretch(200)
81
81
 
82
+ === pan
83
+
84
+ foo.pan(0) # left only
85
+ foo.pan(50) # center(default)
86
+ foo.pan(100) # right only
87
+
82
88
  === mix
83
89
 
84
90
  Scissor.mix([foo, bar], 'mix.mp3')
@@ -1,4 +1,5 @@
1
1
  require 'mp3info'
2
+ require 'mp4info'
2
3
  require 'pathname'
3
4
  require 'riff/reader'
4
5
 
@@ -44,9 +45,27 @@ module Scissor
44
45
  end
45
46
  end
46
47
 
48
+ class M4a < SoundFile
49
+ def length
50
+ info.SECS_NOROUND
51
+ end
52
+
53
+ # FIXME
54
+ def mono?
55
+ false
56
+ end
57
+
58
+ private
59
+
60
+ def info
61
+ @info ||= MP4Info.open(@filename.to_s)
62
+ end
63
+ end
64
+
47
65
  SUPPORTED_FORMATS = {
48
66
  :mp3 => Mp3,
49
- :wav => Wav
67
+ :wav => Wav,
68
+ :m4a => M4a
50
69
  }
51
70
 
52
71
  class Error < StandardError; end
@@ -67,3 +86,36 @@ module Scissor
67
86
  end
68
87
  end
69
88
  end
89
+
90
+ class MP4Info
91
+ private
92
+
93
+ def parse_mvhd(io_stream, level, size)
94
+ raise "Parse error" if size < 32
95
+ data = read_or_raise(io_stream, size, "Premature end of file")
96
+
97
+ version = data.unpack("C")[0] & 255
98
+ if (version == 0)
99
+ scale, duration = data[12..19].unpack("NN")
100
+ elsif (version == 1)
101
+ scale, hi, low = data[20..31].unpack("NNN")
102
+ duration = hi * (2**32) + low
103
+ else
104
+ return
105
+ end
106
+
107
+ printf " %sDur/Scl=#{duration}/#{scale}\n", ' ' * ( 2 * level ) if $DEBUG
108
+
109
+ secs = (duration * 1.0) / scale
110
+
111
+ # add
112
+ @info_atoms["SECS_NOROUND"] = secs
113
+
114
+ @info_atoms["SECS"] = (secs).round
115
+ @info_atoms["MM"] = (secs / 60).floor
116
+ @info_atoms["SS"] = (secs - @info_atoms["MM"] * 60).floor
117
+ @info_atoms["MS"] = (1000 * (secs - secs.floor)).round
118
+ @info_atoms["TIME"] = sprintf "%02d:%02d", @info_atoms["MM"],
119
+ @info_atoms["SECS"] - @info_atoms["MM"] * 60;
120
+ end
121
+ end
data/scissor.gemspec CHANGED
@@ -13,10 +13,11 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.name = %q{scissor}
15
15
  gem.require_paths = ["lib"]
16
- gem.version = "0.4.0"
16
+ gem.version = "0.5.0"
17
17
 
18
18
  gem.add_dependency('open4', '>= 1.3.0')
19
19
  gem.add_dependency('ruby-mp3info')
20
+ gem.add_dependency('mp4info', '1.7.3')
20
21
  gem.add_dependency('riff', '<= 0.3.0')
21
22
  gem.add_dependency('tempdir')
22
23
  gem.add_dependency('streamio-ffmpeg')
Binary file
data/spec/scissor_spec.rb CHANGED
@@ -270,6 +270,12 @@ describe Scissor do
270
270
  result.duration.should be_within(0.1).of(140)
271
271
  end
272
272
 
273
+ it "should write to m4a file" do
274
+ scissor = @mp3.slice(0, 120) + @mp3.slice(150, 20)
275
+ result = scissor.to_file('/tmp/scissor-test/out.m4a')
276
+ result.duration.should be_within(0.1).of(140)
277
+ end
278
+
273
279
  it "should write to file using 'greater than' operator" do
274
280
  result = @mp3.slice(0, 120) + @mp3.slice(150, 20) > '/tmp/scissor-test/out.wav'
275
281
  result.duration.should be_within(0.1).of(140)
@@ -9,6 +9,7 @@ describe Scissor::SoundFile do
9
9
  before do
10
10
  @mp3 = Scissor::SoundFile.new_from_filename(fixture('sample.mp3'))
11
11
  @wav = Scissor::SoundFile.new_from_filename(fixture('sine.wav'))
12
+ @m4a = Scissor::SoundFile.new_from_filename(fixture('sine.m4a'))
12
13
  end
13
14
 
14
15
  after do
@@ -23,12 +24,14 @@ describe Scissor::SoundFile do
23
24
  it "should get length" do
24
25
  @mp3.length.should be_within(0.1).of(178.1)
25
26
  @wav.length.should eql(1.0)
27
+ @m4a.length.should be_within(0.1).of(1.0)
26
28
  end
27
29
 
28
30
  describe '#mono?' do
29
31
  it "should return true if sound file is mono" do
30
32
  @mp3.should be_mono
31
33
  @wav.should_not be_mono
34
+ @m4a.should_not be_mono
32
35
 
33
36
  Scissor::SoundFile.new_from_filename(fixture('mono.wav')).should be_mono
34
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scissor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-20 00:00:00.000000000 Z
12
+ date: 2012-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: open4
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mp4info
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.7.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.3
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: riff
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +181,7 @@ files:
165
181
  - spec/fixtures/foo.bar
166
182
  - spec/fixtures/mono.wav
167
183
  - spec/fixtures/sample.mp3
184
+ - spec/fixtures/sine.m4a
168
185
  - spec/fixtures/sine.wav
169
186
  - spec/fragment_spec.rb
170
187
  - spec/scissor_spec.rb
@@ -185,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
202
  version: '0'
186
203
  segments:
187
204
  - 0
188
- hash: -2487823998857234402
205
+ hash: 337261600329672185
189
206
  required_rubygems_version: !ruby/object:Gem::Requirement
190
207
  none: false
191
208
  requirements:
@@ -194,10 +211,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
211
  version: '0'
195
212
  segments:
196
213
  - 0
197
- hash: -2487823998857234402
214
+ hash: 337261600329672185
198
215
  requirements: []
199
216
  rubyforge_project:
200
- rubygems_version: 1.8.24
217
+ rubygems_version: 1.8.23
201
218
  signing_key:
202
219
  specification_version: 3
203
220
  summary: utility to chop sound files
@@ -206,6 +223,7 @@ test_files:
206
223
  - spec/fixtures/foo.bar
207
224
  - spec/fixtures/mono.wav
208
225
  - spec/fixtures/sample.mp3
226
+ - spec/fixtures/sine.m4a
209
227
  - spec/fixtures/sine.wav
210
228
  - spec/fragment_spec.rb
211
229
  - spec/scissor_spec.rb