[Clam-devel] pyclam: CLAM python bindings (some preliminary results)

David García Garzón dgarcia at iua.upf.edu
Wed Jul 30 12:43:29 PDT 2008


Wow, all that working in python seems amazing to me. Great work, Hernan!
Could you sent a tarball/patch? i want to play with it. :-)

David.


El Wednesday 30 July 2008 21:36:50 Hernán Ordiales va escriure:
> Hi all,
>
> Recently I been playing a little with Boost.Python and CLAM library
> and I'd like to show you the results:
>
> By now I was able to parse with sucess only a subset of clam classes
> and the problems that arose with basic ones were temporary solved with
> a couple of workarounds (especially because dynamic types), but I
> believe those issues could be solved in a better way with more work on
> it.
>
> If you agree and like the idea, let me know and i'll upload my work to
> the repo along with some instrucctions to get it running.
>
> This is how the python code looks like at the moment:
> (fft_example.py)
>
> import clam
> from math import sin
>
> samples = 1024
> sampleRate = 8000.0
> sineFreq = 400.0
>
> myaudio = clam.Audio()
> myaudio.SetSize( samples );
> myaudio.SetSampleRate( sampleRate );
>
> vector = myaudio.GetBuffer()
> for i in range(samples):
> 	vector.set( i, 0.625+0.5*sin(2.0*sineFreq*400.0*((float(i))/sampleRate)) )
> 	#print vector[i]
>
> myspectrum = clam.Spectrum()
> specFlags = clam.SpecTypeFlags()
>
> specFlags.SetFlag( specFlags.GetFlagPosition("Polar"), 1 )
> specFlags.SetFlag( specFlags.GetFlagPosition("Complex"), 1 )
> specFlags.SetFlag( specFlags.GetFlagPosition("MagPhase"), 1 )
> specFlags.SetFlag( specFlags.GetFlagPosition("Polar"), 1 )
> specFlags.SetFlag( specFlags.GetFlagPosition("MagPhaseBPF"), 1 )
>
> myspectrum.SetType( specFlags )
> myspectrum.SetSize( samples/2+1 )
>
> fconfig = clam.FFTConfig()
> fconfig.SetAudioSize( samples )
>
> myfft = clam.FFT_ooura()
> myfft.Configure( fconfig.getReal() )
> myfft.Start()
>
> print "Running object "
> myfft.Do( myaudio.getBase(), myspectrum.getBase() )
>
> print "Storing spectrum"
> clam.XmlStorage.Dump( clam.toComponent(myspectrum), "FFTResult",
> "pyFFT_example.xml")
> ------
>
> Other example:
> (playfile.py)
>
> import clam
> import time
>
> filename = "./test30seg.mp3"
>
> network = clam.Network()
>
> reader = network.AddProcessing( "MonoAudioFileReader" )
> config = clam.MonoAudioFileReaderConfig()
> config.SetSourceFile( filename )
> if not network.ConfigureProcessing(reader, config): print "Could not
> open the file"
>
> sink = network.AddProcessing( "AudioSink" )
>
> network.ConnectPorts( reader+".Samples Read", sink+".AudioIn" )
>
> portaudio_player = clam.PANetworkPlayer()
> network.SetPlayer( portaudio_player );
>
> network.Start()
> time.sleep( clam.MonoAudioFileReader( network.GetProcessing(reader)
> ).GetLength() )
> network.Stop()
> ------
>
> The current available "namespace" of clam bindings:
>
> clam.Audio                      clam.MonoAudioFileReader       
> clam.__file__ clam.Component                 
> clam.MonoAudioFileReaderConfig
> clam.__getattribute__
> clam.ConnectControls            clam.Network                   
> clam.__hash__ clam.ConnectPorts               clam.NetworkPlayer           
>   clam.__init__ clam.ConnectTypedControls       clam.PANetworkPlayer       
>     clam.__name__ clam.DataArray                  clam.Processing          
>       clam.__new__ clam.EFFTType                   clam.ProcessingConfig   
>        clam.__reduce__ clam.Enum                       clam.ProcessingData
> clam.__reduce_ex__
> clam.Err                        clam.SendFloatToInControl      
> clam.__repr__ clam.ErrNotFound                clam.SendFloatToOutControl   
>   clam.__setattr__ clam.FFT                        clam.SpecTypeFlags      
>        clam.__str__ clam.FFTConfig                  clam.Spectrum          
>         clam.eFFT_IUA clam.FFT_base                   clam.Storage         
>           clam.eFFT_NREC clam.FFT_ooura                  clam.XmlStorage   
>              clam.eNone clam.FlagsBase                  clam.__class__     
>             clam.eRFFTW clam.Flags_less__4u__grate_     clam.__delattr__   
>             clam.so clam.GetFloatFromInControl      clam.__dict__          
>         clam.toComponent clam.IllegalValue               clam.__doc__
>
> Let me know.
>
> Cheers.






More information about the clam-devel mailing list