[gst-devel] Sync spectrum messages with audio being played?
EmbeddedMicro
justin at embeddedmicro.com
Sat May 2 19:51:43 CEST 2009
I am writing a plug-in for Rhythmbox that creates visualisations for a LED
cube I have. The plug-in is working, however the spectrum messages come in
bursts and are not synced with the music. This is my first time using
python or dealing with gstreamer so I am just starting to understand it.
Here is what I have so far.
import rb
> import gst
> import serial
> import array
>
> class LEDcube(rb.Plugin):
>
> def activate(self, shell):
> self.max = -60
> self.spectrum = gst.element_factory_make("spectrum")
> self.spectrum.set_property('bands',9)
> self.spectrum.set_property('interval',15000000)
> self.spectrum.set_property('threshold',-50)
>
> player = shell.get_player().props.player
> player.add_filter(self.spectrum)
>
> bus = player.props.bus
> if bus is None:
> self.bus_id = player.connect('notify::bus', self.bus_notify)
> else:
> self.bus_id = player.props.bus.connect('message', self.on_message)
> self.ser = serial.Serial('/dev/ttyS0', 115200, timeout=1)
>
> def deactivate(self, shell):
> player = shell.get_player().props.player
>
> player.remove_filter(self.spectrum)
> player.props.bus.disconnect(self.bus_id)
> self.bus_id = 0
>
> def bus_notify(self, obj, pspec):
> obj.disconnect(self.bus_id)
> self.bus_id = obj.props.bus.connect('message', self.on_message)
>
> def on_message(self, bus, message):
> if message.src == self.spectrum and
> message.structure.has_key('magnitude'):
> magnitudes = message.structure['magnitude']
> self.ser.write("\x35")
> for i in range(0, 9):
> data = array.array('B', [51+int(round(magnitudes[i],0))]).tostring()
> self.ser.write(data)
> self.ser.write(data)
> self.ser.write(data)
Is it possible to set it up so on_message() gets called in time with the
music?
Thanks,
Justin Rajewski
--
View this message in context: http://www.nabble.com/Sync-spectrum-messages-with-audio-being-played--tp23348700p23348700.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.
More information about the gstreamer-devel
mailing list