From 0866b10a9ea7bff7ecaaa7d99334859f382cad3f Mon Sep 17 00:00:00 2001 From: Joshua Minor Date: Sat, 22 Dec 2007 00:44:03 +0000 Subject: Removed lots of dead code. --- diff --git a/Speak.activity/activity.py b/Speak.activity/activity.py index 250c9a7..629219d 100755 --- a/Speak.activity/activity.py +++ b/Speak.activity/activity.py @@ -45,7 +45,6 @@ class SpeakActivity(activity.Activity): self.connect( "notify::active", self._activeCb ) self.audio = audio.AudioGrab(datastore, self._jobject) self.mouth = mouth.Mouth(self.audio) - self.audio.set_wave_copy(self.mouth) box = gtk.VBox(homogeneous=False) box.pack_start(eyeBox, expand=False) diff --git a/Speak.activity/audio.py b/Speak.activity/audio.py index 278f9a6..484285d 100644 --- a/Speak.activity/audio.py +++ b/Speak.activity/audio.py @@ -4,141 +4,60 @@ import gst import pygtk import gtk, gobject import signal, os - import time - import dbus - import audioop - from struct import * - - class AudioGrab(gobject.GObject): __gsignals__ = { - 'new-buffer': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN, gobject.TYPE_PYOBJECT]) + 'new-buffer': (gobject.SIGNAL_RUN_FIRST, None, [gobject.TYPE_PYOBJECT]) } def __init__(self, datastore, _jobject): gobject.GObject.__init__(self) - - self.wave_copy= None - self.electrical_ui_copy= None - - self.datastore = datastore - self._jobject = _jobject - self.pipeline = None - self.fakesink = None - - self.logging_status = False - self.count1 = 48000/9600 - self.final_count = 0 - - self.count_temp = 0 - self.entry_count = 0 - - self.draw_graph_status = False - self.f = None - - self.temp_buffer = [] - self.snapshot_buffer = [] def playfile(self, filename): + # build a pipeline that reads the given file + # and sends it to both the real audio output + # and a fake one that we use to draw from p = 'filesrc name=file-source ! decodebin ! tee name=tee tee.! audioconvert ! alsasink tee.! queue ! audioconvert name=conv' self.pipeline = gst.parse_launch(p) - self.fakesink = gst.element_factory_make("fakesink", "fakesink") - self.fakesink.connect("handoff",self.on_buffer) - self.fakesink.set_property("signal-handoffs",True) - self.pipeline.add(self.fakesink) + # make a fakesink to capture audio + fakesink = gst.element_factory_make("fakesink", "fakesink") + fakesink.connect("handoff",self.on_buffer) + fakesink.set_property("signal-handoffs",True) + self.pipeline.add(fakesink) + # attach it to the pipeline conv = self.pipeline.get_by_name("conv") - gst.element_link_many(conv, self.fakesink) + gst.element_link_many(conv, fakesink) + # set the source file self.pipeline.get_by_name("file-source").set_property('location', filename) - self.pipeline.set_state(gst.STATE_PLAYING) - def disable_handoff_signal(self): - self.fakesink.set_property("signal-handoffs",False) - - def enable_handoff_signal(self): - self.fakesink.set_property("signal-handoffs",True) - + # play + self.restart_sound_device() + + # how do we detect when the sample has finished playing? + # we should stop the sound device and stop emitting buffers + # to save on CPU and battery usage when there is no audio playing + def on_quit(self): - self.fakesink.set_property("signal-handoffs",False) self.pipeline.set_state(gst.STATE_NULL) def _new_buffer(self, buf): - # on the main thread - - if(self.logging_status == True): - - if(self.final_count==777700): #777700 is a special value for indicating 'Snapshot' - #buffer_temp = unpack( str(int(len(self.temp_buffer))/2)+'h' , self.temp_buffer) - for val in self.snapshot_buffer: - self.f.write(str(val)+'\n') #Write the latest buffer - self.f.write("stop") - self.f.close() - self.datastore.write(self._jobject) - self.logging_status=False - - else: - self.count_temp+=1 - - if(self.count_temp==self.final_count): - self.count_temp=0 - write_buffer = unpack( str(int(len(buf))/2)+'h' , buf) - self.f.write(str(write_buffer[int(len(buf)/4.0)])+'\n') #Writing the middle value of the buffer available at each logging time - self.entry_count+=1 - - - self.emit("new-buffer", buf, self.draw_graph_status, self.f) + # pass captured audio to anyone who is interested via the main thread + self.emit("new-buffer", buf) return False - - def on_buffer(self,element,buffer,pad): - # could be in a different thread - #print len(str(buffer)) - gobject.timeout_add(30, self._new_buffer, str(buffer)) - #gobject.idle_add(self._new_buffer, str(buffer)) + def on_buffer(self,element,buffer,pad): + # we got a new buffer of data, ask for another + gobject.timeout_add(100, self._new_buffer, str(buffer)) return True - - def set_logging_status(self, status, f, multiplier): - self.logging_status = status - - if(status==True): - self.f = f - self.final_count = (multiplier*(48000/960)*2) - self.count_temp=0 - self.entry_count=0 - - if(status==False): - self.f.write("stop") - self.f.close() - self.datastore.write(self._jobject) - self.logging_status=False - - - def start_drawing_graph(self, status, f): - self.draw_graph_status = status - if(self.draw_graph_status==True): - self.f = f - return - - def snapshot(self): - self.snapshot_buffer = self.wave_copy.buffers - return - - def set_wave_copy(self, wave): - self.wave_copy = wave - return - - def set_reference_electrical(self,electrical_ui): - self.electrical_ui_copy=electrical_ui - def stop_sound_device(self): self.pipeline.set_state(gst.STATE_NULL) diff --git a/Speak.activity/mouth.py b/Speak.activity/mouth.py index 94d156d..bca2813 100644 --- a/Speak.activity/mouth.py +++ b/Speak.activity/mouth.py @@ -34,8 +34,6 @@ class Mouth(gtk.DrawingArea): self.num_of_points = 105 self.details_show = False - self.logging_status=False - self.f=None self.stop=False @@ -48,14 +46,12 @@ class Mouth(gtk.DrawingArea): self.scaleY = "10" - def _new_buffer(self, obj, buf, status, f): + def _new_buffer(self, obj, buf): self.str_buffer = buf self.integer_buffer = list(unpack( str(int(len(buf))/2)+'h' , buf)) if(len(self.main_buffers)>6301): del self.main_buffers[0:(len(self.main_buffers)-6301)] self.main_buffers += self.integer_buffer - self.logging_status=status - self.f=f return True diff --git a/dist/speak.xo b/dist/speak.xo index 65b0dfd..2e83056 100644 --- a/dist/speak.xo +++ b/dist/speak.xo Binary files differ -- cgit v0.9.1