~ubuntu-branches/ubuntu/wily/python-pyo/wily-proposed

« back to all changes in this revision

Viewing changes to pyolib/players.py

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2015-05-25 09:55:36 UTC
  • mfrom: (13.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20150525095536-haz5xfrxl6u3m085
Tags: 0.7.5-2
Minor packaging fixes and push to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""
2
2
Play soundfiles from the disk.
3
3
 
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.
6
6
 
7
7
"""
8
8
"""
9
 
Copyright 2010 Olivier Belanger
 
9
Copyright 2009-2015 Olivier Belanger
10
10
 
11
11
This file is part of pyo, a python module to help digital signal
12
12
processing script creation.
13
13
 
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.
18
18
 
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.
23
23
 
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/>.
26
26
"""
27
27
from _core import *
28
28
from _maps import *
32
32
class SfPlayer(PyoObject):
33
33
    """
34
34
    Soundfile player.
35
 
    
36
 
    Reads audio data from a file using one of several available interpolation 
 
35
 
 
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
39
39
    rate setting.
40
 
    
 
40
 
41
41
    :Parent: :py:class:`PyoObject`
42
 
    
 
42
 
43
43
    :Args:
44
 
    
 
44
 
45
45
        path : string
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.
49
49
            Defaults to 1.
50
 
            
51
 
            1 is the original pitch, lower values play sound slower, and higher 
52
 
            values play sound faster. 
53
 
            
54
 
            Negative values results in playing sound backward. 
55
 
            
 
50
 
 
51
            1 is the original pitch, lower values play sound slower, and higher
 
52
            values play sound faster.
 
53
 
 
54
            Negative values results in playing sound backward.
 
55
 
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.
62
62
            Defaults to 0.
63
63
        interp : int, optional
64
64
            Interpolation type. Defaults to 2.
68
68
                4. cubic
69
69
 
70
70
    .. note::
71
 
    
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 
 
71
 
 
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']:
75
 
        
 
75
 
76
76
        >>> sf = SfPlayer(SNDS_PATH + "/transparent.aif").out()
77
77
        >>> trig = TrigRand(sf['trig'])
78
 
    
 
78
 
79
79
    >>> s = Server().boot()
80
80
    >>> s.start()
81
81
    >>> snd = SNDS_PATH + "/transparent.aif"
82
82
    >>> sf = SfPlayer(snd, speed=[.75,.8], loop=True, mul=.3).out()
83
 
    
 
83
 
84
84
    """
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):
105
105
        """
106
106
        Sets a new sound to read.
107
 
        
108
 
        The number of channels of the new sound must match those 
 
107
 
 
108
        The number of channels of the new sound must match those
109
109
        of the sound loaded at initialization time.
110
 
        
 
110
 
111
111
        :Args:
112
 
        
 
112
 
113
113
            path : string
114
114
                Full path of the new sound.
115
115
 
129
129
        if _snd_chnls != curNchnls:
130
130
            print "Soundfile must contains exactly %d channels." % curNchnls
131
131
            return
132
 
    
 
132
 
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):
138
138
        """
139
139
        Sets a new sound to read.
140
 
        
141
 
        The number of channels of the new sound must match those 
 
140
 
 
141
        The number of channels of the new sound must match those
142
142
        of the sound loaded at initialization time.
143
 
        
 
143
 
144
144
        :Args:
145
 
        
 
145
 
146
146
            path : string
147
147
                Full path of the new sound.
148
148
 
152
152
    def setSpeed(self, x):
153
153
        """
154
154
        Replace the `speed` attribute.
155
 
        
 
155
 
156
156
        :Args:
157
157
 
158
158
            x : float or PyoObject
159
159
                new `speed` attribute.
160
 
        
 
160
 
161
161
        """
162
162
        self._speed = x
163
163
        x, lmax = convertArgsToLists(x)
166
166
    def setLoop(self, x):
167
167
        """
168
168
        Replace the `loop` attribute.
169
 
        
 
169
 
170
170
        :Args:
171
171
 
172
172
            x : bool {True, False}
173
173
                new `loop` attribute.
174
 
        
 
174
 
175
175
        """
176
176
        self._loop = x
177
177
        x, lmax = convertArgsToLists(x)
182
182
    def setOffset(self, x):
183
183
        """
184
184
        Replace the `offset` attribute.
185
 
        
 
185
 
186
186
        :Args:
187
187
 
188
188
            x : float
189
189
                new `offset` attribute.
190
 
        
 
190
 
191
191
        """
192
192
        self._offset = x
193
193
        x, lmax = convertArgsToLists(x)
196
196
    def setInterp(self, x):
197
197
        """
198
198
        Replace the `interp` attribute.
199
 
        
 
199
 
200
200
        :Args:
201
201
 
202
202
            x : int {1, 2, 3, 4}
203
203
                new `interp` attribute.
204
 
        
 
204
 
205
205
        """
206
206
        self._interp = x
207
207
        x, lmax = convertArgsToLists(x)
208
208
        [obj.setInterp(wrap(x,i)) for i, obj in enumerate(self._base_players)]
209
209
 
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)
215
215
 
216
216
    @property
217
 
    def path(self): 
 
217
    def path(self):
218
218
        """string. Full path of the sound."""
219
219
        return self._path
220
220
    @path.setter
221
221
    def path(self, x): self.setPath(x)
222
 
          
 
222
 
223
223
    @property
224
 
    def sound(self): 
 
224
    def sound(self):
225
225
        """string. Alias to the `path` attribute."""
226
226
        return self._path
227
227
    @sound.setter
228
228
    def sound(self, x): self.setPath(x)
229
 
    
 
229
 
230
230
    @property
231
 
    def speed(self): 
 
231
    def speed(self):
232
232
        """float or PyoObject. Transposition factor."""
233
233
        return self._speed
234
234
    @speed.setter
235
235
    def speed(self, x): self.setSpeed(x)
236
236
 
237
237
    @property
238
 
    def loop(self): 
 
238
    def loop(self):
239
239
        """bool. Looping mode."""
240
240
        return self._loop
241
241
    @loop.setter
242
242
    def loop(self, x): self.setLoop(x)
243
243
 
244
244
    @property
245
 
    def offset(self): 
 
245
    def offset(self):
246
246
        """float. Time, in seconds, of the first sample to read."""
247
247
        return self._offset
248
248
    @offset.setter
249
249
    def offset(self, x): self.setOffset(x)
250
250
 
251
251
    @property
252
 
    def interp(self): 
 
252
    def interp(self):
253
253
        """int {1, 2, 3, 4}. Interpolation method."""
254
254
        return self._interp
255
255
    @interp.setter
258
258
class SfMarkerShuffler(PyoObject):
259
259
    """
260
260
    AIFF with markers soundfile shuffler.
261
 
    
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. 
266
 
    
 
261
 
 
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.
 
266
 
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...
271
 
    
 
271
 
272
272
    :Parent: :py:class:`PyoObject`
273
 
    
 
273
 
274
274
    :Args:
275
 
    
 
275
 
276
276
        path : string
277
277
            Full path name of the sound to read. Can't e changed after
278
278
            initialization.
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.
281
281
            Defaults to 1.
282
 
            
283
 
            1 is the original pitch, lower values play sound slower, and higher 
284
 
            values play sound faster. 
285
 
            
286
 
            Negative values results in playing sound backward. 
287
 
            
 
282
 
 
283
            1 is the original pitch, lower values play sound slower, and higher
 
284
            values play sound faster.
 
285
 
 
286
            Negative values results in playing sound backward.
 
287
 
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()
298
298
    >>> s.start()
299
299
    >>> sf = SfMarkerShuffler(SNDS_PATH + "/transparent.aif", speed=[1,1], mul=.3).out()
300
 
    
 
300
 
301
301
    """
302
302
    def __init__(self, path, speed=1, interp=2, mul=1, add=0):
303
303
        PyoObject.__init__(self, mul, add)
314
314
                sf.close()
315
315
                self._markers = [m[1] for m in markerstmp]
316
316
            except:
317
 
                self._markers = []    
 
317
                self._markers = []
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
323
323
    def setSpeed(self, x):
324
324
        """
325
325
        Replace the `speed` attribute.
326
 
        
 
326
 
327
327
        :Args:
328
328
 
329
329
            x : float or PyoObject
330
330
                new `speed` attribute.
331
 
        
 
331
 
332
332
        """
333
333
        self._speed = x
334
334
        x, lmax = convertArgsToLists(x)
337
337
    def setInterp(self, x):
338
338
        """
339
339
        Replace the `interp` attribute.
340
 
        
 
340
 
341
341
        :Args:
342
342
 
343
343
            x : int {1, 2, 3, 4}
344
344
                new `interp` attribute.
345
 
        
 
345
 
346
346
        """
347
347
        self._interp = x
348
348
        x, lmax = convertArgsToLists(x)
351
351
    def getMarkers(self):
352
352
        """
353
353
        Returns a list of marker time values in samples.
354
 
        
 
354
 
355
355
        """
356
356
        return self._markers
357
 
        
 
357
 
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)
363
 
                    
 
363
 
364
364
    @property
365
 
    def speed(self): 
 
365
    def speed(self):
366
366
        """float or PyoObject. Transposition factor."""
367
367
        return self._speed
368
368
    @speed.setter
369
369
    def speed(self, x): self.setSpeed(x)
370
370
 
371
371
    @property
372
 
    def interp(self): 
 
372
    def interp(self):
373
373
        """int {1, 2, 3, 4}. Interpolation method."""
374
374
        return self._interp
375
375
    @interp.setter
379
379
    """
380
380
    AIFF with markers soundfile looper.
381
381
 
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. 
386
 
    
 
384
    attribute. The object takes care of sampling rate conversion to
 
385
    match the Server sampling rate setting.
 
386
 
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.
390
390
 
391
391
    :Parent: :py:class:`PyoObject`
395
395
        path : string
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.
399
399
            Defaults to 1.
400
 
            
401
 
            1 is the original pitch, lower values play sound slower, and higher 
402
 
            values play sound faster. 
403
 
            
404
 
            Negative values results in playing sound backward. 
405
 
            
 
400
 
 
401
            1 is the original pitch, lower values play sound slower, and higher
 
402
            values play sound faster.
 
403
 
 
404
            Negative values results in playing sound backward.
 
405
 
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.
438
438
                sf.close()
439
439
                self._markers = [m[1] for m in markerstmp]
440
440
            except:
441
 
                self._markers = []    
 
441
                self._markers = []
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
495
495
 
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)
502
502
 
503
503
    @property
504
 
    def speed(self): 
 
504
    def speed(self):
505
505
        """float or PyoObject. Transposition factor."""
506
506
        return self._speed
507
507
    @speed.setter
508
508
    def speed(self, x): self.setSpeed(x)
509
509
 
510
510
    @property
511
 
    def mark(self): 
 
511
    def mark(self):
512
512
        """float or PyoObject. Marker to loop."""
513
513
        return self._marker
514
514
    @mark.setter
515
515
    def mark(self, x): self.setMark(x)
516
516
 
517
517
    @property
518
 
    def interp(self): 
 
518
    def interp(self):
519
519
        """int {1, 2, 3, 4}. Interpolation method."""
520
520
        return self._interp
521
521
    @interp.setter
522
 
    def interp(self, x): self.setInterp(x)
 
522
    def interp(self, x): self.setInterp(x)
 
 
b'\\ No newline at end of file'