stevefolta / SFZero

A simple SFZ player plugin
MIT License
92 stars 32 forks source link

Stream from disk #2

Open imprompt opened 7 years ago

imprompt commented 7 years ago

I would like to implement disk streaming capability to allow loading large instruments. Any guidance here would be very welcome to make this fit better into the existing code.

For SF2 files (to get started):

Loading an instrument: SF2Reader::readSamples() - limit loading to first blocksize number of samples

Playing an instrument: Something needs to trigger the reading of the full sample. I suppose this should be in sfzero::Synth::noteOn() where we could submit an asynchronous loading of the full sample into a temporary buffer. Then when sfzero::Voice::renderNextBlock() (where I understand the bulk of the rendering is done) reaches the end of it's pre-cached block, it could look at the temporary full-sample buffer.

Does this sound the best way?

imprompt commented 7 years ago

Opened the same issue in altalogix/SFZeroModule - probably the more appropriate place for a juce project?

stevefolta commented 7 years ago

Stay away from the altalogix fork (they did unspeakable things to the code style). The schellingb and jamiebullock forks are fine.

Your basic idea sounds good. A couple of notes:

imprompt commented 7 years ago

Thanks for the reply Steve (and your excellent library!) and the heads-up on the different forks. It seems the schellingb fork is pulling updates from the jamiebullock fork so may be the best place to start. I had planned on implementing SF2 first because I have a 2GB SF2 I want to get working on the iPad and are more familiar with the file format, but I see Polyphone can convert to SFZ so will look at SFZ first. I can use my experience of implementing disk streaming in an old sample player "VSamp" I wrote for the mac in the 90s, but will hopefully avoid doing 'unspeakable things' to your code style.

stevefolta commented 7 years ago

Okay, so SF2 does have a real-world use case. I have VSamp! I used to use it live ca. 2010.

osxmidi commented 7 years ago

https://github.com/christophhart/streaming_sampler

Any ideas on how that could be integrated?

imprompt commented 6 years ago

I've implemented my own in the SFZero framework, including support for iOS AUv3. It's currently hard-coded to always operate for SFZ files (only - not implemented for SF2) and preload the first 44100 samples of each sample and then stay at least 22050 samples ahead of the audio stream: https://github.com/imprompt/SFZero/blob/DIsk-Streaming/README.md

All working OK, but I'll tidy it up further including making the preload size a changeable parameter.

osxmidi commented 6 years ago

Maybe I'm missing something but I can't seem to find the disk streaming changes in the code.

imprompt commented 6 years ago

Sorry I hadn't published the module changes. It's there now: https://github.com/imprompt/SFZeroModule/tree/Disk-Streaming

osxmidi commented 6 years ago

Thanks.

It works great.

I think I'll fork it for a Linux version.

imprompt commented 6 years ago

That's great. I'll tidy up the code further and submit a pull request to Steve's original code, although I used the altalogix branch as a starting point as this had a working OSX AU plugin. I'm undecided yet as to whether I should get the disk streaming going with sf2. I agree with Steve's comment above that SF2 appear's to have been bolted on and it was easier to begin with SFZ.