nu_wav 0.1.0 → 0.2.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.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gem.add_dependency('ruby-mp3info', '>= 0.6.13')
14
14
  gem.files.exclude ".document"
15
15
  gem.files.exclude ".gitignore"
16
-
16
+ gem.files.exclude "test/files/**/*"
17
17
  end
18
18
  Jeweler::GemcutterTasks.new
19
19
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/nu_wav.rb CHANGED
@@ -78,10 +78,15 @@ module NuWav
78
78
  def duration
79
79
  fmt = @chunks[:fmt]
80
80
 
81
- if fmt && (fmt.compression_code.to_i == PCM_COMPRESSION)
82
- @header.size / (fmt.sample_rate * fmt.number_of_channels * (fmt.sample_bits / 8))
81
+ if (fmt.compression_code.to_i == PCM_COMPRESSION)
82
+ data = @chunks[:data]
83
+ data.size / (fmt.sample_rate * fmt.number_of_channels * (fmt.sample_bits / 8))
84
+ elsif (fmt.compression_code.to_i == MPEG_COMPRESSION)
85
+ # <chunk type:fact samples_number:78695424 />
86
+ fact = @chunks[:fact]
87
+ fact.samples_number / fmt.sample_rate
83
88
  else
84
- raise "Duration implemented for WAV files only."
89
+ raise "Duration implemented for PCM and MEPG files only."
85
90
  end
86
91
  end
87
92
 
data/nu_wav.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{nu_wav}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["kookster"]
12
+ s.date = %q{2010-04-05}
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
+ s.email = %q{andrew@beginsinwonder.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/nu_wav.rb",
25
+ "nu_wav.gemspec",
26
+ "test/helper.rb",
27
+ "test/test_nu_wav.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/kookster/nu_wav}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.5}
33
+ s.summary = %q{NuWav is a pure ruby audio WAV file parser and writer.}
34
+ s.test_files = [
35
+ "test/helper.rb",
36
+ "test/test_nu_wav.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<ruby-mp3info>, [">= 0.6.13"])
45
+ else
46
+ s.add_dependency(%q<ruby-mp3info>, [">= 0.6.13"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<ruby-mp3info>, [">= 0.6.13"])
50
+ end
51
+ end
52
+
data/test/test_nu_wav.rb CHANGED
@@ -1,46 +1,76 @@
1
1
  require 'helper'
2
+ require 'nu_wav'
2
3
 
3
4
  class TestNuWav < Test::Unit::TestCase
5
+ include NuWav
6
+
4
7
  def test_parse_wav
5
- assert true
6
- end
8
+ w = WaveFile.parse(File.expand_path(File.dirname(__FILE__) + '/files/test_basic.wav'))
9
+ assert_equal 4260240, w.header.size
7
10
 
8
- def test_parse_wav_with_bwf
9
- assert true
11
+ assert_equal 2, w.chunks.size
12
+ assert_equal 48, w.duration
13
+
14
+ fmt = w.chunks[:fmt]
15
+ assert_equal 1, fmt.number_of_channels
16
+ assert_equal 44100, fmt.sample_rate
17
+ assert_equal 88200, fmt.byte_rate
18
+ assert_equal 2, fmt.block_align
19
+ assert_equal 16, fmt.sample_bits
20
+
21
+ data = w.chunks[:data]
22
+ assert_equal 4260204, data.size
10
23
  end
11
24
 
12
25
  def test_parse_wav_with_bwf_and_cart_chunk
13
- assert true
26
+ w = WaveFile.parse(File.expand_path(File.dirname(__FILE__) + '/files/AfropopW_040_SGMT01.wav'))
27
+ assert_equal 6, w.chunks.size
28
+
29
+ # duration is calculated differently for mpeg and pcm
30
+ assert_equal 1784, w.duration
31
+
32
+ # fmt
33
+ assert_equal 2, w.chunks[:fmt].number_of_channels
34
+ assert_equal 44100, w.chunks[:fmt].sample_rate
35
+ assert_equal 32000, w.chunks[:fmt].byte_rate
36
+ assert_equal 835, w.chunks[:fmt].block_align
37
+ assert_equal 65535, w.chunks[:fmt].sample_bits
38
+ assert_equal 22, w.chunks[:fmt].extra_size
39
+ assert_equal 2, w.chunks[:fmt].head_layer
40
+ assert_equal 256000, w.chunks[:fmt].head_bit_rate
41
+ assert_equal 1, w.chunks[:fmt].head_mode
42
+ assert_equal 1, w.chunks[:fmt].head_mode_ext
43
+ assert_equal 0, w.chunks[:fmt].head_emphasis
44
+ assert_equal 28, w.chunks[:fmt].head_flags
45
+
46
+ # fact
47
+ assert_equal 78695424, w.chunks[:fact].samples_number
48
+
49
+ # mext
50
+ assert_equal 7, w.chunks[:mext].sound_information
51
+ assert_equal 835, w.chunks[:mext].frame_size
52
+
53
+ # bext
54
+ assert_equal "A=MPEG1L2,F=44100,B=256,M=STEREO,T=CV_PcxTl2NP\r\n", unpad(w.chunks[:bext].coding_history)
55
+
56
+ # cart
57
+ assert_equal '0101', w.chunks[:cart].version
58
+ assert_equal 'Afropop 070524_Episode on 05/24/2007_sgmt 1', unpad(w.chunks[:cart].title)
59
+ assert_equal 'Georges Collinet', unpad(w.chunks[:cart].artist)
60
+ assert_equal '60314', unpad(w.chunks[:cart].cut_id)
61
+ assert_equal '2007/05/24', unpad(w.chunks[:cart].start_date)
62
+ assert_equal '16:00:00', unpad(w.chunks[:cart].start_time)
63
+ assert_equal '2007/06/24', unpad(w.chunks[:cart].end_date)
64
+ assert_equal '16:00:00', unpad(w.chunks[:cart].end_time)
65
+ assert_equal 'ContentDepot', unpad(w.chunks[:cart].producer_app_id)
66
+ assert_equal '1.0', unpad(w.chunks[:cart].producer_app_version)
67
+
68
+ # data
69
+ assert_equal 57040521, w.chunks[:data].size
14
70
  end
71
+
72
+ def unpad(str)
73
+ str.gsub(/\0*$/, '')
74
+ end
75
+
15
76
  end
16
-
17
- # if NuWav::DEBUG
18
- #
19
- # wf = NuWav::WaveFile.new
20
- # # wf.parse('/Users/akuklewicz/dev/testaudio/0330AK_Studded.wav')
21
- # # puts "wf.duration = #{wf.duration}"
22
- # # puts "wf = #{wf}"
23
- #
24
- # wf.parse('/Users/akuklewicz/dev/workspace/mediajoint/test/fixtures/files/AfropopW_040_SGMT01.wav')
25
- #
26
- # puts "--------------------------------------------------------------------------------"
27
- #
28
- # wf.write_data_file('/Users/akuklewicz/dev/workspace/mediajoint/test/fixtures/files/AfropopW_040_SGMT01.mp2')
29
- #
30
- # # wf.to_file('AK_FreshA05_160_SGMT02')
31
- # # wf.parse('AK_FreshA05_160_SGMT02.wav')
32
- #
33
- # puts "--------------------------------------------------------------------------------"
34
- # #
35
- #
36
- # wv = NuWav::WaveFile.from_mpeg('/Users/akuklewicz/dev/workspace/mediajoint/test/fixtures/files/AK_AfropopW_040_SGMT01.mp2')
37
- # wv.to_file('AK_AfropopW_040_SGMT01_to_file_test.wav')
38
- #
39
- # puts "--------------------------------------------------------------------------------"
40
- #
41
- # wf = NuWav::WaveFile.new
42
- # wf.parse('AK_AfropopW_040_SGMT01_to_file_test.wav')
43
- #
44
- #
45
- #
46
- # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nu_wav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kookster
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-04-03 00:00:00 -04:00
12
+ date: 2010-04-05 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,6 +37,7 @@ files:
37
37
  - Rakefile
38
38
  - VERSION
39
39
  - lib/nu_wav.rb
40
+ - nu_wav.gemspec
40
41
  - test/helper.rb
41
42
  - test/test_nu_wav.rb
42
43
  has_rdoc: true