Re: [Sndobj-devel] Triggered Wav File playback in Python
Status: Abandoned
Brought to you by:
veplaini
From: Victor L. <Vic...@nu...> - 2007-02-06 10:21:41
|
Looks good. But couldn't you just call sndobj.SndWave.SetPos(0) directly? Inheriting is useful, though. all the best Victor At 08:03 06/02/2007, Craig Lewiston wrote: >I was able to figure out how to reset the vector position for the >SndWave() Class. Basically, you just inherit the class into a new >class, and create a method to set the vector position: > >class N_SndWave(sndobj.SndWave): > def resetpos(self): > self.SetPos(0) > >of course, you could also create another method to set the vector >position to whatever point you want: > >class N_SndWave(sndobj.SndWave): > def resetpos(self): > self.SetPos(0) > def setpos(self, offset): > self.SetPos(offset) > > >so, in order play a wav file, then reset and play it again, you would >do the following: >------ >class N_SndWave(sndobj.SndWave): > def resetpos(self): > self.SetPos(0) > >wavfile = N_SndWave('C261.wav', 3) >wavsoundL = sndobj.SndIn(wavfile,1) >wavsoundR = sndobj.SndIn(wavfile,2) >outp = sndobj.SndRTIO(2, sndobj.SND_OUTPUT) >outp.SetOutput(2, wavsoundR) >outp.SetOutput(1, wavsoundL) > >N1 = sndobj.SndThread() >N1.AddObj(wavfile,sndobj.SNDIO_IN) >N1.AddObj(wavsoundR) >N1.AddObj(wavsoundL) >N1.AddObj(outp, sndobj.SNDIO_OUT) > >N1.ProcOn() >time.sleep(1) >wavfile.resetpos() >time.sleep(1) >N1.ProcOff() >------- >by blocks, the above code: >1) Defines new class inherited from SndWave, with method for resetting >vector position >2) Sets up standard SndIn->SndObj->SndIO chain, in this case using 2 >channels (L&R) >3) Setup SndThread object and add components from 2) >4) Turns SndThread on, plays for 1 second, resets vector to beginning, >plays for 1 second, and then stops processing. > >This seems to do the trick, and the playback is very clean. > >-Craig > > > >On 2/5/07, Craig Lewiston <lew...@mi...> wrote: > > I tried #1 & #3 extensively, as well as tinkering with SndRead() > > quite a bit. I'm starting to think that in order to accomplish what i > > want, I need to be able to reset SndWave() to start reading again from > > the beginning of the file. From the documentation for Class SndIO, it > > appears that the protected variable m_vecpos holds the value of the > > current "place reader" in the wav file. Is there any way to access > > this to reset it? > > > > Better yet, is there a way to copy the wav sample into memory and have > > it triggered? > > > > -Craig > > > > > > > > On 2/5/07, Victor Lazzarini <vic...@nu...> wrote: > > > Off the top of my head: > > > > > > 1. Using Enable() and Disable() on the SndIn object to > > > switch it on an off. You might get clicks. > > > > > > 2. Using an envelope (eg. Interp + Ring) and > > > trigger the envelope (SetCurve()) on/off. > > > Use Ring to multiply the envelope signal by the > > > SndIn signal. > > > > > > 3. If you delete the Wave reader object from > > > the thread it will also stop reading the file > > > (but SndIn will also need to be disabled) > > > > > > 4. Have a look at the SndRead class. Another > > > alternative is to load the file on a table and > > > read it with an oscillator or with Lookup/i > > > > > > You're right in that ProcOn() and ProcOff() should > > > perhaps just be used at the start/end of synthesis. > > > > > > Victor > > > > > > > > > > > > > > Anyone have advice on the best route to creating triggered > > > > file playback? I'd like to have my program be able to > > > > start the playback of a wav file when a flag is set, and > > > > then cease playback of that file once the flag is reset. > > > > i want this to happen in a thread, though, because there > > > > will be other processing (and sounds) taking place (such > > > > as a metronome) while the file is playing back. also, the > > > > length of playback will vary depending on when the flag is > > > > reset (which is controlled by user input) > > > > > > > > i'm using SndWave, and patching both channels into SndIn > > > > objects. everything is then added to a SndThread: > > > > ---------------------- > > > > wavfile = sndobj.SndWave('C261.wav', 3, 2,16) > > > > wavsoundR = sndobj.SndIn(wavfile,1) > > > > wavsoundL = sndobj.SndIn(wavfile,2) > > > > outp = sndobj.SndRTIO(2, sndobj.SND_OUTPUT) > > > > outp.SetOutput(2, wavsoundR) > > > > outp.SetOutput(1, wavsoundL) > > > > > > > > IT = sndobj.SndThread() > > > > IT.AddObj(wavfile,sndobj.SNDIO_IN) > > > > IT.AddObj(wavsoundR) > > > > IT.AddObj(wavsoundL) > > > > IT.AddObj(outp, sndobj.SNDIO_OUT) > > > > > > > > IT.ProcOn() > > > > time.sleep(5) > > > > IT.ProcOff() > > > > ----------------------------------- > > > > > > > > I thought about just turning the thread on and off, but > > > > when the thread is turned on again after being turned off, > > > > it just resumes processing where it left off. is there a > > > > way i can get it to resume from the beginnig of the wav > > > > file? > > > > > > > > > > > > thanks, > > > > craig > > > > > > > > ---------------------------------------------------------- > > > > --------------- Using Tomcat but need to do more? Need to > > > > support web services, security? Get stuff done quickly > > > > with pre-integrated technology to make your job easier. > > > > Download IBM WebSphere Application Server v.1.0.1 based on > > > > Apache Geronimo > > > > > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > > _______________________________________________ > > > > Sndobj-devel mailing list > > > > Snd...@li... > > > > https://lists.sourceforge.net/lists/listinfo/sndobj-devel > > > > > > >------------------------------------------------------------------------- >Using Tomcat but need to do more? Need to support web services, security? >Get stuff done quickly with pre-integrated technology to make your job easier. >Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >_______________________________________________ >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 |