From: Axel R. <Axe...@ir...> - 2007-07-10 13:53:41
|
On Saturday 07 July 2007, edu wrote: > hi. > for personal use i implemented a wrapper to wrap the python bindings of > Easdif. While doing that I noticed some problems with the SWIG bindings, > which are independent of the SWIG version (I tried ALL of them): > Matrix.GetNbRows and Matrix.GetNbCols result always in segfaults. Hello Eduardo, I am happy to see that you have been making such nice use of the Easdif library. I cannot reproduce the segfaults with that you report with the latest Easdif (version 1.3.1) which you find in cvs and with swig 1.3.31. Both methods work perfectly for me under linux and the sample script test.py that you can find in the swig/python directory. What os are you working with? > Also, in order to read the matrix more efficiently in python, I > implemented small helper functions in sdif_matrix.cpp to read a whole > matrix into a python array.. what would that look like? If it could be of general use I could put it into the official source. > This changes are not reflected in the SWIG bindings: since these > functions are used for interfacing with numpy arrays (c arrays in > python), I access the shared library directly from python and map the > data to the python arrays. > In this way, you can do, in python: > > from sdiflib import * > entity = Entity('my_sdif_file.sdif', selection=':1GB1/1GB1') # > selection is optional > for frame in entity: > for matrix in frame: > print matrix()[0:100] # will print the first 100 rows in all > the matrices > > given that the sdif has matrices of constant size, the reading is > buffered and you can do interpolation without reading everything first > into memory. (not possible with partial tracking, still) > > entity = Entity('my_very_big_spectral_envelope.sdif', > selection=':1GB1/1GB1') > print entity(10.5, 300) > > will print the value of the spectral envelope at time=10.5 secs at > frequency 300Hz. Values are interpolated linearly by default. > > Based on this library, I made a python module to talk to supervp and > pm2. At the moment some features are still not implemented (gabarit > filter, surface filter) but besides that, everything seems to work quite > good. This library works both in OSX and Linux. It also integrates > audiosculpt's kernels with libraries like Loris and aubio. > > you can do things like: > > from audiosculpt import * > sp = SpectralEnvelope(An('source.aiff', ws=4000), order=30) > sp.plot3d() # will plot a 3d image of sp > print sp(10.5, 300) # print the value at time=10.5sec, freq=300Hz > sp *= 0.5 # scale all the values > sp.write('out.sdif') # write the new results > > > even more, you can do: > > sp0 = SpectralEnvelope(An('source.aiff', ws=4000), order=30) > sp1 =SpectralEnvelope(An('source.aiff', ws=4000), order=2000) > interpolation_bpf = bpf.HalfCos((0,0), (10, 1)) > interpolated_envelope = sp0 * interpolation_bpf + sp1 * (1 - > interpolation_bpf) > > out = FilterBreakpnt(An('white_noise.aiff', ws=4000), > interpolated_envelope) # this will call supervp to produce a breakpoint > filter calculated out of the > # interpolation of the two spectral envelopes with the given shape > (halfcos interpolation > # in 10 seconds). This could of course be done > # quite easily with envscal filter, but this is just a very easy > example. Once gabarit > # filter is supported, it will be much more efficient, of course. > > mask = MaskingEffect(An('source.aiff', ws=4000)) > > print mask(1, 300) # print the weight of the spectrum at time=1sec, > freq=300Hz > mask.plot() # plot the results as a surface plot > out = FilterBreakpnt(An('white_noise.aiff', ws=4000), sp * mask) > # will filter the white noise file only at the places where > # the source file has relevant spectral information > # (otherwise weight=0 --> result = 0) > > > if someone is interested, I can post the sources. > > cheers, > > Eduardo Moguillansky > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > sdif-devel mailing list > sdi...@li... > https://lists.sourceforge.net/lists/listinfo/sdif-devel -- Axel Roebel IRCAM Analysis/Synthesis Team Phone: ++33-1-4478 4845 | Fax: ++33-1-4478 1540 |