Reproducing an C# array of floats

View: New views
5 Messages — Rating Filter:   Alert me  

Reproducing an C# array of floats

by Daniel D.-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
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))
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 floats

by Dino Viehland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

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.
Sent: Wednesday, November 04, 2009 12:12 PM
To: users@...
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))
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 floats

by Daniel D.-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
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@...
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.
Sent: Wednesday, November 04, 2009 12:12 PM
To: users@...
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))
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.



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 floats

by Dino Viehland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

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@... [mailto:users-bounces@...] On Behalf Of Daniel D.
Sent: Wednesday, November 04, 2009 12:48 PM
To: users@...
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@...
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.
Sent: Wednesday, November 04, 2009 12:12 PM
To: users@...
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))
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.

 


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 floats

by Daniel D.-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

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)


 

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