2
2
Play soundfiles from the disk.
4
SfMarkerXXX objects use markers features (store in the header) from
4
SfMarkerXXX objects use markers features (store in the header) from
5
5
an AIFF file to create more specific reading patterns.
9
Copyright 2010 Olivier Belanger
9
Copyright 2009-2015 Olivier Belanger
11
11
This file is part of pyo, a python module to help digital signal
12
12
processing script creation.
14
14
pyo is free software: you can redistribute it and/or modify
15
it under the terms of the GNU General Public License as published by
16
the Free Software Foundation, either version 3 of the License, or
17
(at your option) any later version.
15
it under the terms of the GNU Lesser General Public License as
16
published by the Free Software Foundation, either version 3 of the
17
License, or (at your option) any later version.
19
19
pyo is distributed in the hope that it will be useful,
20
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
GNU General Public License for more details.
22
GNU Lesser General Public License for more details.
24
You should have received a copy of the GNU General Public License
25
along with pyo. If not, see <http://www.gnu.org/licenses/>.
24
You should have received a copy of the GNU Lesser General Public
25
License along with pyo. If not, see <http://www.gnu.org/licenses/>.
27
27
from _core import *
28
28
from _maps import *
32
32
class SfPlayer(PyoObject):
36
Reads audio data from a file using one of several available interpolation
36
Reads audio data from a file using one of several available interpolation
37
37
types. User can alter its pitch with the `speed` attribute. The object
38
takes care of sampling rate conversion to match the Server sampling
38
takes care of sampling rate conversion to match the Server sampling
41
41
:Parent: :py:class:`PyoObject`
46
46
Full path name of the sound to read.
47
47
speed : float or PyoObject, optional
48
Transpose the pitch of input sound by this factor.
48
Transpose the pitch of input sound by this factor.
51
1 is the original pitch, lower values play sound slower, and higher
52
values play sound faster.
54
Negative values results in playing sound backward.
51
1 is the original pitch, lower values play sound slower, and higher
52
values play sound faster.
54
Negative values results in playing sound backward.
56
56
Although the `speed` attribute accepts audio
57
57
rate signal, its value is updated only once per buffer size.
58
58
loop : bool, optional
59
59
If set to True, sound will play in loop. Defaults to False.
60
offset : float, optional
61
Time in seconds of input sound to be skipped, assuming speed = 1.
60
offset : float, optional
61
Time in seconds of input sound to be skipped, assuming speed = 1.
63
63
interp : int, optional
64
64
Interpolation type. Defaults to 2.
72
SfPlayer will sends a trigger signal at the end of the playback if
73
loop is off or any time it wraps around if loop is on. User can
72
SfPlayer will sends a trigger signal at the end of the playback if
73
loop is off or any time it wraps around if loop is on. User can
74
74
retrieve the trigger streams by calling obj['trig']:
76
76
>>> sf = SfPlayer(SNDS_PATH + "/transparent.aif").out()
77
77
>>> trig = TrigRand(sf['trig'])
79
79
>>> s = Server().boot()
81
81
>>> snd = SNDS_PATH + "/transparent.aif"
82
82
>>> sf = SfPlayer(snd, speed=[.75,.8], loop=True, mul=.3).out()
85
85
def __init__(self, path, speed=1, loop=False, offset=0, interp=2, mul=1, add=0):
86
86
PyoObject.__init__(self, mul, add)
104
104
def setPath(self, path):
106
106
Sets a new sound to read.
108
The number of channels of the new sound must match those
108
The number of channels of the new sound must match those
109
109
of the sound loaded at initialization time.
114
114
Full path of the new sound.
129
129
if _snd_chnls != curNchnls:
130
130
print "Soundfile must contains exactly %d channels." % curNchnls
133
133
self._path = path
134
134
path, lmax = convertArgsToLists(path)
135
135
[obj.setSound(wrap(path,i)) for i, obj in enumerate(self._base_players)]
137
137
def setSound(self, path):
139
139
Sets a new sound to read.
141
The number of channels of the new sound must match those
141
The number of channels of the new sound must match those
142
142
of the sound loaded at initialization time.
147
147
Full path of the new sound.
196
196
def setInterp(self, x):
198
198
Replace the `interp` attribute.
202
202
x : int {1, 2, 3, 4}
203
203
new `interp` attribute.
207
207
x, lmax = convertArgsToLists(x)
208
208
[obj.setInterp(wrap(x,i)) for i, obj in enumerate(self._base_players)]
210
210
def ctrl(self, map_list=None, title=None, wxnoserver=False):
211
self._map_list = [SLMap(-2., 2., 'lin', 'speed', self._speed),
211
self._map_list = [SLMap(-2., 2., 'lin', 'speed', self._speed),
212
212
SLMap(1, 4, 'lin', 'interp', self._interp, res="int", dataOnly=True),
213
213
SLMapMul(self._mul)]
214
214
PyoObject.ctrl(self, map_list, title, wxnoserver)
218
218
"""string. Full path of the sound."""
219
219
return self._path
221
221
def path(self, x): self.setPath(x)
225
225
"""string. Alias to the `path` attribute."""
226
226
return self._path
228
228
def sound(self, x): self.setPath(x)
232
232
"""float or PyoObject. Transposition factor."""
233
233
return self._speed
235
235
def speed(self, x): self.setSpeed(x)
239
239
"""bool. Looping mode."""
240
240
return self._loop
242
242
def loop(self, x): self.setLoop(x)
246
246
"""float. Time, in seconds, of the first sample to read."""
247
247
return self._offset
249
249
def offset(self, x): self.setOffset(x)
253
253
"""int {1, 2, 3, 4}. Interpolation method."""
254
254
return self._interp
258
258
class SfMarkerShuffler(PyoObject):
260
260
AIFF with markers soundfile shuffler.
262
Reads audio data from a AIFF file using one of several available
263
interpolation types. User can alter its pitch with the `speed`
264
attribute. The object takes care of sampling rate conversion to
265
match the Server sampling rate setting.
262
Reads audio data from a AIFF file using one of several available
263
interpolation types. User can alter its pitch with the `speed`
264
attribute. The object takes care of sampling rate conversion to
265
match the Server sampling rate setting.
267
267
The reading pointer randomly choose a marker (from the MARK chunk
268
in the header of the AIFF file) as its starting point and reads
269
the samples until it reaches the following marker. Then, it choose
268
in the header of the AIFF file) as its starting point and reads
269
the samples until it reaches the following marker. Then, it choose
270
270
another marker and reads from the new position and so on...
272
272
:Parent: :py:class:`PyoObject`
277
277
Full path name of the sound to read. Can't e changed after
279
279
speed : float or PyoObject, optional
280
Transpose the pitch of input sound by this factor.
280
Transpose the pitch of input sound by this factor.
283
1 is the original pitch, lower values play sound slower, and higher
284
values play sound faster.
286
Negative values results in playing sound backward.
283
1 is the original pitch, lower values play sound slower, and higher
284
values play sound faster.
286
Negative values results in playing sound backward.
288
288
Although the `speed` attribute accepts audio
289
289
rate signal, its value is updated only once per buffer size.
290
290
interp : int, optional
297
297
>>> s = Server().boot()
299
299
>>> sf = SfMarkerShuffler(SNDS_PATH + "/transparent.aif", speed=[1,1], mul=.3).out()
302
302
def __init__(self, path, speed=1, interp=2, mul=1, add=0):
303
303
PyoObject.__init__(self, mul, add)
315
315
self._markers = [m[1] for m in markerstmp]
318
318
self._base_players.append(SfMarkerShuffler_base(wrap(path,i), self._markers, wrap(speed,i), wrap(interp,i)))
319
319
for i in range(lmax * self._snd_chnls):
320
320
j = i / self._snd_chnls
351
351
def getMarkers(self):
353
353
Returns a list of marker time values in samples.
356
356
return self._markers
358
358
def ctrl(self, map_list=None, title=None, wxnoserver=False):
359
self._map_list = [SLMap(0.01, 2., 'lin', 'speed', self._speed),
359
self._map_list = [SLMap(0.01, 2., 'lin', 'speed', self._speed),
360
360
SLMap(1, 4, 'lin', 'interp', self._interp, res="int", dataOnly=True),
361
361
SLMapMul(self._mul)]
362
362
PyoObject.ctrl(self, map_list, title, wxnoserver)
366
366
"""float or PyoObject. Transposition factor."""
367
367
return self._speed
369
369
def speed(self, x): self.setSpeed(x)
373
373
"""int {1, 2, 3, 4}. Interpolation method."""
374
374
return self._interp
380
380
AIFF with markers soundfile looper.
382
Reads audio data from a AIFF file using one of several available
382
Reads audio data from a AIFF file using one of several available
383
383
interpolation types. User can alter its pitch with the `speed`
384
attribute. The object takes care of sampling rate conversion to
385
match the Server sampling rate setting.
384
attribute. The object takes care of sampling rate conversion to
385
match the Server sampling rate setting.
387
387
The reading pointer loops a specific marker (from the MARK chunk
388
in the header of the AIFF file) until it received a new integer
388
in the header of the AIFF file) until it received a new integer
389
389
in the `mark` attribute.
391
391
:Parent: :py:class:`PyoObject`
396
396
Full path name of the sound to read.
397
397
speed : float or PyoObject, optional
398
Transpose the pitch of input sound by this factor.
398
Transpose the pitch of input sound by this factor.
401
1 is the original pitch, lower values play sound slower, and higher
402
values play sound faster.
404
Negative values results in playing sound backward.
401
1 is the original pitch, lower values play sound slower, and higher
402
values play sound faster.
404
Negative values results in playing sound backward.
406
406
Although the `speed` attribute accepts audio
407
407
rate signal, its value is updated only once per buffer size.
408
408
mark : float or PyoObject, optional
409
Integer denoting the marker to loop, in the range
409
Integer denoting the marker to loop, in the range
410
410
0 -> len(getMarkers()). Defaults to 0.
411
411
interp : int, optional
412
412
Choice of the interpolation method. Defaults to 2.
439
439
self._markers = [m[1] for m in markerstmp]
442
442
self._base_players.append(SfMarkerLooper_base(wrap(path,i), self._markers, wrap(speed,i), wrap(mark,i), wrap(interp,i)))
443
443
for i in range(lmax * self._snd_chnls):
444
444
j = i / self._snd_chnls
494
494
return self._markers
496
496
def ctrl(self, map_list=None, title=None, wxnoserver=False):
497
self._map_list = [SLMap(0.01, 2., 'lin', 'speed', self._speed),
497
self._map_list = [SLMap(0.01, 2., 'lin', 'speed', self._speed),
498
498
SLMap(0, len(self._markers)-1, 'lin', 'mark', self._mark, 'int'),
499
499
SLMap(1, 4, 'lin', 'interp', self._interp, res="int", dataOnly=True),
500
500
SLMapMul(self._mul)]
501
501
PyoObject.ctrl(self, map_list, title, wxnoserver)
505
505
"""float or PyoObject. Transposition factor."""
506
506
return self._speed
508
508
def speed(self, x): self.setSpeed(x)
512
512
"""float or PyoObject. Marker to loop."""
513
513
return self._marker
515
515
def mark(self, x): self.setMark(x)
519
519
"""int {1, 2, 3, 4}. Interpolation method."""
520
520
return self._interp
522
def interp(self, x): self.setInterp(x)
522
def interp(self, x): self.setInterp(x)
b'\\ No newline at end of file'