Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect size in header when using custom chunks #50

Closed
rjkat opened this issue Nov 15, 2017 · 5 comments
Closed

Incorrect size in header when using custom chunks #50

rjkat opened this issue Nov 15, 2017 · 5 comments
Assignees

Comments

@rjkat
Copy link
Contributor

rjkat commented Nov 15, 2017

In wavwrite, the length of the data chunk is used for both the header and the data chunk size.

data_length::UInt32 = size(samples, 1) * block_align
# ...
WAV.write_standard_header(io, data_length) # < here
# ...
WAV.write(io, b"data")
WAV.write_le(io, data_length)
WAV.write_data(io, fmt, samples)

This results in an incorrect size in the header in the case where custom chunks have been supplied.
The fix looks something like this:

data_length::UInt32 = size(samples, 1) * block_align
# (4 byte id + 4 byte length + data length) for each custom chunk
extra_length = 8 * length(chunks) + sum([length(c) for (_, c) in chunks]) 
# ...
WAV.write_standard_header(io, data_length + extra_length) # < add extra length here
# ...
WAV.write(io, b"data")
WAV.write_le(io, data_length) # < this bit stays the same
WAV.write_data(io, fmt, samples)

Thanks for your work on this package, it's fantastic 👍

@dancasimiro
Copy link
Owner

Hi @rkat,

I'm sorry about this bug. It looks like you put together a good fix. Do you have time to submit a pull request? I think that you are only missing a unit test.

If not, I will base a fix on the code that you supplied the next chance that I have.

Thanks for the bug report!

@rjkat
Copy link
Contributor Author

rjkat commented Nov 28, 2017

No worries, I'll add a unit test and make a pull request :)

rjkat added a commit to rjkat/WAV.jl that referenced this issue Nov 28, 2017
dancasimiro added a commit that referenced this issue Dec 3, 2017
fix issue #50 (incorrect header size when using custom chunks)
@dancasimiro
Copy link
Owner

Fixed by pull request #51, commit f0ed3cd

@dancasimiro
Copy link
Owner

Fixed in v0.9.0

@rjkat
Copy link
Contributor Author

rjkat commented Dec 6, 2017

Awesome, thanks Dan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants