Skip to content

Add support for Wave files with LIST section #11

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

Merged
merged 2 commits into from
Dec 17, 2018

Conversation

Rocketct
Copy link
Contributor

@Rocketct Rocketct commented Nov 14, 2018

Added, in readHeader() internal API, a logic to ignore the extrabytes in fmt header's chunk in WAV file.
I have test the changes with two f.wav files generated from ffmpeg at a sample rate of 22050 Hz and seems that works.

cc/ @sandeepmistry , @agdl if you can make other test

Resolve #9

Copy link
Contributor

@sandeepmistry sandeepmistry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make some more changes to make the start position of the audio data dynamic.

If you look inside currentTime, cue and read - sizeof(struct WaveFileHeader) is still used.

uint32_t size = 0, data;
uint8_t buffer[] = {0, 0, 0, 0};

fileSize = _file.size() - 36;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use sizeof(some struct) here instead of the 36?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rocketct any feedback on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the 36 byte in this case represent the dimension of the not extended subchunk1 + the dimension of the first three filed of the structure WaveFileHeader, this means that for get this value by sizeof is required or add or subtract the sizeof of different part of this last, for example somthing like sizeof(WaveFileHeader) - sizeof(WaveFileHeader.subchunk2)

Copy link
Contributor

@sandeepmistry sandeepmistry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rocketct looking better, please see the new comments I added.

_file.close();
return;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need the check for header.subChunk1.size != 16 here, like I mentioned below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok after this piece of code make sense, i'll add

return;
}
//if findData goes fine, data label is assigned to subChunk2.id
header.subChunk2.id = 0x64617461;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems strange to assign this here, we can just remove the check below instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think that id should be assigned for structure integrity i can try the new and the old file if all goes
fine, yes


//check if "data" field is present
while (count < fileSize) {
if (_file.read((void *)&byteread, 1) != 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider using:

int b = 0;

/// ...

b = file.read();
if (b == -1) {
 ///...
}

here.

fileSize = _file.size() - offset;

//check if "data" field is present
while (count < fileSize) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to use: while (_file.available()) here, then we don't need the file size calculated and the offset passed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok is better save space and remove a variable, i'm agree with you

int SDWaveFile::read(void* buffer, size_t size)
{
uint32_t position = _file.position();
int read = _file.read(buffer, size);

if (position == 0) {
// replace the header with 0's
memset(buffer, 0x00, sizeof(struct WaveFileHeader));
memset(buffer, 0x00, size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of size here, I think it should be: sizeof(struct WaveFileHeader) + _headerOffset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmm maybe is better remove completely now because is no longer used all the structure in one time but as a single read to the file with different size each time, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need it, otherwise there will be some "noise" when the wave file is played because the head is interpreted as audio.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ok ok i have understand i just looked better, well this could be done simply with sizeof(struct WaveFileHeader) about _headerOffset, in my opinion is not required because i cut off the fmt's extras byte and send the header as if it is the PCM one, then this https://github.com/arduino-libraries/ArduinoSound/pull/11/files/485f98353ae43feb80a92947e50e3e099005f770#diff-76c1dfd43efb327c34a33ded368fb3c0R210 is done only in the first call of the read (in findDataHeader), let me know if ok eventually i think a way to integrete _headerOffset part in the structure

@@ -173,14 +173,48 @@ int SDWaveFile::begin()
return 1;
}

int SDWaveFile::findData(int offset) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's clearer if this is renamed to findDataHeaderOffset?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes is better now

return;
}

_headerOffset = findData(headerSize);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this var could be renamed to something like _dataHeaderOffset.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes also in this case is ok

@Rocketct Rocketct force-pushed the master branch 9 times, most recently from ca6743c to 7eede68 Compare December 17, 2018 17:26
Added, in readheader internal API, a logic to ignore the extrabyte in fmt header's chunk in WAV file.
@sandeepmistry sandeepmistry changed the title Add support for fmt's extrabytes reading Add support for Wave files with LIST section Dec 17, 2018
@sandeepmistry sandeepmistry merged commit bf2b557 into arduino-libraries:master Dec 17, 2018
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

Successfully merging this pull request may close these issues.

2 participants