|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Please help to translate this short Delphi codeI 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 VB6 or one of the .NET versions?
Show quoteHide quote "Kathy" <Kathy@kathy> wrote in message news:%23MFrvoumJHA.5124@TK2MSFTNGP03.phx.gbl... | 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 | |
Show quote
Hide quote
"C Kevin Provance" <BillMRapedMySh***@.netblows.ms> wrote in message visual basic 5.news:%23k2dLYvmJHA.4028@TK2MSFTNGP03.phx.gbl... > VB6 or one of the .NET versions? > > > "Kathy" <Kathy@kathy> wrote in message > news:%23MFrvoumJHA.5124@TK2MSFTNGP03.phx.gbl... > | 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 > | > | > 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 Kathy wrote:
Show quoteHide quote > I am struggling with: The Delphi code must be treating every pair of bytes as an integer.> 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 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) Temp as an VB Integer, can never be >32767. Use a Long to get what you need.
/Henning Show quoteHide quote "Kathy" <Kathy@kathy> skrev i meddelandet news:uVVYpawmJHA.5412@TK2MSFTNGP04.phx.gbl... > > "C Kevin Provance" <BillMRapedMySh***@.netblows.ms> wrote in message > news:%23k2dLYvmJHA.4028@TK2MSFTNGP03.phx.gbl... >> VB6 or one of the .NET versions? >> >> >> "Kathy" <Kathy@kathy> wrote in message >> news:%23MFrvoumJHA.5124@TK2MSFTNGP03.phx.gbl... >> | 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 > 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 Kathy wrote:
Show quoteHide quote > Thank you very much both, Jim Mack and Henning. There are three possible tricks, but all depend on the bytes being in> 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. 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.
Show quote
Hide quote
"Jim Mack" <jmack@mdxi.nospam.com> wrote in message I am trying to do that since yesterday to no avail.news:OvGcDQ1mJHA.1168@TK2MSFTNGP05.phx.gbl... > 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. > 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 Kathy wrote:
Show quoteHide quote > "Jim Mack" wrote... We'd need to see your Declare for CopyMemory to know why things aren't>> 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 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)
Show quote
Hide quote
"Jim Mack" <jmack@mdxi.nospam.com> wrote in message So this is the cause of the problem:news:eLhMzt2mJHA.5124@TK2MSFTNGP03.phx.gbl... > Kathy wrote: >> "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. 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 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 Show quoteHide quote "Jim Mack" <jmack@mdxi.nospam.com> wrote in message news:eLhMzt2mJHA.5124@TK2MSFTNGP03.phx.gbl... > Kathy wrote: >> "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" > > > 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 Show quoteHide quote "Kathy" <Kathy@kathy> skrev i meddelandet news:OxHzUH4mJHA.5124@TK2MSFTNGP03.phx.gbl... > 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" <jmack@mdxi.nospam.com> wrote in message > news:eLhMzt2mJHA.5124@TK2MSFTNGP03.phx.gbl... >> Kathy wrote: >>> "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" >> >> >> > > Forget the VarPtr thing, parameters are declared as ByRef......
/Henning Show quoteHide quote "Henning" <computer_h***@coldmail.com> skrev i meddelandet news:49ac5ec4$0$16216$57c3e1d3@news3.bahnhof.se... > 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 > > > "Kathy" <Kathy@kathy> skrev i meddelandet > news:OxHzUH4mJHA.5124@TK2MSFTNGP03.phx.gbl... >> 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" <jmack@mdxi.nospam.com> wrote in message >> news:eLhMzt2mJHA.5124@TK2MSFTNGP03.phx.gbl... >>> Kathy wrote: >>>> "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" >>> >>> >>> >> >> > > 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 That makes sense. 47 = &H2F, 187 = &HBB, &H2FBB = 12219. ;)
/Henning Show quoteHide quote "Kathy" <Kathy@kathy> skrev i meddelandet news:%23HSSDY4mJHA.4448@TK2MSFTNGP05.phx.gbl... > 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 >
Show quote
Hide quote
"Kathy" <Kathy@kathy> skrev i meddelandet Guess you have to pass the Pointers (VarPtr) to the arrays to CopyMem.news:udSAIg2mJHA.4372@TK2MSFTNGP02.phx.gbl... > > "Jim Mack" <jmack@mdxi.nospam.com> wrote in message > news:OvGcDQ1mJHA.1168@TK2MSFTNGP05.phx.gbl... >> 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 > /Henning Henning wrote:>
> Guess you have to pass the Pointers (VarPtr) to the arrays to Not if you use the Declare shown (As Any). In VB6 parameters are> CopyMem. assumed ByRef, so passing BytArray(0) in such a place would pass a pointer to the beginning of the data.
Show quote
Hide quote
"Kathy" <Kathy@kathy> wrote in message I think you need to check the Skype documentation and find out exactly what news:uVVYpawmJHA.5412@TK2MSFTNGP04.phx.gbl... > 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 the bytes you are receiving are supposed to represent. For example, it could be an 8 bit mono waveform where the 8 bit value represents positive and negative values in the range 127 to -128 or it could (more probably) be a 16 bit mono waveform (with every pair of bytes of the received data representing one two byte signed Integer) where each signed Integer represents a voltage in the range 32767 to - 32768. If these values were temporarily held in standard 16 bit signed Integers (such as VB uses) then the voltage of zero would be represented by a Integer value of zero and the voltage levels (positive and negative) could be read directly but if they were instead held in 16 bit unsigned Integers (which perhaps Delphi can use if it wishes) then the voltage of zero would be represented by an unsigned Integer value of 32767. > I am sure I an doing something wrong above, because That result makes sense actually because from your code you appear to be > Avg(1) value changes very little around 127 value > although volume changes drastically. reading alternate bytes of a Byte array containing the waveform data. If such data represents 16 bit signed voltage values (each pair of bytes holding one value) and if you happen to be reading the lo byte of each pair then you are effectively reading almost random byte data between zero and 255 (because it respresents just tiny voltage fluctuations in the waveform), the average of which is likely to be about 127 regardless of the overall "loudness" of the waveform, which is itself controlled almost entirely by the data in the hi byte, which you are not reading. What result do you get if you change the above code so that it instead reads the hi bytes by changing For i = 1 To 32000 Step 2 to For i = 0 To 32000 Step 2. Do you get a different result then? > Temp = Abs(StempMemB(i)) By the way, the Temp = Abs(etc) in the above VB code is entirely redundant > If Temp > 32767 Then Temp = 32767 in VB because you are reading data (presumably) from an array of Bytes, each of which holds a positive value in the range 0 to 255 (Bytes are unsigned in VB). Assitionally the line If Temp > 3267 Then (etc) is also entirely redundant when reading Byte values in VB because a value read from a Byte cannot possibly exceed 255, let alone exceed 32767. Therefore I presume that those lines are remnants of the original Delphi code which you have left in. I don't actually use Delphi so I don't know what the Delphi code you are converting does but perhaps it is reading 16 bit waveform data (which of course represents a signed value) and it is reading it from a Delphi array of two byte signed Integers (or perhaps deriving those two byte signed Integers from a block of byte data), in which case each signed Integer will return a value in the range -32767 to 32768, representing positive and begative voltage values of a waveform. The Delphi code is then taking the absolute value of that, which will return all positive values in the range 0 to 32768. This is the effect of full wave rectification of the voltage waveform (similar to what would be achieved electronically by passing the waveform through a full wave bridge rectifier) and by adding those values and taking the average of the result you will get the average level of the overall waveform, which does not actually tell you the volume but it does roughly approximate it. The code seems to be additionally capping values above 32767 (there should be in fact only one of these, the value 32768) which seems a bit pedantic (if what I have guessed about what it is doing is correct) but it does remove a very slight and almost negligible bias that might otherwise result. All of this, and more, is very easy to do in VB but first I think you need to establish exactly what tpye of waveform data Skype is sending you, and whether the Integer data (if that is what it is) is in hi-lo or in the lo-hi format that VB uses. I suspect the former because it appears from your example code that you are reading alternate bytes from byte 1 of a Byte array that presumably starts at byte zero and they appear to be the lo order bytes, although I don't know if your code is using Option Base at all so I'm not sure going soley by your declaration. When you have such information then post again. Mike
close excel from VB6
Pset and SetPixel Bug How to get special Appdata folder What am I doing wrong How difficult is to add my menu to Windows Explorer? Use Proc with Static Variables Multiple Times OT MS Community Visibility Vista behaves differently to WordBasic command even though same version of Word! Unbelieveable code, it produces one result in VB6 run and another if compiled in a exe file ???? Wha Legacy vs Opp |
|||||||||||||||||||||||