Changeset 1f8e522
- Timestamp:
- Oct 21, 2009, 3:16:02 PM (15 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 09b1777
- Parents:
- 40acfbc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
interfaces/python/aubioinput.py
r40acfbc r1f8e522 58 58 gobject.type_register(AubioSink) 59 59 60 class aubioinput: 61 def __init__(self, location, process = None, hopsize = 512, 60 class aubioinput(gst.Bin): 61 62 ret = 0 63 64 def __init__(self, uri, process = None, hopsize = 512, 62 65 caps = None): 63 from os.path import isfile 64 if not isfile(location): 65 raise ValueError, "location should be a file" 66 src = gst.element_factory_make('filesrc') 67 src.set_property('location', location) 68 dec = gst.element_factory_make('decodebin') 69 dec.connect('new-decoded-pad', self.on_new_decoded_pad) 66 if uri.startswith('/'): 67 from urllib import quote 68 uri = 'file://'+quote(uri) 69 src = gst.element_factory_make('uridecodebin') 70 src.set_property('uri', uri) 71 src.connect('pad-added', self.source_pad_added_cb) 70 72 conv = gst.element_factory_make('audioconvert') 73 self.conv = conv 71 74 rsmpl = gst.element_factory_make('audioresample') 72 75 capsfilter = gst.element_factory_make('capsfilter') … … 80 83 self.bus = self.pipeline.get_bus() 81 84 self.bus.add_signal_watch() 82 self.bus.connect('message ::eos', self.on_eos)85 self.bus.connect('message', self.on_eos) 83 86 84 87 self.apad = conv.get_pad('sink') 85 88 86 self.pipeline.add(src, dec,conv, rsmpl, capsfilter, sink)89 self.pipeline.add(src, conv, rsmpl, capsfilter, sink) 87 90 88 src.link(dec)89 91 gst.element_link_many(conv, rsmpl, capsfilter, sink) 90 92 91 93 self.mainloop = gobject.MainLoop() 92 94 self.pipeline.set_state(gst.STATE_PLAYING) 95 96 def run(self): 93 97 self.mainloop.run() 98 return self.ret 94 99 95 def on_new_decoded_pad(self, element, pad, last): 96 caps = pad.get_caps() 97 name = caps[0].get_name() 98 #print 'on_new_decoded_pad:', name 100 def source_pad_added_cb(self, src, pad): 101 name = pad.get_caps()[0].get_name() 99 102 if name == 'audio/x-raw-float' or name == 'audio/x-raw-int': 100 if not self.apad.is_linked(): # Only link once 101 pad.link(self.apad) 103 pad.link(self.conv.get_pad("sink")) 104 105 def source_pad_removed_cb(self, src, pad): 106 pad.unlink(self.conv.get_pad("sink")) 102 107 103 108 def on_eos(self, bus, msg): 104 self.bus.remove_signal_watch() 105 self.pipeline.set_state(gst.STATE_PAUSED) 106 self.mainloop.quit() 109 if msg.type == gst.MESSAGE_EOS: 110 self.bus.remove_signal_watch() 111 self.pipeline.set_state(gst.STATE_PAUSED) 112 self.mainloop.quit() 113 elif msg.type == gst.MESSAGE_ERROR: 114 print "ERROR", msg.parse_error() 115 self.bus.remove_signal_watch() 116 self.pipeline.set_state(gst.STATE_PAUSED) 117 self.mainloop.quit() 118 self.ret = 1 # set return value to 1 in case of error 107 119 108 120 if __name__ == '__main__': … … 112 124 sys.exit(1) 113 125 for filename in sys.argv[1:]: 114 peak = [0. , 0.]126 peak = [0.] # use a mutable 115 127 def process(buf, hop): 116 128 peak[0] = max( peak[0], abs(buf.max()) ) 117 peak[1] = min( peak[1], abs(buf.min()))118 aubioinput(filename, process = process, hopsize = 512)119 print "Finished reading %s, peak value is %f" % (filename, min(peak))129 a = aubioinput(filename, process = process, hopsize = 512) 130 if a.run() == 0: # only display the results if no 131 print "Finished reading %s, peak value is %f" % (filename, max(peak))
Note: See TracChangeset
for help on using the changeset viewer.