Exemplo n.º 1
0
    def __init__(self, *args):

        dbus.service.Object.__init__(self, *args)
        # State Variables
        self.playing = False
        self.audioChan = 0x20;
        self.selectedAudioChan = self.audioChan
        self.subChan = 0;  #most likely will refere to a tetrode sub-channel
        self.selectedSubChan = self.subChan    

        self.eio = NetEventIO("10.0.0.2")
        
        # AudioControl Event Constants setup on 10/13/08
        self.AUDIO_EVENT_CMD = 0x12
        self.ENABLE_AUDIO_EVENTS = 1
        self.DISABLE_AUDIO_EVENTS = 0
        self.AUDIO_REQUEST = 0
        self.AUDIO_UPDATE = 1

        #Create GST elements - pipeline will not be created
        gobject.type_register(SomaAudioEventFilter)
        self.eventSource = gst.element_factory_make('somaeventsource', "SomaEventSource")
        self.audioEventFilter = SomaAudioEventFilter()
        self.AUDIO_SINK = "pulsesink"
        self.audioSink = gst.element_factory_make(self.AUDIO_SINK)
        self.audioConverter = gst.element_factory_make("audioconvert")
        self.audioResampler= gst.element_factory_make("audioresample")
        self.queue = gst.element_factory_make("queue")
        self.pipeline = None
Exemplo n.º 2
0
    def initialize_pipeline(self):
        gobject.type_register(SomaAudioEventFilter)

        self.eventSource = gst.element_factory_make('somaeventsource', "SomaEventSource")
        self.somaAudioEventFilter = SomaAudioEventFilter()
        self.update_source()
        self.alsaSink = gst.element_factory_make("osssink")

        self.pipeline = gst.Pipeline()
        self.pipeline.add(self.eventSource, self.somaAudioEventFilter)
        self.ac = gst.element_factory_make("audioconvert")
        self.ars = gst.element_factory_make("audioresample")
        self.queue = gst.element_factory_make("queue")
        self.pipeline.add(self.queue, self.ac, self.ars)
        self.pipeline.add(self.alsaSink)
        
        gst.element_link_many(self.eventSource, self.somaAudioEventFilter,self.queue, self.ac, self.ars, self.alsaSink)
Exemplo n.º 3
0
    for e in erx:
        print e

eio.stop()
        


import pygtk, pygst
pygtk.require("2.0")
pygst.require("0.10")

import gtk, gtk.glade, gst, gobject
from somaEventFilter import SomaAudioEventFilter

eventSource = gst.element_factory_make('somaeventsource', "SomaEventSource")
somaAudioEventFilter = SomaAudioEventFilter()

audioSrcChan = 0x20
somaAudioEventFilter.set_audio_src(audioSrcChan)

#self.update_source()
alsaSink = gst.element_factory_make("osssink")

pipeline = gst.Pipeline()
pipeline.add(eventSource, somaAudioEventFilter)
ac = gst.element_factory_make("audioconvert")
ars = gst.element_factory_make("audioresample")
queue = gst.element_factory_make("queue")
pipeline.add(queue, ac, ars)
pipeline.add(alsaSink)
        
Exemplo n.º 4
0
class AudioMonitorGui(dbus.service.Object):
    def myInit(self): #used so I don't have to overload the dbus.service.object contsructor

        gladefile = "audioMonitor.glade"
        windowname = "main_window"
        abt_dlg_name = "about_dialog"
        self.wTree = gtk.glade.XML(gladefile,windowname)
        self.aTree = gtk.glade.XML(gladefile,abt_dlg_name)
        self.window = self.wTree.get_widget(windowname)
        self.about_dlg = self.aTree.get_widget(abt_dlg_name)
#        self.wTree.get_widget()
        self.window.show()
        self.playing = False
        self.audioSrcChan = 0x20;
        self.tetrodeChan = 0;        
        self.changes_made_while_paused = False

        combo = self.wTree.get_widget("source_combo")
        combo.set_active(0)        

        dic = { "on_play_pause_button_clicked"  : self.play_pause_clicked,
                "on_source_combo_changed"       : self.source_combo_action,
                "on_ch0_radio_pressed"          : self.ch0_radio_pressed,
                "on_ch1_radio_pressed"          : self.ch1_radio_pressed,
                "on_ch2_radio_pressed"          : self.ch2_radio_pressed,
                "on_ch3_radio_pressed"          : self.ch3_radio_pressed,
                "on_main_window_destroy"        : self.quit, 
                "on_quit_menu_activate"         : self.quit,
                "on_about_menu_activate"        : self.display_about,
                "on_ch0_radio_group_changed"    : self.radio_group_change
               }
    
        self.wTree.signal_autoconnect(dic)
        self.initialize_pipeline()                      

    def initialize_pipeline(self):
        gobject.type_register(SomaAudioEventFilter)

        self.eventSource = gst.element_factory_make('somaeventsource', "SomaEventSource")
        self.somaAudioEventFilter = SomaAudioEventFilter()
        self.update_source()
        self.alsaSink = gst.element_factory_make("osssink")

        self.pipeline = gst.Pipeline()
        self.pipeline.add(self.eventSource, self.somaAudioEventFilter)
        self.ac = gst.element_factory_make("audioconvert")
        self.ars = gst.element_factory_make("audioresample")
        self.queue = gst.element_factory_make("queue")
        self.pipeline.add(self.queue, self.ac, self.ars)
        self.pipeline.add(self.alsaSink)
        
        gst.element_link_many(self.eventSource, self.somaAudioEventFilter,self.queue, self.ac, self.ars, self.alsaSink)

    def restart_pipeline(self):
        print "Changing pipeline"
        self.pipeline_pause()
        print "pushing new src to SomaAudioEventFilter"
        self.update_source()
        self.pipeline_start()

    def set_source(self, src):
        if (self.audioSrcChan == src):
            print "set_source called but same source given"
            return

        self.audioSrcChan = src
        self.wTree.get_widget('source_combo').set_active(self.audioSrcChan)
        print "New source selected:", self.audioSrcChan
        if self.playing==True:
            self.restart_pipeline()        
        
        else:
            self.changes_made_while_paused = True

    def update_source(self):
        print "Changing caps, setting event source to:", self.audioSrcChan
        self.audioSrcChan = 0x20
        self.somaAudioEventFilter.set_audio_src(self.audioSrcChan)       

    def pipeline_start(self):
        print "Starting pipeline, setting state to gst.STATE_PLAYING"
        self.pipeline.set_state(gst.STATE_PLAYING)

    def pipeline_pause(self):
        print "Pausing Pipeline, setting state to gst.STATE_NULL"
        self.pipeline.set_state(gst.STATE_NULL)

    def check_for_changes(self):
        if self.changes_made_while_paused == True:
            print "Changes made while paused, updating src"
            self.update_source()
    
    def set_play(self):
        self.wTree.get_widget('play_pause_button').set_label("gtk-media-pause")
        self.check_for_changes()
        self.pipeline_start()
        self.playing = True

    def set_pause(self):
        self.wTree.get_widget('play_pause_button').set_label("gtk-media-play")
        self.pipeline_pause()
        self.playing = False

# ---------- DBus Methods
    @dbus.service.method("soma.audio.AudioMonitor")
    def start_audio_monitor(self):
        print "DBus call to start audio monitor"
        self.set_play()        
        
    @dbus.service.method("soma.audio.AudioMonitor")
    def pause_audio_monitor(self):
        print "DBus call to pause audio monitor"
        self.set_pause()        

    @dbus.service.method("soma.audio.AudioMonitor")
    def set_audio_src(self, src):
        self.set_source(src)

#    @dbus.service.method("com.Soma.AudioMonitor")
#    def set_tetrode_channel(self):
#        print "Not yet implemented"

# ---------- GTK+  Callbacks below this point

    def source_combo_action(self, widget):
        newSrc = widget.get_active()
        self.set_source(newSrc)

    def quit_menu_selected(self, widget):
        print "Quit application selected"
    def about_menu_selected(self, widget):
        print "About selected"

    def radio_group_change(self, widget):
        print "CHANGE"

    def ch0_radio_pressed(self, widget):
        print "Ch0 radio button pressed"
        self.tetrodeChan=0

    def ch1_radio_pressed(self, widget):
        print "Ch1 radio button pressed"
        self.tetrodeChan=1

    def ch2_radio_pressed(self, widget):
        print "Ch2 radio button pressed"
        self.tetrodeChan=2

    def ch3_radio_pressed(self, widget):
        print "Ch3 radio button pressed"
        self.tetrodeChan=3

    def play_pause_clicked(self, widget):
        #if current state is paused, then button is clicked to play, once clicked 
        #the playbin starts and the button becomes a  pause buttom
        print "Play pause button pressed, setting button icon:", 

        if self.playing==False: #Not currently playing, set to play, then change widget
            print "pause"
            self.set_play()

        elif self.playing==True: #Currently playing set to pause, then change widget
            print "play"
            self.set_pause()

    def display_about(self, widget):
        resp = self.about_dlg.run()
        if  resp == gtk.RESPONSE_CANCEL:
            self.about_dlg.hide()
        print resp

    def quit(self, widget):
        print "Main window destroy called by:", widget.get_name()
        gtk.main_quit()
Exemplo n.º 5
0
class AudioMonitorCore(dbus.service.Object):
    def __init__(self, *args):

        dbus.service.Object.__init__(self, *args)
        # State Variables
        self.playing = False
        self.audioChan = 0x20;
        self.selectedAudioChan = self.audioChan
        self.subChan = 0;  #most likely will refere to a tetrode sub-channel
        self.selectedSubChan = self.subChan    

        self.eio = NetEventIO("10.0.0.2")
        
        # AudioControl Event Constants setup on 10/13/08
        self.AUDIO_EVENT_CMD = 0x12
        self.ENABLE_AUDIO_EVENTS = 1
        self.DISABLE_AUDIO_EVENTS = 0
        self.AUDIO_REQUEST = 0
        self.AUDIO_UPDATE = 1

        #Create GST elements - pipeline will not be created
        gobject.type_register(SomaAudioEventFilter)
        self.eventSource = gst.element_factory_make('somaeventsource', "SomaEventSource")
        self.audioEventFilter = SomaAudioEventFilter()
        self.AUDIO_SINK = "pulsesink"
        self.audioSink = gst.element_factory_make(self.AUDIO_SINK)
        self.audioConverter = gst.element_factory_make("audioconvert")
        self.audioResampler= gst.element_factory_make("audioresample")
        self.queue = gst.element_factory_make("queue")
        self.pipeline = None
        
    def setChannel(self, src):
        print "setting Channel to:", src
        self.selectedAudioChan = src
    
    def getChannel(self):
        return self.audioChan

    def setSubChannel(self, chan):
        print "stting SubChannel to:", chan
        self.selectedSubChan = chan

    def getSubChannel(self):
        return self.subChan

    def startPlaying(self):
        if self.pipeline == None:
            self.__createNewPipeline()
            print "Create Pipeline" 

        print "Play Pipeline"
        self.pipeline.set_state(gst.STATE_PLAYING)

    def stopPlaying(self):
        print "Destroy Pipeline"
    
        if self.pipeline != None:
            self.pipeline.set_state(gst.STATE_NULL)
    
        self.pipeline = None

# ----- Private Methods, Pipeline control, Event Transmission, and looping 
    def __createNewPipeline(self):

        self.pipeline = gst.Pipeline()
        self.audioEventFilter.set_audio_src(self.audioChan)
        self.pipeline.add(self.eventSource, self.audioEventFilter)
        self.pipeline.add(self.queue, self.audioConverter, self.audioResampler)
        self.pipeline.add(self.audioSink)
        
        gst.element_link_many(self.eventSource, self.audioEventFilter,self.queue, self.audioConverter, self.audioResampler, self.audioSink)
    def __loop(self):

        if self.audioChan != self.selectedAudioChan:
            changeSource()

        if self.subChan != self.selectedSubChan:
            changeSource()

        self.processEvents(self.eio.getEvents(), False)
        
    def changeSource(self):

        self.stopPlaying()
        
        self.disableCurrentSource()
        self.enableDesiredSource()
        
        if self.playing==True:
            self.startPlaying()

    def disableCurrentSource(self):
        e = self.disableEvent()

        self.eio.addRxMask(self.AUDIO_EVENT_CMD, self.audioChan) 

        ea = eaddr.TXDest()
        ea[self.audioChan] = 1
        self.eio.sendEvent(e, ea) # Send the disable Event
        self.processEvents(self.eio.getEvents(), True) # Act when the disable Event is echoed back
        ea[self.audioChan] = 0
        self.playing = False

    def enableDesiredSource(self):
        self.eio.addRxMask(self.AUDIO_EVENT_CMD, self.selectedAudioChan, True) 

        e = self.enableEvent()
        ea[self.selectedAudioChan] = 0        
        self.eio.sendEvent(e, ea) # Send the enable event
        self.processEvents(self.eio.getEvents(), True) # Act when the enable Event is echoed back
    
    def processEvents(self, events, active):
        for e in events:
            src = e.src
            if unpack('>H', e.data[0])[0] == 1: #Reporting a Change
                if unpack('>H', e.data[1])[0] == 0: #Device has been disabled
                    if src==self.audioChan:
                        self.stopPlaying()
                        if active==False: # if the source wasn't actively changed re-enable it
                            self.enableDesiredSource()
                        
                if unpack('>H', e.data[1])[0] == 1: #Device has been enabled
                    if src==self.selectedAudioChan:
                        self.audioChan = self.selectedAudioChan #selected chan is playing make

    def disableEvent(self):
        e = Event()
        e.cmd = self.AUDIO_EVENT_CMD
        e.src = eaddr.NETWORK
        e.data[0] = pack('>H', 0) #Requesting Change
        e.data[1] = pack('>H', 0) #Set Channel to Off
        return e

    def enableEvent(self):
        e = Event()
        e.cmd = self.AUDIO_EVENT_CMD
        e.src = eaddr.NETWORK
        e.data[0] = pack('>H', 0) #Requesting Change
        e.data[1] = pack('>H', 1) #Set Channel to On
        e.data[2] = pack('>H', self.selectedSubChan)
        e.data[3] = pack('>H', 32000)
        return e

               

# ---------- DBus Methods
    @dbus.service.method("soma.audio.AudioMonitor")
    def start_playing(self):
        print "DBus call to start audio monitor"
        self.startPlaying()        
        
    @dbus.service.method("soma.audio.AudioMonitor")
    def stop_playing(self):
        print "DBus call to pause audio monitor"
        self.stopPlaying()        

    @dbus.service.method("soma.audio.AudioMonitor", in_signature='i')
    def set_audio_channel(self, src):
        print src
        self.setChannel(src)

    @dbus.service.method("soma.audio.AudioMonitor", out_signature='i')
    def get_audio_channel(self):
        return self.getChannel()

    @dbus.service.method("soma.audio.AudioMonitor", in_signature='i')
    def set_sub_channel(self, src):
        self.setSubChannel(src)

    @dbus.service.method("soma.audio.AudioMonitor", out_signature='i')
    def get_sub_channel(self):
        return self.getSubChannel()
  
    @dbus.service.method("soma.audio.AudioMonitor", out_signature='b')
    def get_playing_state(self):
        return self.playing