Hi there,
that example I gave you contains a lot of ideas, if you haven’t come across them individually before, it makes sense that it won’t be easy to understand it in one go - that’s completely normal
sample "/foo/bar/baz.wav", slice: look, num_slices: num_chunks, amp: (line 1, 0, steps: num_chunks).look
There’s a few things going on here:
- A call to
sample
with a number of different options being set
- A ring which is generated by the
line
function
- A call to
look
on this ring
Let’s look at each in turn. Once you’ve worked through all the parts, try then to combine them in your head. It may take a little time, but be patient and walk away and come back to it a few times. Eventually it might click and make sense, but if it doesn’t, (and that’s also totally normal) let me know and I’ll try and find a different way of explaining things
1. Sample
Calls to sample
have one required argument (the name/path of the sample to trigger) some filter options (if the path is a list of paths or a folder containing multiple sample files), and some options. In this case, we’re not using any filter options (for more information about this look up the sample
documentation).
However, we are specifying a path to a wav file "/foo/bar/baz.wav"
and some opts: slice:
, num_slices:
and amp:
. The amp:
opt is the most obvious, this is an amplitude (1 being default) with which to play back the sample: an amp:
of 0
is silent, 0.5
is half amplitude and 2
is double amplitude.
The slice:
and num_slices:
opts are more interesting. The num_slices:
opt lets you specify how many equally spaced slices of the original audio we should consider and slice:
sets the start:
and finish:
opts implicitly.
(See A.12 Sample Slicing in the tutorial for a manual version of this which sets start:
and finish:
opts directly and was written before slice:
was available).
2. Rings
For a nice description of rings take a look at section 8.4 of the built-in tutorial.
As a quick summary, they’re essentially lists of things that when indexed into always return an element within the original list. For example:
[1, 2, 3, 4][100] #=> nil
- the list only has 4 elements, so indexing 100 is off the end, therefore return nil
.
(ring 1, 2, 3, 4)[100] #=> 1
- the ring only has 4 elements, but indexing 100 wraps around internally (using mod
) so we get a value within the ring. Indexing 101
would return 2 etc.
In this case we have a ring generated from the line
function which will build a ring containing an ordered sequence of numbers with starting value 1
and finish value 0
and 10
steps:
(line 1, 0, steps: 10) #=> (ring 1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1)
Using the line
function is a shorter and neater way of creating the above ring rather than writing it out by hand.
3. Look
look
is part of the counting system which is documented in section 9.4 of the built-in tutorial. Please also look through the examples of the look
docstring. Essentially calls to tick
increment a live-loop-local counter and calls to look
will return the current value of that counter. However, when called on rings, look will not just look up the current value of the counter, it will use that value as an index into the ring itself. This will always return a value within the ring no matter how big or small the counter value (due to the index-wrapping property of rings).