Re: [Sndobj-devel] PySndObj: Problem with SndObj & time.sleep() -- making a metronome with SndObj
Status: Abandoned
Brought to you by:
veplaini
From: todd i. <tes...@as...> - 2007-01-29 15:12:23
|
Certainly you should not be getting the distorted sounds, but one other possibility to try that might be more solid would be to use SyncGrain to generate a "grain" (the beep) at some rate. i can't test it right now, but i would think that would work and would not rely on the time stuff in python. On Jan 29, 2007, at 3:24 AM, Victor Lazzarini wrote: > Instead of turning the thread on and off, you can try using > SndObj::Disable()/Enable() to > turn the processing of an object off (outputs zero thereafter)/on. > Or you > can use SetAmp(0) on the Oscili object that zeros the amplitude. > > Because there are two threads, timing might be slightly wobbly. If you > need precision you can set a callback that calls either method. > This will > be called from the processing thread, always before processing. The > timing resolution then is however many samples your vector is (you > can bring it down to 1 sample if you need). > > Callbacks for SndThread were introduced in the latest version (better > get the latest CVS) and are documented in the latest reference manual. > There are some examples of its use in the python subdir of the > sources. > > Victor > > At 05:55 29/01/2007, Craig Lewiston wrote: >> 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 >> >> --------------------------------------------------------------------- >> ---- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to >> share your >> opinions on IT & business topics through brief surveys - and earn >> cash >> http://www.techsay.com/default.php? >> page=join.php&p=sourceforge&CID=DEVDEV >> _______________________________________________ >> Sndobj-devel mailing list >> Snd...@li... >> https://lists.sourceforge.net/lists/listinfo/sndobj-devel > > Victor Lazzarini > Music Technology Laboratory > Music Department > National University of Ireland, Maynooth > > > ---------------------------------------------------------------------- > --- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Sndobj-devel mailing list > Snd...@li... > https://lists.sourceforge.net/lists/listinfo/sndobj-devel |