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

Implemented WAV source, sink and backend #659

Merged
merged 2 commits into from
Jan 30, 2024
Merged

Conversation

Pekureda
Copy link
Contributor

Implemented issue: 576

  • Implemented source, sink and backend for WAV file read and write operation handling,
  • Added dr_wav single header library,
  • Read operations of WAV files are performed using dr_wav,
  • Implemented WavHeader to store and handle headers of written WAV files,
  • Changed lib download links from ftp to https based.

Copy link

🤖 Upon creation, pull request description does not have a link to an issue. If there is a related issue, please add it to the description using any of the supported formats.

@github-actions github-actions bot added the work in progress Pull request is still in progress and changing label Dec 11, 2023
@Pekureda Pekureda marked this pull request as ready for review December 11, 2023 22:19
@github-actions github-actions bot added ready for review Pull request can be reviewed and removed work in progress Pull request is still in progress and changing labels Dec 11, 2023
@gavv gavv added the contribution A pull-request by someone else except maintainers label Dec 15, 2023
@gavv
Copy link
Member

gavv commented Dec 15, 2023

Thanks for PR! Will review in upcoming days!

@gavv gavv added review in progress Pull request is being reviewed and removed ready for review Pull request can be reviewed labels Dec 15, 2023
Copy link
Member

@gavv gavv left a comment

Choose a reason for hiding this comment

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

Thanks for the patch, here are a few comments.

src/internal_modules/roc_sndio/wav_backend.cpp Outdated Show resolved Hide resolved
src/internal_modules/roc_sndio/wav_backend.h Outdated Show resolved Hide resolved
src/internal_modules/roc_sndio/wav_header.cpp Outdated Show resolved Hide resolved
Comment on lines 62 to 68
memcpy(header_data + offset, &chunk_id_, sizeof(chunk_id_));
offset += sizeof(chunk_id_);
memcpy(header_data + offset, &chunk_size_, sizeof(chunk_size_));
offset += sizeof(chunk_size_);
memcpy(header_data + offset, &format_, sizeof(format_));
offset += sizeof(format_);
memcpy(header_data + offset, &subchunk1_id_, sizeof(subchunk1_id_));
Copy link
Member

Choose a reason for hiding this comment

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

I guess the code can be simpler and shorter if we would make WavHeader a struct and write it directly to file?

Currently we're defining all fields in .h and then repeating all fields in this function, which doubles the code size. Instead, we could just fwrite() the whole struct.

We'd need to use ROC_ATTR_PACKED_BEGIN/ROC_ATTR_PACKED_END for the struct to ensure that compiler does not insert any padding.

If WavHeader becomes a struct, I guess we can define in directly in wav_sink.cpp (in anon namespace), since it will be small and won't be used anywhere else.

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've decided to leave this class but move header data to a POD struct, which memory is this time managed by the WavHeader instead of the user, so it should be cheaper to use it. In case of inclusion of some other, extra parameters to the header, it should be a bit easier to extend this class.

Technically the number of samples written so far can be stored in WavSink, so I'm not really set on any of those solutions, because they're similarly good to me.

Copy link
Member

Choose a reason for hiding this comment

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

I think current version is nice!

src/internal_modules/roc_sndio/wav_header.cpp Outdated Show resolved Hide resolved
src/internal_modules/roc_sndio/wav_source.cpp Outdated Show resolved Hide resolved
src/internal_modules/roc_sndio/wav_source.h Outdated Show resolved Hide resolved
src/internal_modules/roc_sndio/wav_source.cpp Outdated Show resolved Hide resolved
src/internal_modules/roc_sndio/wav_source.cpp Outdated Show resolved Hide resolved
3rdparty/dr_wav/dr_wav.h Outdated Show resolved Hide resolved
@gavv gavv added needs revision Pull request should be revised by its author and removed review in progress Pull request is being reviewed labels Dec 22, 2023
@Pekureda Pekureda requested a review from gavv December 27, 2023 17:56
@github-actions github-actions bot added ready for review Pull request can be reviewed and removed needs revision Pull request should be revised by its author labels Dec 27, 2023
@Pekureda
Copy link
Contributor Author

Thanks for detailed review and finding all those issues! I've updated the commit and fixed mentioned problems.

@gavv
Copy link
Member

gavv commented Dec 29, 2023

Thanks,

It seems you forgot to commit your changes or pushed a wrong commit?

Seems that the new cimmit is identical to the old one.

https://github.com/roc-streaming/roc-toolkit/compare/155d58f67566a3a8c2833059268dc80572743a1b..d7378fa820baea482d65ae5afd9242532cca1e3a

@gavv
Copy link
Member

gavv commented Dec 29, 2023

Hi, I've pushed commit 03d29eb to develop branch that adds new fields sample_format and pcm_format to SampleSpec.

It mostly does not affect this PR, but SampleSpec ctor now has new parameter pcm_format, which you can just set to audio::Sample_RawFormat (which means that source/sink produces/consumes samples in "raw" format - 32-bit PCM floats).

So please rebase on fresh develop.

@Pekureda Pekureda force-pushed the R576_1 branch 2 times, most recently from fb07872 to e377951 Compare December 30, 2023 12:16
@Pekureda
Copy link
Contributor Author

It's rebased and adjusted to newest changes on develop branch. I must've not force pushed the amended commit and not noticed that.

@gavv gavv added this to the next milestone Jan 30, 2024
@gavv gavv merged commit e543420 into roc-streaming:develop Jan 30, 2024
32 checks passed
@github-actions github-actions bot removed the ready for review Pull request can be reviewed label Jan 30, 2024
@gavv
Copy link
Member

gavv commented Jan 30, 2024

Thanks, looks and works great!

I've pushed a small follow-up commit: fc0fab2

Changes:

  • Array::grow() call is now not needed
  • In WavSink, if channels or rate is not specified, use default values (otherwise roc-send panics)
  • In WavSource, ignore sample_spec from config (we don't and can't use it because we can't do any conversions)
  • Use Sample_RawFormat instead of PcmFormat_Float32_Le when reporting sample spec. Sample_RawFormat corresponds to format of sample_t type. It's equal to PcmFormat_Float32_Le only on little-endian machines, but it's PcmFormat_Float32_Be on big-endian ones.

@gavv
Copy link
Member

gavv commented Jan 30, 2024

We also forgot one small thing, I've created a new issue for it: #684

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution A pull-request by someone else except maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants