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.
#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.
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