[IronPython] Reproducing an C# array of floats

Dino Viehland dinov at microsoft.com
Wed Nov 4 21:58:43 CET 2009

Ahh, 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 at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Daniel D.
Sent: Wednesday, November 04, 2009 12:48 PM
To: users at lists.ironpython.com
Subject: Re: [IronPython] Reproducing an C# array of floats

Hi Dino, thanks for the quick reply.

Now 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 at microsoft.com
To: users at lists.ironpython.com
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 at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Daniel D.
Sent: Wednesday, November 04, 2009 12:12 PM
To: users at lists.ironpython.com
Subject: [IronPython] Reproducing an C# array of floats

Hi all,

Sorry 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))

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

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)

#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.


Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you.<http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010>

Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail(r).<http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20091104/674772a1/attachment.html>

More information about the Ironpython-users mailing list