Re: [Sndobj-devel] Triggered Wav File playback in Python
Status: Abandoned
Brought to you by:
veplaini
From: Craig L. <lew...@mi...> - 2007-02-06 20:52:29
|
you're right, there's no need to inherit and create a new class. the way i arrived at that solution was that i was trying to access the protected variable m_vecpos from the SndIO class (was trying to access this in an instance of SndWave). that's why i tried inheriting, because m_vecpos is protected. however, even when i inherited, i wasn't able to access m_vecpos, which i now believe is due to the SWIG interface between python and the cpp code. i had missed that SndWave is derived from SndFIO which is derived from SndIO (was only looking at the documentation for SndWave, and not at the library class tree near the beginning of the documentation). Since SetPos() is defined in SndFIO, i didn't know that it was a method available to SndWave. all that said, is there a method for accessing protected variables such as m_vecpos from Python? When i run dir() on a SndWave object, i see the following methods that might be able to accomplish this: __getattr__ __getattribute__ __setattr__ can you suggest where i can find out how to use these? anyway, thanks for the continued help, Craig On 2/6/07, Victor Lazzarini <Vic...@nu...> wrote: > 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 > > |