15.1.7 Extracting samples from audio clips: channel_data
The channel_data command gets samples from an audio clip.
-
channel_data takes one mandatory argument and up to
two optional argument:
-
A, an audio clip.
- Optionally options, which can be the following (the
order is unimportant):
-
One of:
-
n, a postive integer (channel number).
- matrix, the symbol.
- One of:
-
range=[m,n] or range=m..n
for nonnegative integers m and n.
- range=a..b for floating point numbers a and
b.
- channel_data(A ⟨,options⟩)
returns data from the channels as a sequence of lists. The returned
sample values are all within the interval [−1.0,1.0], i.e. the
amplitude of the returned signal is relative. The maximum possible
amplitude is represented by the value 1.0.
-
With no options, data from all channels are returned as a
sequence of lists.
- With the option n (the channel number) or if there is only
one channel, only the data from this channel is returned in a
single list.
- With the option matrix, the lists representing the
channel data are returned as the rows of a matrix.
- With the option range=[m,n] or
range=m..n, with m and n integers, only the
samples from n-th to m-th (inclusive) are extracted.
- With the option range=a..b, with floating point
numbers a and b, then a and b are bounds in seconds.
Example.
Assuming that the directory sounds contains example.wav, a
wav file with three seconds of stereo sound:
Input:
s:=readwav("/path/to/sounds/example.wav"):; |
L,R:=channel_data(s,range=1.2..1.5)
|
Output:
A list L resp. R containing the data between 1.2 and
1.5 seconds in the left resp. right channel of the original file.