Please help to translate this short Delphi code 
Author Message
 Please help to translate this short Delphi code

Hello,
           I need some help to implement this delphi code into vbasic.
Specially, I am looking for the vbasic equivalent of this operation:
Temp := Abs(TIntegers(Buff)[I]);

Please see the code below:
======================
Type
      TIntegers = Array of SmallInt;

Procedure TForm1.SoundServerExecute(AContext: TIdContext);

Var BufSize : Integer;
    Buff    : TBytes;

    Function GetEnergyLevel : Integer;

    Var I, Temp : Integer;
        Total, Avg  : Int64;

    Begin
      Total := 0;
      For I := 0 to (BufSize Div 2) do
      Begin
        Temp := Abs(TIntegers(Buff)[I]);
        if Temp > 32767 Then Temp := 32767;
        Total := Total + Temp;
      End;
      Avg := Total Div (BufSize Div 2);
      Result := Avg;
    End;

================
Thanks,
Kathy



Fri, 19 Aug 2011 11:51:30 GMT  
 Please help to translate this short Delphi code
VB6 or one of the .NET versions?


| Hello,
|           I need some help to implement this Delphi code into vbasic.
| Specially, I am looking for the vbasic equivalent of this operation:
| Temp := Abs(TIntegers(Buff)[I]);
|
| Please see the code below:
| ======================
| Type
|      TIntegers = Array of SmallInt;
|
| Procedure TForm1.SoundServerExecute(AContext: TIdContext);
|
| Var BufSize : Integer;
|    Buff    : TBytes;
|
|    Function GetEnergyLevel : Integer;
|
|    Var I, Temp : Integer;
|        Total, Avg  : Int64;
|
|    Begin
|      Total := 0;
|      For I := 0 to (BufSize Div 2) do
|      Begin
|        Temp := Abs(TIntegers(Buff)[I]);
|        if Temp > 32767 Then Temp := 32767;
|        Total := Total + Temp;
|      End;
|      Avg := Total Div (BufSize Div 2);
|      Result := Avg;
|    End;
|
| ================
| Thanks,
| Kathy
|
|



Fri, 19 Aug 2011 13:16:28 GMT  
 Please help to translate this short Delphi code



Quote:
> VB6 or one of the .NET versions?



> | Hello,
> |           I need some help to implement this Delphi code into vbasic.
> | Specially, I am looking for the vbasic equivalent of this operation:
> | Temp := Abs(TIntegers(Buff)[I]);
> |
> | Please see the code below:
> | ======================
> | Type
> |      TIntegers = Array of SmallInt;
> |
> | Procedure TForm1.SoundServerExecute(AContext: TIdContext);
> |
> | Var BufSize : Integer;
> |    Buff    : TBytes;
> |
> |    Function GetEnergyLevel : Integer;
> |
> |    Var I, Temp : Integer;
> |        Total, Avg  : Int64;
> |
> |    Begin
> |      Total := 0;
> |      For I := 0 to (BufSize Div 2) do
> |      Begin
> |        Temp := Abs(TIntegers(Buff)[I]);
> |        if Temp > 32767 Then Temp := 32767;
> |        Total := Total + Temp;
> |      End;
> |      Avg := Total Div (BufSize Div 2);
> |      Result := Avg;
> |    End;
> |
> | ================
> | Thanks,
> | Kathy
> |
> |

Visual Basic 5.
I am not advanced to try dotnet yet.

To add:
I have already accomplished that task almost completely.
I am struggling with:
how to convert(?) array of bytes into array of integers.
or in other words:
the received audio stream is an array of bytes:

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
   Dim b() As Byte
If Winsock1.State = sckConnected Then Winsock1.GetData b, vbArray + vbByte
CopyMemory StempMemB(tempMemLen), b(0), bytesTotal
tempMemLen = tempMemLen + bytesTotal
    If tempMemLen >= 32000 Then             '1 sec
        Call SkypeGetEnergyLevel
        tempMemLen = 0    'stream
    End If
End Sub

Private Sub SkypeGetEnergyLevel()
Dim Temp As Integer
Dim Total As Long
Dim Avg(1 To 4) As Long

    For i = 1 To 32000 Step 2
        Temp = Abs(StempMemB(i))
        If Temp > 32767 Then Temp = 32767
        Total = Total + Temp
    Next
    Avg(1) = Total / 16000
    Debug.Print "Avg(1): " & Avg(1)
End Sub

I am sure I an doing something wrong above, because Avg(1) value changes
very little around 127 value although volume changes drastically.
Where possible is my mistake?
Thank you,
Kathy



Fri, 19 Aug 2011 15:15:20 GMT  
 Please help to translate this short Delphi code

Quote:

> I am struggling with:
> how to convert(?) array of bytes into array of integers.

> Private Sub SkypeGetEnergyLevel()
> Dim Temp As Integer
> Dim Total As Long
> Dim Avg(1 To 4) As Long

>     For i = 1 To 32000 Step 2
>         Temp = Abs(StempMemB(i))
>         If Temp > 32767 Then Temp = 32767
>         Total = Total + Temp
>     Next
>     Avg(1) = Total / 16000
>     Debug.Print "Avg(1): " & Avg(1)
> End Sub

> I am sure I an doing something wrong above, because Avg(1) value
> changes very little around 127 value although volume changes
> drastically. Where possible is my mistake?
> Thank you,
> Kathy

The Delphi code must be treating every pair of bytes as an integer.
Assuming the correct endian-ness, you could pull a trick in VB and
overlay the array, but a more straightforward way would be:

 Dim Temp As Long ' to avoid overflow
 For i = 1 To 32000 Step 2

   Temp = StempMemB(i) + 256& * StempMemB(i + 1)

   If Temp > 32767 Then Temp = 32767

   Total = Total + Temp
 Next
 Avg(1) = Total / 16000

 Depending on the actual byte order, you might have to promote the
other byte of the pair:

   Temp = StempMemB(i + 1) + 256& * StempMemB(i)

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"



Fri, 19 Aug 2011 19:52:19 GMT  
 Please help to translate this short Delphi code
Temp as an VB Integer, can never be >32767. Use a Long to get what you need.

/Henning



Quote:



>> VB6 or one of the .NET versions?



>> | Hello,
>> |           I need some help to implement this Delphi code into vbasic.
>> | Specially, I am looking for the vbasic equivalent of this operation:
>> | Temp := Abs(TIntegers(Buff)[I]);
>> |
>> | Please see the code below:
>> | ======================
>> | Type
>> |      TIntegers = Array of SmallInt;
>> |
>> | Procedure TForm1.SoundServerExecute(AContext: TIdContext);
>> |
>> | Var BufSize : Integer;
>> |    Buff    : TBytes;
>> |
>> |    Function GetEnergyLevel : Integer;
>> |
>> |    Var I, Temp : Integer;
>> |        Total, Avg  : Int64;
>> |
>> |    Begin
>> |      Total := 0;
>> |      For I := 0 to (BufSize Div 2) do
>> |      Begin
>> |        Temp := Abs(TIntegers(Buff)[I]);
>> |        if Temp > 32767 Then Temp := 32767;
>> |        Total := Total + Temp;
>> |      End;
>> |      Avg := Total Div (BufSize Div 2);
>> |      Result := Avg;
>> |    End;
>> |
>> | ================
>> | Thanks,
>> | Kathy
>> |
>> |

> visual basic 5.
> I am not advanced to try dotnet yet.

> To add:
> I have already accomplished that task almost completely.
> I am struggling with:
> how to convert(?) array of bytes into array of integers.
> or in other words:
> the received audio stream is an array of bytes:

> Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
>   Dim b() As Byte
> If Winsock1.State = sckConnected Then Winsock1.GetData b, vbArray + vbByte
> CopyMemory StempMemB(tempMemLen), b(0), bytesTotal
> tempMemLen = tempMemLen + bytesTotal
>    If tempMemLen >= 32000 Then             '1 sec
>        Call SkypeGetEnergyLevel
>        tempMemLen = 0    'stream
>    End If
> End Sub

> Private Sub SkypeGetEnergyLevel()
> Dim Temp As Integer
> Dim Total As Long
> Dim Avg(1 To 4) As Long

>    For i = 1 To 32000 Step 2
>        Temp = Abs(StempMemB(i))
>        If Temp > 32767 Then Temp = 32767
>        Total = Total + Temp
>    Next
>    Avg(1) = Total / 16000
>    Debug.Print "Avg(1): " & Avg(1)
> End Sub

> I am sure I an doing something wrong above, because Avg(1) value changes
> very little around 127 value although volume changes drastically.
> Where possible is my mistake?
> Thank you,
> Kathy



Fri, 19 Aug 2011 21:40:59 GMT  
 Please help to translate this short Delphi code
Thank you very much both, Jim Mack and Henning.
I am wondering, whether the hack provided by Jim is the only solution?
I am looking for the fastest way of calculation to reduce the overhead.
My code has to do a lot of conversions of that kind and the processing time
can become quite a significant factor, I am afraid.
For example I have the following questions:
1.
Is it possible to gather audio stream directly into integer array instead of
byte array?
I've tried that with Winsock but received "mismatched" error for b():
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
   Dim b() As Integer
If Winsock1.State = sckConnected Then Winsock1.GetData b, vbArray +
vbInteger
--------
End Sub
2.
If 1) is impossible, then maybe I can use some operation on the memory to
convert the bytes array into integers array?

I need to find the fastest way to make that calculations.

Thanks again,
Kathy



Fri, 19 Aug 2011 23:47:58 GMT  
 Please help to translate this short Delphi code

Quote:

> Thank you very much both, Jim Mack and Henning.
> I am wondering, whether the hack provided by Jim is the only
> solution? I am looking for the fastest way of calculation to reduce
> the overhead. My code has to do a lot of conversions of that kind
> and the processing time can become quite a significant factor, I am
> afraid. For example I have the following questions:
> 1.
> Is it possible to gather audio stream directly into integer array
> instead of byte array?
> I've tried that with Winsock but received "mismatched" error for
> b(): Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
>    Dim b() As Integer
> If Winsock1.State = sckConnected Then Winsock1.GetData b, vbArray +
> vbInteger
> --------
> End Sub
> 2.
> If 1) is impossible, then maybe I can use some operation on the
> memory to convert the bytes array into integers array?

> I need to find the fastest way to make that calculations.

There are three possible tricks, but all depend on the bytes being in
the correct order.

First, you can copymem one array into another:

Dim Ints(1 to 16000) As Integer
Dim Byts(1 to 32000) As Byte

Read your data into the byte array, then:

    CopyMem Ints(1), Byts(1), 32000

Now Ints() is an array of integers you can directly manipulate. It's
pretty fast.

Second, and much faster, is to "overlay" the byte array with an
integer array. To do this you have to modify the SafeArray structure
of the integer array. Create the arrays as above, but instead of
CopyMem, save off the pvData element of the integer array, then
replace it with the pvData element of the byte array. Run your code,
then replace the integer array's original pvData before it goes out of
scope.

Third is similar, but doesn't create a separate array: alter the type
and number of elements in the byte array's SafeArray structure so that
it has an element size of 2 (not 1), and a size of exactly half what
it originally had. You can safely destroy the modified array without
reverting it.

I don't have exact step-by-step instructions at hand, but if you look
up the SafeArray structure, you'll find examples.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"



Sat, 20 Aug 2011 00:29:07 GMT  
 Please help to translate this short Delphi code


Quote:
> First, you can copymem one array into another:

> Dim Ints(1 to 16000) As Integer
> Dim Byts(1 to 32000) As Byte

> Read your data into the byte array, then:

>    CopyMem Ints(1), Byts(1), 32000

> Now Ints() is an array of integers you can directly manipulate. It's
> pretty fast.

I am trying to do that since yesterday to no avail.
Please see this:
===============
Public SkypetempMemB(640000) As Byte
Public SkypetempMemI(640000) As Integer

CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
CopyMemory SkypetempMemI(tempMemLen), b(0), bytesTotal

For i = 0 To bytesTotal - 1
    Debug.Print i & " > " & SkypetempMemB(i) & vbTab & SkypetempMemI(i)
Next
=================

The printout from dDebug.Print(the end of it):
2681 > 9    0
2682 > 247  0
2683 > 242  0
2684 > 38   0
2685 > 20   0
2686 > 103  0
2687 > 227  0
2688 > 193  0
2689 > 36   0
2690 > 234  0
2691 > 207  0
2692 > 85   0
2693 > 6    0
2694 > 57   0
2695 > 235  0
2696 > 129  0
2697 > 207  0
2698 > 223  0

data read from the integer array is always 0
What am I doing wrong?
Thanks,
Kathy



Sat, 20 Aug 2011 02:52:19 GMT  
 Please help to translate this short Delphi code

Quote:

> "Jim Mack" wrote...
>> First, you can copymem one array into another:

>> Dim Ints(1 to 16000) As Integer
>> Dim Byts(1 to 32000) As Byte

>> Read your data into the byte array, then:

>>    CopyMem Ints(1), Byts(1), 32000

>> Now Ints() is an array of integers you can directly manipulate.
>> It's pretty fast.

> I am trying to do that since yesterday to no avail.
> Please see this:
> ===============
> Public SkypetempMemB(640000) As Byte
> Public SkypetempMemI(640000) As Integer

> CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
> CopyMemory SkypetempMemI(tempMemLen), b(0), bytesTotal

We'd need to see your Declare for CopyMemory to know why things aren't
working out for you.

Try this one (air code):

Private Declare Sub ByteToInt Lib "kernel32" _
    Alias "RtlMoveMemory" _
    (ByRef Target As Integer, ByRef Source As Byte, _
     ByVal ByteCount As Long)

 Call ByteToInt(IntArray(0), ByteArray(0), nBytes)

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"



Sat, 20 Aug 2011 03:16:53 GMT  
 Please help to translate this short Delphi code


Quote:

>> "Jim Mack" wrote...
>>> First, you can copymem one array into another:

>>> Dim Ints(1 to 16000) As Integer
>>> Dim Byts(1 to 32000) As Byte

>>> Read your data into the byte array, then:

>>>    CopyMem Ints(1), Byts(1), 32000

>>> Now Ints() is an array of integers you can directly manipulate.
>>> It's pretty fast.

>> I am trying to do that since yesterday to no avail.
>> Please see this:
>> ===============
>> Public SkypetempMemB(640000) As Byte
>> Public SkypetempMemI(640000) As Integer

>> CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
>> CopyMemory SkypetempMemI(tempMemLen), b(0), bytesTotal

> We'd need to see your Declare for CopyMemory to know why things aren't
> working out for you.

> Try this one (air code):

> Private Declare Sub ByteToInt Lib "kernel32" _
>    Alias "RtlMoveMemory" _
>    (ByRef Target As Integer, ByRef Source As Byte, _
>     ByVal ByteCount As Long)

> Call ByteToInt(IntArray(0), ByteArray(0), nBytes)

> --
>   Jim Mack
>   Twisted tees at http://www.cafepress.com/2050inc
>   "We sew confusion"

Thank you.
So this is the cause of the problem:
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (hpvDest As
Any, hpvSource As Any, ByVal cbCopy As Long)
?

I think I have to declare another function then, because I am using  the
current declaration successfully in many parts of my project.
Kathy



Sat, 20 Aug 2011 05:03:20 GMT  
 Please help to translate this short Delphi code



Quote:



>> First, you can copymem one array into another:

>> Dim Ints(1 to 16000) As Integer
>> Dim Byts(1 to 32000) As Byte

>> Read your data into the byte array, then:

>>    CopyMem Ints(1), Byts(1), 32000

>> Now Ints() is an array of integers you can directly manipulate. It's
>> pretty fast.

> I am trying to do that since yesterday to no avail.
> Please see this:
> ===============
> Public SkypetempMemB(640000) As Byte
> Public SkypetempMemI(640000) As Integer

> CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
> CopyMemory SkypetempMemI(tempMemLen), b(0), bytesTotal

> For i = 0 To bytesTotal - 1
>    Debug.Print i & " > " & SkypetempMemB(i) & vbTab & SkypetempMemI(i)
> Next
> =================

> The printout from dDebug.Print(the end of it):
> 2681 > 9    0
> 2682 > 247  0
> 2683 > 242  0
> 2684 > 38   0
> 2685 > 20   0
> 2686 > 103  0
> 2687 > 227  0
> 2688 > 193  0
> 2689 > 36   0
> 2690 > 234  0
> 2691 > 207  0
> 2692 > 85   0
> 2693 > 6    0
> 2694 > 57   0
> 2695 > 235  0
> 2696 > 129  0
> 2697 > 207  0
> 2698 > 223  0

> data read from the integer array is always 0
> What am I doing wrong?
> Thanks,
> Kathy

Guess you have to pass the Pointers (VarPtr) to the arrays to CopyMem.

/Henning



Sat, 20 Aug 2011 05:42:16 GMT  
 Please help to translate this short Delphi code
Sorry to trouble you but I have exactly the same problem.
Please see below:
==============
Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (hpvDest As
Any, hpvSource As Any, ByVal cbCopy As Long)
Declare Sub ByteToInt Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Target
As Integer, ByRef Source As Byte, ByVal ByteCount As Long)
Public SkypetempMemB(640000) As Byte
Public SkypetempMemI(640000) As Integer

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
   Dim b() As Byte
If Winsock1.State = sckConnected Then Winsock1.GetData b, vbArray + vbByte
CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
ByteToInt SkypetempMemI(tempMemLen), b(0), bytesTotal
For i = 0 To bytesTotal - 1
    Debug.Print i & " > " & SkypetempMemB(i) & vbTab & SkypetempMemI(i)
Next
--------
==================
And the printout is:
2681 > 33   0
2682 > 103  0
2683 > 30   0
2684 > 123  0
2685 > 188  0
2686 > 80   0
2687 > 67   0
2688 > 207  0
2689 > 202  0
2690 > 122  0
2691 > 252  0
2692 > 249  0
2693 > 11   0
2694 > 48   0
2695 > 211  0
2696 > 205  0
2697 > 33   0
2698 > 97   0
2699 > 242  0
2700 > 122  0
2701 > 251  0
2702 > 119  0
2703 > 6    0
2704 > 146  0
2705 > 248  0
2706 > 235  0
2707 > 248  0
2708 > 52   0
2709 > 233  0
2710 > 57   0
2711 > 227  0
2712 > 51   0
2713 > 5    0
2714 > 8    0
2715 > 204  0
2716 > 77   0
2717 > 246  0
2718 > 135  0
2719 > 55   0
2720 > 5    0
2721 > 236  0
2722 > 60   0
2723 > 16   0
2724 > 1    0
2725 > 104  0
2726 > 6    0
2727 > 246  0
2728 > 156  0
2729 > 93   0
2730 > 48   0
2731 > 21   0
2732 > 128  0
2733 > 40   0
2734 > 239  0
2735 > 44   0
2736 > 23   0
2737 > 243  0
2738 > 232  0
2739 > 35   0
2740 > 116  0
2741 > 224  0
2742 > 2    0
2743 > 67   0
2744 > 93   0
2745 > 223  0
2746 > 110  0
2747 > 33   0
2748 > 23   0
2749 > 19   0
2750 > 218  0
2751 > 18   0
2752 > 206  0
2753 > 251  0
2754 > 222  0
2755 > 247  0
2756 > 179  0
2757 > 249  0
2758 > 137  0
2759 > 188  0
2760 > 183  0
2761 > 233  0
2762 > 198  0
2763 > 165  0
2764 > 98   0
2765 > 221  0
2766 > 206  0
2767 > 142  0
2768 > 31   0
2769 > 218  0
2770 > 44   0
2771 > 209  0
2772 > 111  0
2773 > 169  0
2774 > 160  0
2775 > 225  0
2776 > 137  0
2777 > 202  0
2778 > 115  0
2779 > 203  0
2780 > 22   0
2781 > 204  0
2782 > 53   0
2783 > 195  0
2784 > 63   0
2785 > 223  0
2786 > 236  0
2787 > 228  0
2788 > 164  0
2789 > 176  0
2790 > 9    0
2791 > 31   0
2792 > 198  0
2793 > 164  0
2794 > 171  0
2795 > 7    0
2796 > 169  0
2797 > 226  0
2798 > 198  0
2799 > 226  0
2800 > 173  0
2801 > 240  0
2802 > 14   0
2803 > 6    0
2804 > 116  0
2805 > 224  0
2806 > 145  0
2807 > 0    0
2808 > 176  0
2809 > 20   0
2810 > 72   0
2811 > 218  0
2812 > 112  0
2813 > 31   0
2814 > 240  0
2815 > 248  0
2816 > 75   0
2817 > 245  0
2818 > 101  0
2819 > 1    0
2820 > 57   0
2821 > 233  0
2822 > 166  0
2823 > 2    0
2824 > 251  0
2825 > 194  0
2826 > 200  0
2827 > 245  0
2828 > 68   0
2829 > 218  0
2830 > 0    0
2831 > 229  0
2832 > 238  0
2833 > 210  0
2834 > 150  0
2835 > 246  0
2836 > 58   0
2837 > 9    0
2838 > 151  0
2839 > 216  0
2840 > 64   0
2841 > 12   0
2842 > 160  0
2843 > 248  0
2844 > 79   0
2845 > 32   0
2846 > 80   0
2847 > 232  0
2848 > 97   0
2849 > 50   0
2850 > 63   0
2851 > 2    0
2852 > 246  0
2853 > 47   0
2854 > 0    0
2855 > 0    0
2856 > 181  0
2857 > 72   0
2858 > 73   0
2859 > 29   0
2860 > 71   0
2861 > 13   0
2862 > 138  0
2863 > 117  0
2864 > 184  0
2865 > 29   0
2866 > 56   0
2867 > 78   0
2868 > 189  0
2869 > 66   0
2870 > 76   0
2871 > 86   0
2872 > 185  0
2873 > 56   0
2874 > 89   0
2875 > 67   0
2876 > 58   0
2877 > 53   0
2878 > 147  0
2879 > 69   0


Quote:

>> "Jim Mack" wrote...
>>> First, you can copymem one array into another:

>>> Dim Ints(1 to 16000) As Integer
>>> Dim Byts(1 to 32000) As Byte

>>> Read your data into the byte array, then:

>>>    CopyMem Ints(1), Byts(1), 32000

>>> Now Ints() is an array of integers you can directly manipulate.
>>> It's pretty fast.

>> I am trying to do that since yesterday to no avail.
>> Please see this:
>> ===============
>> Public SkypetempMemB(640000) As Byte
>> Public SkypetempMemI(640000) As Integer

>> CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
>> CopyMemory SkypetempMemI(tempMemLen), b(0), bytesTotal

> We'd need to see your Declare for CopyMemory to know why things aren't
> working out for you.

> Try this one (air code):

> Private Declare Sub ByteToInt Lib "kernel32" _
>    Alias "RtlMoveMemory" _
>    (ByRef Target As Integer, ByRef Source As Byte, _
>     ByVal ByteCount As Long)

> Call ByteToInt(IntArray(0), ByteArray(0), nBytes)

> --
>   Jim Mack
>   Twisted tees at http://www.cafepress.com/2050inc
>   "We sew confusion"



Sat, 20 Aug 2011 05:57:00 GMT  
 Please help to translate this short Delphi code
My fault, sorry.
I was using Debug.Print to display values in the immediate window, but
because of it's the small buffer only the end was displayed, and in my case
the end always were zeros.
I stored the data in the file and the result was quite different:!
Thanks again,
Kathy

0 > 187 12219
1 > 47 22664
2 > 136 14478
3 > 88 23849
4 > 142 17196
5 > 56 22457
6 > 41 5186
7 > 93 20231
8 > 44 6425
9 > 67 7764
10 > 185 10728
11 > 87 3831
12 > 66 5705
13 > 20 6940
14 > 7 4129
15 > 79 -4978
16 > 25 13247
17 > 25 -23187
18 > 84 -1165
19 > 30 -16722
20 > 232 -14226
21 > 41 -14863
22 > 247 -7037
23 > 14 -12288
24 > 73 -7193
25 > 22 -11782
26 > 28 -17213
27 > 27 -4878
28 > 33 -21374
29 > 16 -16957
30 > 142 -12358
31 > 236 -13954
32 > 191 -17736
33 > 51 -3084
34 > 109 1030
35 > 165 -16234
36 > 115 9060
37 > 251 3182
38 > 174 5337
39 > 190 18024
40 > 110 20299
41 > 200 19892
42 > 241 20810
43 > 197 6654
44 > 131 15598
45 > 228 -837
46 > 0 -7141
47 > 208 8754
48 > 231 -21024
49 > 227 -2752
50 > 250 -21800
51 > 209 -14538
52 > 195 -13272
53 > 188 -18297
54 > 242 -10975
55 > 236 1443
56 > 130 -16718
57 > 172 2216
58 > 195 -1613
59 > 189 -6737
60 > 186 2726
61 > 207 -5293
62 > 126 7780
63 > 201 -12132
64 > 184 4586
65 > 186 -7267
66 > 244 -7451
67 > 243 2111
68 > 6 4831
69 > 4 913
70 > 150 19985
71 > 192 6971
72 > 100 -1132



Sat, 20 Aug 2011 06:26:56 GMT  
 Please help to translate this short Delphi code
CopyMemory VarPtr(SkypetempMemB(tempMemLen)), VarPtr(b), bytesTotal
CopyMemory VarPtr(SkypetempMemI(tempMemLen/2)), VarPtr(b), bytesTotal
or
CopyMemory VarPtr(SkypetempMemI) + tempMemLen, VarPtr(b), bytesTotal

In the For..Next Loop, the Integer Array will be half the size of the Byte
Array. Number of Int's is half of number of Bytes. The above presuming
values are twobytes per value, and as mentioned the Endianess is correct.

/Henning



Quote:
> Sorry to trouble you but I have exactly the same problem.
> Please see below:
> ==============
> Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (hpvDest
> As Any, hpvSource As Any, ByVal cbCopy As Long)
> Declare Sub ByteToInt Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef
> Target As Integer, ByRef Source As Byte, ByVal ByteCount As Long)
> Public SkypetempMemB(640000) As Byte
> Public SkypetempMemI(640000) As Integer

> Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
>   Dim b() As Byte
> If Winsock1.State = sckConnected Then Winsock1.GetData b, vbArray + vbByte
> CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
> ByteToInt SkypetempMemI(tempMemLen), b(0), bytesTotal
> For i = 0 To bytesTotal - 1
>    Debug.Print i & " > " & SkypetempMemB(i) & vbTab & SkypetempMemI(i)
> Next
> --------
> ==================
> And the printout is:
> 2681 > 33   0
> 2682 > 103  0
> 2683 > 30   0
> 2684 > 123  0
> 2685 > 188  0
> 2686 > 80   0
> 2687 > 67   0
> 2688 > 207  0
> 2689 > 202  0
> 2690 > 122  0
> 2691 > 252  0
> 2692 > 249  0
> 2693 > 11   0
> 2694 > 48   0
> 2695 > 211  0
> 2696 > 205  0
> 2697 > 33   0
> 2698 > 97   0
> 2699 > 242  0
> 2700 > 122  0
> 2701 > 251  0
> 2702 > 119  0
> 2703 > 6    0
> 2704 > 146  0
> 2705 > 248  0
> 2706 > 235  0
> 2707 > 248  0
> 2708 > 52   0
> 2709 > 233  0
> 2710 > 57   0
> 2711 > 227  0
> 2712 > 51   0
> 2713 > 5    0
> 2714 > 8    0
> 2715 > 204  0
> 2716 > 77   0
> 2717 > 246  0
> 2718 > 135  0
> 2719 > 55   0
> 2720 > 5    0
> 2721 > 236  0
> 2722 > 60   0
> 2723 > 16   0
> 2724 > 1    0
> 2725 > 104  0
> 2726 > 6    0
> 2727 > 246  0
> 2728 > 156  0
> 2729 > 93   0
> 2730 > 48   0
> 2731 > 21   0
> 2732 > 128  0
> 2733 > 40   0
> 2734 > 239  0
> 2735 > 44   0
> 2736 > 23   0
> 2737 > 243  0
> 2738 > 232  0
> 2739 > 35   0
> 2740 > 116  0
> 2741 > 224  0
> 2742 > 2    0
> 2743 > 67   0
> 2744 > 93   0
> 2745 > 223  0
> 2746 > 110  0
> 2747 > 33   0
> 2748 > 23   0
> 2749 > 19   0
> 2750 > 218  0
> 2751 > 18   0
> 2752 > 206  0
> 2753 > 251  0
> 2754 > 222  0
> 2755 > 247  0
> 2756 > 179  0
> 2757 > 249  0
> 2758 > 137  0
> 2759 > 188  0
> 2760 > 183  0
> 2761 > 233  0
> 2762 > 198  0
> 2763 > 165  0
> 2764 > 98   0
> 2765 > 221  0
> 2766 > 206  0
> 2767 > 142  0
> 2768 > 31   0
> 2769 > 218  0
> 2770 > 44   0
> 2771 > 209  0
> 2772 > 111  0
> 2773 > 169  0
> 2774 > 160  0
> 2775 > 225  0
> 2776 > 137  0
> 2777 > 202  0
> 2778 > 115  0
> 2779 > 203  0
> 2780 > 22   0
> 2781 > 204  0
> 2782 > 53   0
> 2783 > 195  0
> 2784 > 63   0
> 2785 > 223  0
> 2786 > 236  0
> 2787 > 228  0
> 2788 > 164  0
> 2789 > 176  0
> 2790 > 9    0
> 2791 > 31   0
> 2792 > 198  0
> 2793 > 164  0
> 2794 > 171  0
> 2795 > 7    0
> 2796 > 169  0
> 2797 > 226  0
> 2798 > 198  0
> 2799 > 226  0
> 2800 > 173  0
> 2801 > 240  0
> 2802 > 14   0
> 2803 > 6    0
> 2804 > 116  0
> 2805 > 224  0
> 2806 > 145  0
> 2807 > 0    0
> 2808 > 176  0
> 2809 > 20   0
> 2810 > 72   0
> 2811 > 218  0
> 2812 > 112  0
> 2813 > 31   0
> 2814 > 240  0
> 2815 > 248  0
> 2816 > 75   0
> 2817 > 245  0
> 2818 > 101  0
> 2819 > 1    0
> 2820 > 57   0
> 2821 > 233  0
> 2822 > 166  0
> 2823 > 2    0
> 2824 > 251  0
> 2825 > 194  0
> 2826 > 200  0
> 2827 > 245  0
> 2828 > 68   0
> 2829 > 218  0
> 2830 > 0    0
> 2831 > 229  0
> 2832 > 238  0
> 2833 > 210  0
> 2834 > 150  0
> 2835 > 246  0
> 2836 > 58   0
> 2837 > 9    0
> 2838 > 151  0
> 2839 > 216  0
> 2840 > 64   0
> 2841 > 12   0
> 2842 > 160  0
> 2843 > 248  0
> 2844 > 79   0
> 2845 > 32   0
> 2846 > 80   0
> 2847 > 232  0
> 2848 > 97   0
> 2849 > 50   0
> 2850 > 63   0
> 2851 > 2    0
> 2852 > 246  0
> 2853 > 47   0
> 2854 > 0    0
> 2855 > 0    0
> 2856 > 181  0
> 2857 > 72   0
> 2858 > 73   0
> 2859 > 29   0
> 2860 > 71   0
> 2861 > 13   0
> 2862 > 138  0
> 2863 > 117  0
> 2864 > 184  0
> 2865 > 29   0
> 2866 > 56   0
> 2867 > 78   0
> 2868 > 189  0
> 2869 > 66   0
> 2870 > 76   0
> 2871 > 86   0
> 2872 > 185  0
> 2873 > 56   0
> 2874 > 89   0
> 2875 > 67   0
> 2876 > 58   0
> 2877 > 53   0
> 2878 > 147  0
> 2879 > 69   0




>>> "Jim Mack" wrote...
>>>> First, you can copymem one array into another:

>>>> Dim Ints(1 to 16000) As Integer
>>>> Dim Byts(1 to 32000) As Byte

>>>> Read your data into the byte array, then:

>>>>    CopyMem Ints(1), Byts(1), 32000

>>>> Now Ints() is an array of integers you can directly manipulate.
>>>> It's pretty fast.

>>> I am trying to do that since yesterday to no avail.
>>> Please see this:
>>> ===============
>>> Public SkypetempMemB(640000) As Byte
>>> Public SkypetempMemI(640000) As Integer

>>> CopyMemory SkypetempMemB(tempMemLen), b(0), bytesTotal
>>> CopyMemory SkypetempMemI(tempMemLen), b(0), bytesTotal

>> We'd need to see your Declare for CopyMemory to know why things aren't
>> working out for you.

>> Try this one (air code):

>> Private Declare Sub ByteToInt Lib "kernel32" _
>>    Alias "RtlMoveMemory" _
>>    (ByRef Target As Integer, ByRef Source As Byte, _
>>     ByVal ByteCount As Long)

>> Call ByteToInt(IntArray(0), ByteArray(0), nBytes)

>> --
>>   Jim Mack
>>   Twisted tees at http://www.cafepress.com/2050inc
>>   "We sew confusion"



Sat, 20 Aug 2011 06:28:38 GMT  
 Please help to translate this short Delphi code

Quote:

> Guess you have to pass the Pointers (VarPtr) to the arrays to
> CopyMem.

Not if you use the Declare shown (As Any). In VB6 parameters are
assumed ByRef, so passing BytArray(0) in such a place would pass a
pointer to the beginning of the data.

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"



Sat, 20 Aug 2011 06:36:21 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Please help translate this code.

2. Please help Translate This C Code

3. Short message short answer Please Help

4. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

5. Translating a short file name to full name

6. Please help in translate from C# to VB

7. Please help me with Increment Operator Translate...

8. Please help translate C# to VB.NET

9. Please help translate C# to VB.NET

10. Please help to translate Javascript to VBscript

11. Help translating C++ Code

12. Need more help translating C++ code with BitBlt!

 

 
Powered by phpBB® Forum Software