sdclibbery / limut

Live coding music and visuals within a browser using WebAudio and WebGL
Other
56 stars 4 forks source link

[Feature] Allowing users to add new sampled instruments/players #1

Closed mathigatti closed 3 years ago

mathigatti commented 3 years ago

Wow this tool is amazing, thanks for bulding and sharing it!

Would it be possible to create a general sample instrument? Like the piano one but for any instrument given a folder with samples.

I mean adding some way to allow users to load their samples and then using them like the piano command.

sdclibbery commented 3 years ago

Hiya! Thanks for the kind words and for the suggestion 🙂 I've actually just added the ability to play samples from the web; eg:

p play 0, dur=2, sample='https://upload.wikimedia.org/wikipedia/commons/b/b6/Sting_%282%29.ogg'

It requires the audio file to be shared with CORS on the server (all wikimedia files are shared this way, but many other online sounds are not), and it may take a while to download and start playing, especially with longer files. The support is pretty basic so far, theres no beat stretch or cutting up / rearranging the sample, and it doesn't allow for pitched instruments like the piano. Is it good enough for now, or would some of the above improvements be useful?

sdclibbery commented 3 years ago

Anyway, just added a sample synth to play pitched samples; eg: s sample 0.1., dur=1, sample='https://upload.wikimedia.org/wikipedia/commons/8/83/Audio_frequency_tone%2C_C3%2C_130.81hz.ogg', samplepitch=130.81 It's fairly simple and it doesn't support vibrato yet, but it should work. Let me know if it works for you 🙂

mathigatti commented 3 years ago

Excellent, thank you very much!

That works but I thought it might be easier to use if it allows to load local audio files like in this example.

Do you think it might be possible to do? I just forked the project, I don't know if it's the simplest approach but I'm trying to add an "upload your samples" button and a new sample player that works the same than the piano (loading different samples depending the note) but using the local samples instead of the ones in the salamander folder.

sdclibbery commented 3 years ago

Possibly you might need to use a file and a FileReader, a bit like the first half of this: https://www.russellgood.com/process-uploaded-file-web-audio-api/ ? I think the tricky bit will be not having to reselect all your samples whenever you reload the page. Maybe the files can be stored in local storage?

mathigatti commented 3 years ago

Thanks! I will try that