Hello
I have a program that records audio from firewire device (FA-66) with Jack connection. The interface is created with pygtk and the recording with py-jack (http://sourceforge.net/projects/py-jack/). The recording is done in a different thread because the GUI must be used at the same time for viewing results from the audio.
The problem is that when I start the recording thread, the GUI becomes very slow to respond. I have gtk.gdk function start_threads() at the beginning of the main thread. If I've got it right, I don't need threads_enter() and threads_leave(), because the recording doesn't affect the GUI. Please correct if I'm wrong.
The function jack.process() records audio from three microphones. If I replace it, for example, with time.sleep(2), everything works ok.
What is the best way to create threading in this case? Why does the jack.process freeze the GUI? Does it take all the cpu time or something? Samples of my code below:
soundrecorder.py:
...
def start(self):
Thread(target=self._start).start()
def _start(self):
while self.eventhandler.record.isSet():
data = self._jackRecord(self.sample_length)
self.datahandler.queue.put(data)
def _jackRecord(self, length):
capture = Numeric.zeros((self.inputs, int(self.sample_rate * length)), 'f')
output = Numeric.zeros((self.inputs, self.buffer_size), 'f')
i = 0
while i < capture.shape[1] - self.buffer_size:
try:
jack.process(output, capture[:,i:i+self.buffer_size])
i += self.buffer_size
except:
pass
return capture
eventhandler.py: recordStart() and recordStop() are simply callback functions that are called when start and stop buttons are pressed.
...
def recordStart(self, widget, data=None):
if not self.record.isSet():
self.record.set()
self.soundrecorder = SoundRecorder(self, self.datahandler)
self.soundrecorder.connect()
self.soundrecorder.start()
def recordStop(self, widget, data=None):
if self.record.isSet():
self.record.clear()
del(self.soundrecorder)