Skip to content

Samples

Miika Alonen edited this page Oct 17, 2022 · 3 revisions

Samples

Samples can be used to create new sample based synth or samples as patterns. Long samples can also be splitted and played as patterns.

Using sample as a synth

You can also use zplay with samples to create new "synths" where zplay uses Sonic Pi's pitch or rate parameters to play the degrees. Sample length is kept the same by default, which also affects the produces sound. Alternatively use rate_based pitch altering that will also change the sample length.

Note lengths do not affect the sample length by default (Still ). Samples can be cut to note length using cut where the value is the multiplier for the actual note length, meaning 1 means same as the actual note length and for example 0.95 means slightly less. etc.

Examples:

# Pitch based (default)
zplay "[: q 4 4 3 e 4 5 | q 0 1 2 1 2 2 4 5 | q 2 2 3 | e 4 5 6 4 5 3 4 2 3 2 :]", sample: :guit_e_fifths, start: 0.2, finish: 0.25, amp: 3

# Pitch vs. rate based sound different on different samples

zplay "h 1 3 2 4 wr", sample: :ambi_choir, rate_based: true
zplay "h 1 3 2 4 wr", sample: :ambi_choir

zplay "h 1 3 2 4 wr", sample: :ambi_glass_rub, rate_based: true, cut: 1.5
zplay "h 1 3 2 4 wr", sample: :ambi_glass_rub, cut: 1.5

Custom Samples

Custom samples can be used with direct path or with sample_dir parameter and number of the sample:

zplay "1 2 3 4", sample: "~/samples/Jungle/Vocals/Bad Boy.wav"
zplay "1 2 3 4", sample_dir: "~/samples/Jungle/Vocals/", sample: 1 # Gets first sample from the directory

Rhythmic patterns using samples

All capital characters can be assigned for sample use in root level or via use parameter. Note that some characters may overwrite other control characters like 'A', but it doesnt matter if you are not using that control character.

zplay "[ D [D D]] hD D", use: { D: :bass_woodsy_c }

zplay "[: q X O e X X q O :2]", X: :bd_tek, O: :drum_snare_soft # Assign X and O for samples

# Same using **use** parameter
zplay "[: q X O e X X q O :2]", use: {"X": :bd_tek, "O": :drum_snare_soft}

# Sleep and other sample opts can be defined in hash
zplay "[: O q X X X X :2]", X: :bd_tek, O: {sample: :ambi_choir, rate: 0.3, duration: 0}

# Sample or midi mapping can also be edited in separate hash object
n = {
  B: :bd_tek,
  K: :drum_snare_soft,
  H: {sample: :drum_cymbal_closed, amp: 0.2}
}

# Reuses existing n mapping:
zplay "[B H] [B [H H]] [BK H] [[BK B] H]", use: n

# Re-use the same pattern midi instuments using **midi: true** (values could also be changed in hashmap):
zplay "[B H] [B [H H]] [BK H] [[BK B] H]", B: 60, H: 70, K: 90, midi: true, port: "loopmidi"

Rhytmic patterns and samples can be defined and modified separately. Breakbeat example:

use_bpm 200
breakbeat = "| HB H | HS [H B] | [H B] [H B] | HS [H B] |
             | HB H | HS H     | [H H] [r B] | HS [H H] |"

samples = {
  B: :bd_tek,
  S: :drum_snare_soft,
  H: {sample: :drum_cymbal_closed, amp: 0.2}
}

z1 breakbeat, use: samples

Splitting long samples

Samples can be splitted automatically using onset detection algorithm (same as using :onset in Sonic Pi). Splitted samples can be played using generative patterns.

For example:

z1 "q 0 1 2 0 (4..6)~ e 5 (0,9)", split: :loop_amen
z1 "q (2 1 5 2)<3,6>(4 2 3 0)", split: :loop_industrial
z1 "q 0 e (0,7) 1 q 4 (0,3)", split: :loop_breakbeat
Clone this wiki locally