Converting vb code to C#

S

Stephen

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
 
D

David Browne

Stephen said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

converting vb to c# 2
Converting VB code to C# 2
VB to C# 2
Convert VB to C# (Redim array question) 3
Converting VB to C# 4
Help converting Vb.Net to C# 7
convert this vb to C# 2
Converting C# to VB 4

Top