Skip to content

Commit

Permalink
fix for mpeg based wavs
Browse files Browse the repository at this point in the history
  • Loading branch information
kookster committed May 29, 2011
1 parent 0e0c501 commit 98bdbbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/nu_wav.rb
Expand Up @@ -178,8 +178,7 @@ def self.from_mpeg(file_name)
wave = WaveFile.new

# data chunk
data = DataChunk.new
data.data = file.read
data = DataChunk.new_from_file(file)
wave.chunks[:data] = data

# fmt chunk
Expand Down Expand Up @@ -599,6 +598,14 @@ def self.parse(id, size, file)

return chunk
end

def self.new_from_file(file)
tmp_data = Tempfile.open('data_chunk')
tmp_data.binmode
File.copy(file.path, tmp_data.path)
tmp_data.rewind
self.new('data', File.size(file.path), tmp_data)
end

def initialize(id=nil, size=nil, tmp_data_file=nil)
@id, @size, @tmp_data_file = id, size, tmp_data_file
Expand Down
7 changes: 7 additions & 0 deletions test/test_nu_wav.rb
@@ -1,6 +1,7 @@
require 'helper'
require 'nu_wav'
require 'tempfile'
require 'ftools'

class TestNuWav < Test::Unit::TestCase
include NuWav
Expand Down Expand Up @@ -85,6 +86,12 @@ def test_parse_wav_with_bwf_and_cart_chunk
puts "end of test: #{memory_usage/1024} mb"
end

def test_from_mpeg
w = WaveFile.from_mpeg(File.expand_path(File.dirname(__FILE__) + '/files/test.mp2'))
w.to_file('test_from_mpeg.wav')
w.write_data_file('test_from_mpeg.mp2')
end

def unpad(str)
str.gsub(/\0*$/, '')
end
Expand Down

0 comments on commit 98bdbbf

Please sign in to comment.