Package topo :: Package patterns :: Module audio
[hide private]
[frames] | no frames]

Source Code for Module topo.patterns.audio

 1  """ 
 2  Pattern generators for audio signals. 
 3   
 4   
 5  $Id: audio.py 6931 2007-10-21 06:01:35Z ceball $ 
 6  """ 
 7  __version__='$Revision: 6931 $' 
 8   
 9  # CEBALERT: you need to build pyaudiolab to use this file. 
10  # (Not tested it on Windows or OS X.) 
11  try: 
12      import pyaudiolab 
13  except ImportError: 
14      print "Warning: pyaudiolab must be built to use audio.py" 
15       
16  import numpy 
17   
18  from topo.base.parameterclasses import Integer,Parameter 
19   
20  from topo.misc.filepaths import Filename 
21   
22  from topo.patterns.basic import OneDPowerSpectrum 
23   
24   
25   
26 -class Audio(OneDPowerSpectrum):
27 """ 28 ** Untested: currently being written. ** 29 """ 30 # CB: find an example sound (I haven't listened to this one; 31 # there's no signal in it for the first hundred or so frames). 32 # Use a wav file. 33 filename = Filename( 34 default='lib/python2.4/site-packages/pyaudiolab/test_data/test.flac', 35 precedence=0.9,doc= 36 """ 37 File path (can be relative to Topographica's base path) to an audio file. 38 The audio can be in any format accepted by pyaudiolab, e.g. WAV, AIFF, or FLAC. 39 """) 40 41 # CEBHACKALERT: make Audio's parameters window_length,overlap be independent of 42 # the sampling rate. 43
44 - def __init__(self,**params):
45 """ 46 Read the audio file into an array. 47 """ 48 self._source = pyaudiolab.sndfile(params.get('filename',self.filename),'read') 49 n_frames = self._source.get_nframes() 50 sig = self._source.read_frames(n_frames,dtype=numpy.float32) 51 spacing = 1.0/self._source.get_samplerate() 52 53 super(Audio,self).__init__(signal=sig,sample_spacing=spacing,**params)
54