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

Can 2 Sampler instances share the set of same audio files? #1216

Open
eddydong opened this issue Nov 13, 2023 · 4 comments
Open

Can 2 Sampler instances share the set of same audio files? #1216

eddydong opened this issue Nov 13, 2023 · 4 comments

Comments

@eddydong
Copy link

Say I have 2 tracks of the same piano instrument. I new-ed 2 Sampler( url:{xxx}, function(){} ), each for a track, with the same "url:{xxx}" parameter since they are the same instrument.

The issue is: each time it will download the audio files (referred to by the "url:{xxx}" parameter) from the server. I believe this is a waste of server bandwidth - since the 2 set of audio files are identical, isn't there a way that we just download one set of the audio files and let the 2 sampler instances share it?

@eddydong
Copy link
Author

Or let me ask this way: can we feed the new Sampler() function a set of buffered audio files, instead of the url every time? If that's possible, we can load the audio files in the buffer first and then anytime when we need a new instance of this instrument, we just new it from the buffer.

@dirkk0
Copy link

dirkk0 commented Nov 13, 2023

I am pretty sure Tone does this already:
https://github.com/Tonejs/Tone.js/blob/c313bc6/Tone/instrument/Sampler.ts#L14
but I personally didn't try it yet.

@eddydong
Copy link
Author

I am pretty sure Tone does this already: https://github.com/Tonejs/Tone.js/blob/c313bc6/Tone/instrument/Sampler.ts#L14 but I personally didn't try it yet.

Thanks for the info! Unfortunately I don't know much about the TS code... Can you please help write a few lines in JS illustrating how to do 1) load audio files into a whatever buffer, and 2) new Samplers from the buffer? Thanks very much!!!

@dirkk0
Copy link

dirkk0 commented Nov 14, 2023

I could, but what you are doing is most likely 'premature optimization'. Bandwidth is cheap and the browser cache will take care of all of this for you - this is what it's for.
So: if this type of optimization is still very important to you, then your project is of professional nature, and in this case you are welcome to email me for a quote.

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

No branches or pull requests

2 participants