nu_wav 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/nu_wav.rb +16 -8
  3. data/nu_wav.gemspec +2 -2
  4. metadata +4 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
data/lib/nu_wav.rb CHANGED
@@ -8,6 +8,7 @@ require 'rubygems'
8
8
  require 'mp3info'
9
9
  require 'date'
10
10
  require 'tempfile'
11
+ require 'fileutils'
11
12
 
12
13
  module NuWav
13
14
 
@@ -43,9 +44,7 @@ module NuWav
43
44
  attr_accessor :header, :chunks
44
45
 
45
46
  def self.parse(wave_file)
46
- wf = NuWav::WaveFile.new
47
- wf.parse(wave_file)
48
- wf
47
+ NuWav::WaveFile.new.parse(wave_file)
49
48
  end
50
49
 
51
50
  def initialize
@@ -54,6 +53,8 @@ module NuWav
54
53
 
55
54
  def parse(wave_file)
56
55
  NuWav::WaveFile.log "Processing wave file #{wave_file.inspect}...."
56
+ wave_file_size = File.size(wave_file)
57
+
57
58
  File.open(wave_file, File::RDWR) do |f|
58
59
 
59
60
  #only for windows, make sure we are operating in binary mode
@@ -64,8 +65,10 @@ module NuWav
64
65
  riff, riff_length = read_chunk_header(f)
65
66
  NuWav::WaveFile.log "riff: #{riff}"
66
67
  NuWav::WaveFile.log "riff_length: #{riff_length}"
68
+ NuWav::WaveFile.log "wave_file_size: #{wave_file_size}"
69
+
67
70
  raise NotRIFFFormat unless riff == 'RIFF'
68
- riff_end = f.tell + riff_length
71
+ riff_end = [f.tell + riff_length, wave_file_size].min
69
72
 
70
73
  riff_type = f.read(4)
71
74
  raise NotWAVEFormat unless riff_type == 'WAVE'
@@ -95,6 +98,7 @@ module NuWav
95
98
  end
96
99
  @chunks.each{|k,v| NuWav::WaveFile.log "#{k}: #{v}\n\n" unless k.to_s == 'data'}
97
100
  NuWav::WaveFile.log "parse done"
101
+ self
98
102
  end
99
103
 
100
104
  def duration
@@ -272,7 +276,10 @@ module NuWav
272
276
 
273
277
  def read_chunk_header(file)
274
278
  hdr = file.read(8)
275
- chunkName, chunkLen = hdr.unpack("A4V")
279
+ # puts "hdr: #{hdr}"
280
+ chunkName, chunkLen = hdr.unpack("A4V") rescue [nil, nil]
281
+ # puts "chunkName: '#{chunkName}', chunkLen: '#{chunkLen}'"
282
+ [chunkName, chunkLen]
276
283
  end
277
284
 
278
285
  def chunk_class(name)
@@ -335,7 +342,7 @@ module NuWav
335
342
  end
336
343
 
337
344
  def read_char(start, length=(@raw.length-start))
338
- @raw[start..(start+length-1)]
345
+ (@raw[start..(start+length-1)] || '').strip
339
346
  end
340
347
 
341
348
  def write_dword(val)
@@ -350,6 +357,7 @@ module NuWav
350
357
 
351
358
  def write_char(val, length=nil)
352
359
  val ||= ''
360
+ val = val.to_s
353
361
  length ||= val.length
354
362
  # NuWav::WaveFile.log "length:#{length} val.length:#{val.length} val:#{val}"
355
363
  padding = "\0" * [(length - val.length), 0].max
@@ -602,9 +610,9 @@ module NuWav
602
610
  def self.new_from_file(file)
603
611
  tmp_data = Tempfile.open('data_chunk')
604
612
  tmp_data.binmode
605
- File.copy(file.path, tmp_data.path)
613
+ FileUtils.cp(file.path, tmp_data.path)
606
614
  tmp_data.rewind
607
- self.new('data', File.size(file.path), tmp_data)
615
+ self.new('data', File.size(tmp_data.path).to_s, tmp_data)
608
616
  end
609
617
 
610
618
  def initialize(id=nil, size=nil, tmp_data_file=nil)
data/nu_wav.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{nu_wav}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kookster"]
12
- s.date = %q{2011-08-15}
12
+ s.date = %q{2012-07-19}
13
13
  s.description = %q{NuWav is a pure ruby audio WAV file parser and writer. It supports Broadcast Wave Format (BWF), inclluding MPEG audio data, and the public radio standard cart chunk.}
14
14
  s.email = %q{andrew@beginsinwonder.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nu_wav
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - kookster
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-15 00:00:00 -04:00
18
+ date: 2012-07-19 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency