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

WaveWriter - WaveHeader is not fully valid. #12

Closed
ThuCommix opened this issue Aug 7, 2015 · 14 comments
Closed

WaveWriter - WaveHeader is not fully valid. #12

ThuCommix opened this issue Aug 7, 2015 · 14 comments
Assignees
Labels

Comments

@ThuCommix
Copy link

https://github.com/filoe/cscore/blob/master/CSCore/Codecs/WAV/WaveWriter.cs#L249

If I read the WaveHeader the DataSize is always zero.

            waveHeader.RiffId = br.ReadBytes(4);
            waveHeader.Size = br.ReadUInt32();
            waveHeader.WavId = br.ReadBytes(4);
            waveHeader.FmtId = br.ReadBytes(4);
            waveHeader.FmtSize = br.ReadUInt32();
            waveHeader.Format = br.ReadUInt16();
            waveHeader.Channels = br.ReadUInt16();
            waveHeader.SampleRate = br.ReadUInt32();
            waveHeader.BytesPerSec = br.ReadUInt32();
            waveHeader.BlockSize = br.ReadUInt16();
            waveHeader.Bit = br.ReadUInt16();
            waveHeader.DataId = br.ReadBytes(4);
            waveHeader.DataSize = br.ReadUInt32();

So I guess _dataLength is 0 at the time of writing the header? Most playback devices ignore the wrong data length flag, but some (mine) need this flag for validity checks.

@ThuCommix
Copy link
Author

Also confirmed for 1_1.

@filoe
Copy link
Owner

filoe commented Aug 8, 2015

Did you dispose the WaveWriter?

@ThuCommix
Copy link
Author

Yes, I'm using it in a using-block. Sorry for late reply.

@filoe
Copy link
Owner

filoe commented Aug 17, 2015

I am going to have a look at it. But you could take a look at the cscore decoder. The cscore decoder should be able to read the datasize.

@ThuCommix
Copy link
Author

Do you mean the WaveFileReader? If yes it simply ignores the data length.

@filoe
Copy link
Owner

filoe commented Aug 17, 2015

Ok, I am going to debug it today or in the next few days. But by just reading the code, I can't find any mistake in the WaveWriter class. Every Write operation increments the _dataLength correctly. And the Dispose method calls the WriteHeader method which writes down the _dataLength at the correct position.

@ThuCommix
Copy link
Author

You also writing the header in the ctor https://github.com/filoe/cscore/blob/master/CSCore/Codecs/WAV/WaveWriter.cs#L54

@filoe
Copy link
Owner

filoe commented Aug 17, 2015

Of course, the line you mentioned reserves some space for the header inside of the stream. But the content of the header gets written by the WriteHeader method which gets called in the Dispose method: https://github.com/filoe/cscore/blob/master/CSCore/Codecs/WAV/WaveWriter.cs#L265

@ThuCommix
Copy link
Author

Yes but line 60 is still not necessary as far as I can see. But thats not the problem just a side note 🍡

@filoe
Copy link
Owner

filoe commented Aug 17, 2015

You're right, line 60 or the loop at line 54 would not be necessary.

@ThuCommix
Copy link
Author

Also you could seek the stream by 44 bytes so you don't need to write 0 44 times. Don't know if this would bring a bit more performance.

@filoe
Copy link
Owner

filoe commented Aug 17, 2015

You're right again, but I can't reproduce your issue. I am sorry. I've just encoded a wav file:
0

And the cscore also is able to read it correctly:
1

But let me tell you, that your decoder won't work for all wav files. In order to be more flexible what different wav files concerns, you may should implement wave file chunks instead of reading the fmt and data chunk straigt forward.

@filoe filoe self-assigned this Sep 23, 2015
@filoe
Copy link
Owner

filoe commented Jan 21, 2016

Still waiting on any updates...

@filoe
Copy link
Owner

filoe commented Feb 24, 2016

Since this issue could not be reproduced, and @ThuCommix did not respond for months... I would guess I can close this.

@filoe filoe closed this as completed Feb 24, 2016
@filoe filoe added question and removed help wanted labels Jan 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants