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

Add the support of FLAC loops #242

Merged
merged 2 commits into from
May 26, 2020
Merged

Add the support of FLAC loops #242

merged 2 commits into from
May 26, 2020

Conversation

jpcima
Copy link
Collaborator

@jpcima jpcima commented May 17, 2020

#229
This adds the support of FLAC loops, the same as ARIA.
This is not yet supported in libsndfile: libsndfile/libsndfile#59.
Hence this uses an ad-hoc implementation based on direct file parsing.

This is NOT the tag-based implementation. Tag-based support may be added as extra in the future.

This uses a feature known as foreign RIFF blocks.
These blocks are obtained by encoding a WAV file by the FLAC command-line encoder, using the flag --keep-foreign-metadata.

Example
FLAC_loop_test.zip

Reference

src/sfizz/FileInstrument.cpp Outdated Show resolved Hide resolved
fread(riffId, 4, 1, stream.get()) == 1 && memcmp(riffId, "smpl", 4) == 0 &&
fread_u32le(stream.get(), riffChunkSize) && riffChunkSize <= block_size - 12)
{
std::unique_ptr<uint8_t[]> chunk { new uint8_t[riffChunkSize] };
Copy link
Member

Choose a reason for hiding this comment

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

How big is riffChunkSize here? If we ignore values that are too crazy we could stack-allocate this with std:array (and get an implicit cast to const span later too).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The chunk size has a fixed header, followed by arbitrary number of loops, followed by the sampler-specific chunk.

Here I'm fine with alloc'ing this chunk, because this is checked to be no larger than the FLAC metadata block. The block has a size encoded in 24 bits, which makes it 16MB in the worst case.

src/sfizz/FileInstrument.cpp Outdated Show resolved Hide resolved
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