How to create a Sampler Instrument / sampleOscillator

hello everyone,
i am trying to get my head around this for a couple of days and checked on github, the juce tutorials and this forum and havent found anything yet to make it possible to create a simple instrument that loads a sample (well that part i got) and play it like an oscillator.
what i found is the SamplerSound and SamplerVoice - Class
but i dont know really how to pass the sample to the buffer without making the application crash.
thanks in advance, steve

i made it work to play a sample via SamplerSound and SamplerVoice. my Sample that i have loaded with the AudioFormatReader gets played via my midikeyboard. i am still very stuck on how to make the sample loop. i figured that i probably shouldnt add it with “addSound(new SamplerSound()” and instead read it into a buffer and use that “somehow” in the renderNextBlock Method. propably geting the length of the sample etc. anyone got any idea how to do go on from here?

you mean a wavetable oscillator, don’t you? you could for example declare that a user has to drop a sample that is on the note c1 in order to get correct results. that would make things easy because every note has a specific wavelength. then you’d define the resolution of your wavetable, for example 256, like in serum. now there can be 256 samples / wave. from these informations you could mathematically calculate how it should put the samples from the audio sample into the buffer of the oscillator so it’s more or less correct. i’d use linear interpolation for all indexes that don’t have exact values. then you could just play that oscillator back at any frequency by changing the speed at which it increments through the buffer for each sample. i could give you a more detailed example if i had the project in front of me now where i did something like this, but maybe you wanna figure it out yourself anyway. it’s been pretty fun

1 Like

thanks for the reply. a code to look at is always appreciated as i am a noob. but at the end i need to code it on my own to understand it completly even if it takes me ages… :slight_smile: