Author Topic: vb custom stream question  (Read 2526 times)

RevG

  • Posts: 454
vb custom stream question
« on: 8 May '03 - 20:53 »
I promised to upload my code for handling winamp vis, and dsp plugins. It has taken me a bit longer because I am creating activex controls so that vb and delphi users can benefit from this as well. As soon as I solve this last problem I will upload the activex controls with source and examples of how to use them.

I have both activex controls done (winamp dsp, and winamp vis). I am just having some trouble with the vb examples I am creating to show how to use the activex controls.

Here is the C++ code that Ian provided me to handle the problem of winamp dsp plugins returning too little data to fill the buffer or too much data to fit in the buffer. This code worked great in c++ for the dsp plugins! Thanks Ian!

When I translated this code into vb the sound is a bit messed up like it doesn't have enough samples or skips and stuff a little bit, but it almost works so I must have made just a small error somewhere in the vb code. I am hoping someone can notice my problem in my vb code by comparing it to the c++ code which works perfectly.

Here is the c++ code which works great.

Code: [Select]

#define decblock 10000 // bytes to decode at a time
char excess[decblock*2]; // excess buffer
int exlen=0;

DWORD CALLBACK MyStreamProc(HSTREAM handle,char *buffer,DWORD length,DWORD user)
{
   char decbuf[decblock*2]; // decoding buffer - winamp DSP returns at most double the data?
   int c=length;
   if (exlen) { // excess left from last time
         int a=min(c,exlen);
         memcpy(buffer,excess,a);
         exlen-=a;
         if (exlen) memmove(excess,excess+a,exlen); // some excess remaining
         buffer+=a; // advance buffer
         c-=a;
   }
   while (c) {
         int a=BASS_ChannelGetData(decodehandle, decbuf, decblock);
         if (a==-1) break; // end of data (you may want to continue processing for effect tail)
         a=4*ModifySamplesProc(g_currentModule,decbuf,a/4,16,2,44100);
         if (a>c) { // some excess data, keep it for next time
               memcpy(buffer,decbuf,c);
               exlen=a-c;
               memcpy(excess,decbuf+c,exlen);
               c=0; // all done
         } else {
               memcpy(buffer,decbuf,a);
               buffer+=a; // advance buffer
               c-=a;
         }
   }
   return length-c;
}




Here is the vb code which almost works, but seems to be missing some samples, because the sound skips and stuff a little bit.

Code: [Select]

Public Const decblock = 4608
Public excess(decblock * 2) As Byte
Public exlen As Long 'this is initalized to 0 in my form_load event
Public nBufferPos As Long

Function STREAMPROC(ByVal handle As Long, ByVal buffer As Long, ByVal Length As Long, ByVal user As Long) As Long
   
   nBufferPos = 0
   
   Dim decbuff() As Byte
   Dim tempbuffer() As Byte
   ReDim tempbuffer(Length) As Byte
   Dim c As Long
   Dim a As Long
   
   ReDim decbuff(decblock * 2) As Byte
   c = Length
   
   If exlen Then
      a = 0
      If c < exlen Then
          a = c
      Else
          a = exlen
      End If
   Else
      a = exlen
      Call CopyMemory(tempbuffer(nBufferPos), excess(0), a)
      exlen = exlen - a
      If exlen Then
          Call CopyMemory(excess(0), excess(a), exlen)
      End If
          nBufferPos = nBufferPos + a
          c = c - a
  End If
 
  Do While (c)
      a = BASS_ChannelGetData(m_hStream, decbuff(0), decblock)
      If a < 0 Then
          Exit Do
      End If
     
     If frmMain.started Then
     a = 4 * frmMain.ActiveVis1.ModifySamples(VarPtr(decbuff(0)), (a / 4), 16, 2, 44100)
     End If
     
      If a > c Then
          Call CopyMemory(tempbuffer(nBufferPos), decbuff(0), c)
          exlen = a - c
          Call CopyMemory(excess(0), decbuff(c), exlen)
          c = 0
      Else
          Call CopyMemory(tempbuffer(nBufferPos), decbuff(0), a)
          nBufferPos = nBufferPos + a
          c = c - a
      End If
  Loop
 
  Call CopyMemory(ByVal buffer, tempbuffer(0), Length - c)
 
  STREAMPROC = Length - c

End Function



Thanks in advance  :)

RevG

  • Posts: 454
Re: vb custom stream question
« Reply #1 on: 9 May '03 - 06:28 »
k, I figured out what my problem was. I had an else statement in there where there shouldn't have been  :P

I'm not a vb programmer so i don't notice these things as quickly.

I am just doing some finishing touches on the activex controls and the example applications. I will probably whip up some documentation and then I will upload the ocx controls along with c++ source code and vb examples of how to use the activex controls.

Cheers,
Greg

Rah'Dick

  • XMPlay Support
  • Posts: 932
Re: vb custom stream question
« Reply #2 on: 27 May '03 - 01:48 »
Hmmm, handling Winamp DSP plugins sounds VERY nice to me...
Could you upload the AX controls somewhere so I could fiddle around with them? ;)

Thanks!