[IronPython] Reproducing an C# array of floats

Daniel D. olomen at hotmail.com
Wed Nov 4 21:12:26 CET 2009

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20091104/0ef1ff71/attachment.html>

More information about the Ironpython-users mailing list