Cabbage Logo
Back to Cabbage Site

A simple sampler

Here’s a simple sampler I’ve been working on, I mainly wanted it to look decent. There’s a lot I could add, different FX and different samples… I have an example of changing the audio file with a knob somewhere I need to look at that but any tips are definitely welcome. Theres also gotta be a better way to filter the samples than have a filter for each pad but it works :\

I spent all day yesterday on this, time well invested

Here is the file



Nice work. Your gut instinct is right, there is a better way to do this without all that copy and paste code. The tricky thing is that the schedule and event opcodes don’t allow strings to be passed as p-fields. But one way you can do it is to set up a global array of strings, then pass an index as p4 when calling your one Pad instrument…

; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

event_i "i","get",0,-1
event_i "i","rev",0,-1

#define OUT #outs aout * chnget:k(Slev), aout * chnget:k(Slev)#

gSSamples[] init 4
gSSamples[0] = "./samples/Floor tom 2.wav"
gSSamples[1] = "./samples/Snare 1.wav"
gSSamples[2] = "./samples/hihat 1.wav"
gSSamples[3] = "./samples/kick.wav"

gSPads[] init 4
gSPads[0] = "tom"
gSPads[1] = "snare"
gSPads[2] = "hihat"
gSPads[3] = "kick"

instr get

schedkwhen changed:k(chnget:k("tom")), 0, 0, 100, 0, 1, 0 
schedkwhen changed:k(chnget:k("snare")), 0, 0, 100, 0, 1, 1
schedkwhen changed:k(chnget:k("hat")), 0, 0, 100, 0, 1, 2
schedkwhen changed:k(chnget:k("kick")), 0, 0, 100, 0, 1, 3


instr 100
    iPad = p4  
    a1, a2 diskin2 gSSamples[iPad], 1
    aout moogladder a1, 20000 * chnget:k("cutoff"), 1 * chnget("res")
    Slev = sprintf("%slev", gSPads[iPad])
    garev += (a1 * chnget:k("tomrev")) 

instr rev

If you renamed your samples to tom, kick, snare and hihat, you could do all of this with a single array and sprintf. :+1: