"Stephen" <sv******@hotmail.com> wrote in message
news:a9**************************@posting.google.c om...
Hi
I am trying to duplicate the functionality of a vb function in a c#
function, but I am having no luck. I have never worked with vb, so it
is all new to me. My main problem seems to be duplicating the FileGet
call.
Thanks heaps for any help you can give me on this problem
Stephen
FileOpen(WaveFile, WaveFileName, OpenMode.Binary)
ReDim Y(NumSamples - 1, NumChannels - 1)
If BitsPerSample = 8 Then
Dim ybyte(NumChannels - 1, NumSamples - 1) As Byte
FileGet(WaveFile, ybyte) ' read data in one go
For i = 0 To NumSamples - 1
For c = 0 To NumChannels - 1
Y(i, c) = (ybyte(c, i) - 128) / 128# '8 Bits/sample is unsigned
Next
Next
End If
This code is takes a NxM byte array and transposes into a MxN double array,
and applies an expression to each byte.
The expression
Y(i, c) = (ybyte(c, i) - 128) / 128# '8 Bits/sample is unsigned
performs a linear transform of the value from the interval [0,255] to the
interval [-1,1].
So something like:
double[] Y;
using (FileStream f = new FileStream(WaveFileName))
{
Y = new double[NumSamples * NumChannels ];
byte[] ybyte = new byte[NumChannels *NumSamples ];
f.Read(ybyte);
for (int i=0;i<NumSamples;i++)
for (int c=0;c<NumChannels;c++)
{
Y[i*NumSamples+c] = (ybyte(c*NumChannels+i)-128d)/128d;
}
}
David