|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Reproducing an C# array of floatsSorry for the silly question. I'm quite new to ironpython and I've been trying to solve this issue for the last 3 hours. I'm not able to reproduce this code in IronPython. float[] sample = new float[8192/sizeof(float)] I've tried the following but nothing seems to work in my specific case: System.Array.CreateInstance(float, (8192/4)) clr.Reference[System.Array[float]](8192/4) System.Array[float]([(8192/4)]) I'm trying to use the SlimDX to capture the microphone input, and pass it to NumPy to do same FFT stuff. The original C# code is here: http://crsouza.blogspot.com/2009/08/capturing-sound-from-microphone-using.html And here my modified version import clr clr.AddReference('SlimDX') from SlimDX import * from System import * captureDevice = DirectSound.DirectSoundCapture() waveFormat = Multimedia.WaveFormat() waveFormat.FormatTag = Multimedia.WaveFormatTag.IeeeFloat # For Int16, change to Pcm waveFormat.BitsPerSample = 32 # Floats are 32 bits waveFormat.BlockAlignment = (waveFormat.BitsPerSample/8) waveFormat.Channels = 1 waveFormat.SamplesPerSecond = 44100 waveFormat.AverageBytesPerSecond = waveFormat.SamplesPerSecond*waveFormat.BlockAlignment*waveFormat.Channels bufferDescription = DirectSound.CaptureBufferDescription() bufferDescription.BufferBytes = 8192 bufferDescription.Format = waveFormat bufferDescription.WaveMapped = False buffer = DirectSound.CaptureBuffer(captureDevice,bufferDescription) buffer.Start(True) #float[] sample = new float[8192/sizeof(float)]; #sample = Array.CreateInstance(float, (8192/4)) #sample = clr.Reference[Array[float]](8192/4) sample = Array[float]([(8192/4)]) while (True): #print sample print buffer.Read(sample, 0, True); .... which is generating the following error C:\Documents and Settings\Administrator\My Documents>ipy sound_capture_test.py Traceback (most recent call last): File "sound_capture_test.py", line 34, in sound_capture_test.py TypeError: Read() takes at least 2147483647 arguments (3 given) Any help will be very appreciated. Thanks, Daniel Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you. _______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
|
|
Re: Reproducing an C# array of floatsfloat in Python is actually double in C#. You probably want: from System import Single System.Array.CreateInstance(Single, …) And so on. From: users-bounces@...
[mailto:users-bounces@...] On Behalf Of Daniel D. Hi all, Windows
Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail
you. _______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
|
|
Re: Reproducing an C# array of floatsNow I'm using System.Single instead float but the error persists. For some reason the Read (ref. http://is.gd/4Ngjt) method of SlimDX.DirectSound.CaptureBuffer isn't accepting the array reference properly. Maybe I should try the Microsoft.DirextX.DirectSound lib, but it's been a little bit difficult to find good references about IronPython+DirectSound (probably by own fault). From: dinov@... To: users@... Date: Wed, 4 Nov 2009 20:20:35 +0000 Subject: Re: [IronPython] Reproducing an C# array of floats float in Python is actually double in C#. You probably want:
from System import Single
System.Array.CreateInstance(Single, …)
And so on.
From: users-bounces@...
[mailto:users-bounces@...] On Behalf Of Daniel D.
Hi all, Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you. Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. _______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
|
|
Re: Reproducing an C# array of floatsAhh, read is a generic method and you’re getting type inference
from C# but not IronPython. IronPython 2.6 includes type inference on generic
methods so this might just work there, but otherwise I think you can do: print
buffer.Read[Single](sample, 0, True) The
square brackets are how we specifiy generic type parameters. From:
users-bounces@... [mailto:users-bounces@...] On
Behalf Of Daniel D. Hi Dino, thanks for the quick reply. From: dinov@... float in Python is actually double in C#. You probably
want: from System import Single System.Array.CreateInstance(Single, …) And so on. From:
users-bounces@... [mailto:users-bounces@...] On
Behalf Of Daniel D. Hi all, Windows
Live: Friends
get your Flickr, Yelp, and Digg updates when they e-mail you. Windows
Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. _______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
|
|
Re: Reproducing an C# array of floatsAhh, read is a generic method and you’re getting type inference from C# but not IronPython. IronPython 2.6 includes type inference on generic methods so this might just work there, but otherwise I think you can do:
print buffer.Read[Single](sample, 0, True)
worked perfectly! thank you so much dino. Windows Live: Keep your friends up to date with what you do online. _______________________________________________ Users mailing list Users@... http://lists.ironpython.com/listinfo.cgi/users-ironpython.com |
| Free embeddable forum powered by Nabble | Forum Help |