[Sndobj-devel] PySndObj: Problem with SndObj & time.sleep() -- making a metronome with SndObj
Status: Abandoned
Brought to you by:
veplaini
From: Craig L. <lew...@mi...> - 2007-01-29 05:55:10
|
One use of SndObj in my application is to provide the audio "beep" for a metronome thread that executes alongside my main program loop (a Tkinter GUI). I figured the easiest way to go about this would be to stick the following steps inside a loop: 1) turn the sound on, 2) wait for the beep length (in this case 50 ms), 3) turn the sound off, 4) wait the remainder of time until the next beat. The four steps would reside inside a loop that executed for the duration of the song. However, working towards that end, I've found that when i simply attempt to do the following (without putting it in a loop): thread.ProcOn() time.sleep(0.05) thread.ProcOff() time.sleep(0.45) I don't get the desired effect. I want the sound on for 50 ms, and then off for 450 ms. Instead, with the above code, I get 50 ms of the desired sound (a sine wave in this case), followed by 450 ms of a distorted version of the sound. It seems to be a weird interaction between SndThread and time.sleep. When i do this: thread.ProcOn() time.sleep(0.05) thread.ProcOff() or this: thread.ProcOn() time.sleep(0.05) I get the desired result: 50 ms of a sine wave. (In the second case, I really don't understand why it stops WITHOUT the thread.ProcOff() statement, but that's not the issue here) if I do this: thread.ProcOn() I get NO output, which is weird because i would expect it to just turn the sound on and not turn it off until i hard-closed the Python Interpreter. Here's the full code: ------------------------------------ import sndobj import time tab = sndobj.HarmTable(5000,2, 1) osc = sndobj.Oscili(tab, 3000, 16000) outp = sndobj.SndRTIO(1) outp.SetOutput(1, osc) thread = sndobj.SndThread() thread.AddObj(osc) thread.AddObj(outp, sndobj.SNDIO_OUT) thread.ProcOn() time.sleep(0.05) thread.ProcOff() time.sleep(0.45) ------------------------------------ and my system specs: OSX 10.4.8, Powerbook G4, Python 2.4.4 So, I'm sorta at a loss for what to do. I've gone through enough trouble to get SndObj up and running (I was using tkSnack before [http://www.speech.kth.se/snack/]), which gave me problems of its own (intermittent playback quality). I'm trying to figure out if I should stick through with SndObj for realtime audio processing in my application, or look for another module. Also, concerning the metronome problem, I was wondering if maybe the better route to take, instead of creating a loop to start and stop the sound, would be instead to create one metronome audio track that lasts the length of the song, and then just play it at the beginning and stop it at the end. Thoughts? Thanks, Craig |