|
From: edu <mog...@gm...> - 2007-07-07 02:27:38
|
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.
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..
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
|