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

2008-07-30 Thread Hernán Ordiales
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.MonoAudioFileReaderclam.__file__
clam.Component  clam.MonoAudioFileReaderConfig
clam.__getattribute__
clam.ConnectControlsclam.Networkclam.__hash__
clam.ConnectPorts   clam.NetworkPlayer  clam.__init__
clam.ConnectTypedControls   clam.PANetworkPlayerclam.__name__
clam.DataArray  clam.Processing clam.__new__
clam.EFFTType   clam.ProcessingConfig   clam.__reduce__
clam.Enum   clam.ProcessingData
clam.__reduce_ex__
clam.Errclam.SendFloatToInControl   clam.__repr__
clam.ErrNotFoundclam.SendFloatToOutControl  clam.__setattr__
clam.FFTclam.SpecTypeFlags  clam.__str__
clam.FFTConfig  clam.Spectrum   clam.eFFT_IUA
clam.FFT_base   clam.Storageclam.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.
-- 
Hernán
http://h.ordia.com.ar
GnuPG: 0xEE8A3FE9

___
Clam-devel mailing list
Clam-devel@llistes.projectes.lafarga.org
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel


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

2008-07-30 Thread David García Garzón
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.ConnectControlsclam.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.Errclam.SendFloatToInControl  
 clam.__repr__ clam.ErrNotFoundclam.SendFloatToOutControl   
   clam.__setattr__ clam.FFTclam.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.



___
Clam-devel mailing list
Clam-devel@llistes.projectes.lafarga.org
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel


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

2008-07-30 Thread David García Garzón
6mb is to much load i would prefer the files to compile it + instructions. I 
can wait.

El Wednesday 30 July 2008 21:53:02 Hernán Ordiales va escriure:
 On Wed, Jul 30, 2008 at 4:43 PM, David García Garzón

 [EMAIL PROTECTED] wrote:
  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. :-)

 I'll send you the compiled .so (about 6mb) to test it just put it in
 the same dir of the python script (or where you run the python as
 interpreter or ipython). Then I'll prepare some instructions in order
 to allow you compile it by your own (beside boost.python other tools
 are needed like py++ and gccxml) along with the tarball of the
 project.



___
Clam-devel mailing list
Clam-devel@llistes.projectes.lafarga.org
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel


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

2008-07-30 Thread Hernán Ordiales
On Wed, Jul 30, 2008 at 4:58 PM, David García Garzón
[EMAIL PROTECTED] wrote:
 6mb is to much load i would prefer the files to compile it + instructions. I
 can wait.

ok

-- 
Hernán
http://h.ordia.com.ar
GnuPG: 0xEE8A3FE9

___
Clam-devel mailing list
Clam-devel@llistes.projectes.lafarga.org
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel


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

2008-07-30 Thread Pau Arumí

 Recently I been playing a little with Boost.Python and CLAM library
 and I'd like to show you the results:

Super! this is something wished for long time!

Now, is anybody else to pull a rabbit out the hat? 

;-)


___
Clam-devel mailing list
Clam-devel@llistes.projectes.lafarga.org
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel


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

2008-07-30 Thread Hernán Ordiales
Hi again, I prepared a tarball[1], see the README file for
instructions. Most problems and issues are commented and explained
inside the code (don't worry, the project are a few files)

Some notes:
* As said is a subset of classes, i was increasing the code base step
by step and i think i can continue in the same way.
* I had to do a simple wrap to some classes since dynamic types
brought me problems with the parse and bindings (like audio or
spectrum)
* It's a pity i couldn't get it working the original Array class
because the way is implemented (with pointers and by hand memory
allocation) since std::vectors bindings to numpy vectors works nearly
from scratch. I managed to get working a wrap with the [] operator,
but no supports assigment at the moment (the workaround is the set
method).
* I was able to parse SpecTypeFlags and Flags classes but couldn't get
working a binding to a std::bitset in python. The workaround is use
specFlags.SetFlag( specFlags.GetFlagPosition(Polar), 1 ) instead of
specFlags.bPolar=1
* Other things i can't remember at the moment :-D, just check the project files!

Of course, there are a lot of things to improve, is just a preliminary
approach with the mind in have a couple of examples working, not more.

[1] http://audiores.uint8.com.ar/files/code/python/pyclam.tar.gz
[2] http://audiores.uint8.com.ar/files/code/python/clam.so made with
the r11758 of the clam library.

Cheers

On Wed, Jul 30, 2008 at 4:43 PM, David García Garzón
[EMAIL PROTECTED] wrote:
 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.ConnectControlsclam.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.Errclam.SendFloatToInControl
 clam.__repr__ clam.ErrNotFoundclam.SendFloatToOutControl
   clam.__setattr__ clam.FFTclam.SpecTypeFlags
clam.__str__ clam.FFTConfig  clam.Spectrum