Page 1 of 1

sfz format: smpl chunk loops not supported for FLAC files

Posted: Wed Jun 10, 2020 7:08 pm
by jjlearman
I posted an sfz format sample set and got a bug report that the loops don't work in linuxsampler.

https://github.com/sfzinstruments/jlearman.jRhodes3c

This instrument uses SFZ format with FLAC files containing'smpl' chunks specifying the loops. It works on Sforzando and original sfz/sfz+. (I don't remember whether sfz/sfz+ supported FLAC files, but they honored 'smpl' chunks in .wav files.)

Please add support for 'smpl' chunks (for both .wav and .flac files.)

Thanks!

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Thu Jun 11, 2020 3:12 pm
by cuse
I am barely using the SFZ engine, nor have I written the relevant SFZ loop parameter code. I just had a short glimpse on the relevant code sections so far, which actually don't reveal anything abvious in this case. The SFZ engine honours the loop_mode, loop_start and loop_end opcodes:
http://svn.linuxsampler.org/cgi-bin/vie ... 3497#l1607

By default it's set to no_loop:
http://svn.linuxsampler.org/cgi-bin/vie ... =3497#l347

However, it is then actually still using the default sample info from the sample file itself:
http://svn.linuxsampler.org/cgi-bin/vie ... =3497#l200

For the sample file's loop info, LS is using the meta info provided by libsndfile. So we're not accessing chunks directly for that:
http://svn.linuxsampler.org/cgi-bin/vie ... v=2399#l75

I realize there is a different problem BTW: If a user specifies loop_mode=no_loop in a sfz file, then my expectation would be that the sampler should ignore the sample's loop info and not play any loop. As the code looks right now, it would probably still play a loop in this case (provided the sample file has a loop stored).

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Thu Jun 11, 2020 3:20 pm
by cuse
cuse wrote:
Thu Jun 11, 2020 3:12 pm
By default it's set to no_loop:
http://svn.linuxsampler.org/cgi-bin/vie ... =3497#l347
...
I realize there is a different problem BTW: If a user specifies loop_mode=no_loop in a sfz file, then my expectation would be that the sampler should ignore the sample's loop info and not play any loop. As the code looks right now, it would probably still play a loop in this case (provided the sample file has a loop stored).
Correction, it is initialized with LOOP_UNSET by default (not no_loop). So no, I don't see any obvious bug here regarding loop handling right now.

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Thu Jun 11, 2020 3:54 pm
by cuse
Digging further, it seems to me as if libsndfile does not support reading/writing loop info from/to FLAC files:
https://github.com/erikd/libsndfile/blo ... src/flac.c

Just for comparison, the relevant libsndfile source section for loop info in wav files:
https://github.com/erikd/libsndfile/blo ... av.c#L1136

So maybe you should file a report with libsndfile instead? Cross-posting appreciated on this issue (i.e. LS devel ML).

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Thu Jun 11, 2020 4:07 pm
by jjlearman
Wow, fast analysis! I'm impressed. Thanks for tracing it down to libsndfile, which I was not aware of. I will see if I can find where to post a request there.

Also, thanks for pointing out loop_mode. I'm not sure how it's set in my sfz, which was largely created by Extreme Sample Converter (extranslator.com) from my original SF2 (created by my own python scripts, and possibly with errors, but worked on original sfz/sfz+ players.)

It's a good question whether loop_mode should affect interpretation of loops embedded in audio files. I suspect that it's ignored by certain other players. It would probably be most useful if it was honored (by ignoring the 'smpl' chunk loop if loop_mode is no_loop.) So, I agree with your ideas about how that *should* work.

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Thu Jun 11, 2020 5:42 pm
by cuse
loop_mode seems to be SFZv1, so it should be supported by all players:
https://sfzformat.com/opcodes/loop_mode

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Thu Jun 11, 2020 9:54 pm
by jjlearman
It looks like a fix was posted to libsndfile to address this issue 25 days ago. Are you perhaps due for an update?

See https://github.com/sfztools/sfizz/pull/242 and https://github.com/erikd/libsndfile/issues/59

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Sat Jun 13, 2020 1:14 pm
by cuse
These were not fixes for libsndfile. What they do is simply accessing the 'smpl' RIFF chunk directly (on application level, not as a libsndfile patch).

We could make a similar workaround in LS of course, it is not complicated, but the preferable solution still would be to address this in libsndilfe. The point of using libsndfile in the SFZ engine was to get rid of the burden to maintain code for a huge number of audio file formats by ourselves.

Maybe you can bump this issue once more to see whether there is a chance by Erik to handle this in libsndfile, if there is none in near future, then we can still decide to address this with a hack on LS level.

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Mon Jun 15, 2020 10:14 pm
by jjlearman
Right, I see now that was for sfizz (whatever that is.) I've asked as you suggested and will post back if they answer.

Re: sfz format: smpl chunk loops not supported for FLAC files

Posted: Mon Jun 22, 2020 4:04 pm
by jjlearman
Update from libsndfile: (https://github.com/erikd/libsndfile/issues/59)
The solution is some significant refactoring as follows:

* Set up a bunch of routines to parse blocks of memory with functions similar to psf_binheader_readf().

* Convert wav_read_smpl_chunk() to work with this new block parsing function.

* Call wav_read_smpl_chunk() from the src/flac.c with the metadata block.

AFAICS changing wav_read_smpl_chunk() is probably not necessary. It might make sense simply passing a temporary copy of SF_PRIVATE structure to wav_read_smpl_chunk() with SF_PRIVATE->vio being filled with custom seek/read functions which read from memory instead of doing real file I/O.