var tog:Single;
px:array[0..1]of Single;
begin
tog:=spp;
data[0]:=0;
data[1]:=data[0];
while tog>0 do
begin
if tog<1 then
step:=tog
else
step:=1;
Dec(tog,step);
end;
end;
// scan the peaks
void __cdecl ScanPeaks(void *p)
{
DWORD decoder=(DWORD)p;
DWORD pos=0;
float spp=BASS_ChannelBytes2Seconds(decoder,bpp); // seconds per pixel
while (!killscan) {
float peak[2];
if (spp>1) { // more than 1 second per pixel, break it down...
float todo=spp;
peak[1]=peak[0]=0;
do {
float level[2],step=(todo<1?todo:1);
BASS_ChannelGetLevelEx(decoder,level,step,BASS_LEVEL_STEREO); // scan peaks
if (peak[0]<level[0]) peak[0]=level[0];
if (peak[1]<level[1]) peak[1]=level[1];
todo-=step;
} while (todo>0);
} else
BASS_ChannelGetLevelEx(decoder,peak,spp,BASS_LEVEL_STEREO); // scan peaks
{
DWORD a;
for (a=0;a<peak[0]*(HEIGHT/2);a++)
wavebuf[(HEIGHT/2-1-a)*WIDTH+pos]=1+a; // draw left peak
for (a=0;a<peak[1]*(HEIGHT/2);a++)
wavebuf[(HEIGHT/2+1+a)*WIDTH+pos]=1+a; // draw right peak
}
pos++;
if (pos>=WIDTH) break; // reached end of display
if (!BASS_ChannelIsActive(decoder)) break; // reached end of channel
}
if (!killscan) {
DWORD size;
BASS_ChannelSetPosition(decoder,(QWORD)-1,BASS_POS_BYTE|BASS_POS_SCAN); // build seek table (scan to end)
size=BASS_ChannelGetAttributeEx(decoder,BASS_ATTRIB_SCANINFO,0,0); // get seek table size
if (size) { // got it
void *info=malloc(size); // allocate a buffer
BASS_ChannelGetAttributeEx(decoder,BASS_ATTRIB_SCANINFO,info,size); // get the seek table
BASS_ChannelSetAttributeEx(chan,BASS_ATTRIB_SCANINFO,info,size); // apply it to the playback channel
free(info);
}
}
BASS_StreamFree(decoder); // free the decoder
scanthread=0;
}
procedure ScanPeaks(p:Pointer);cdecl;
var decoder,pos,a,size:LongWord;
spp,todo:Single;
info:Pointer;
peak,level:array[0..1]of Single;
begin
decoder:=LongWord(p);
pos:=0;
spp:=BASS_ChannelBytes2Seconds(decoder,bpp); // seconds per pixel
while (killscan = 0) do
begin
if (spp>1)then // more than 1 second per pixel, break it down...
begin
todo:=spp;
peak[0]:=0;
peak[1]:=peak[0];
while (todo>0)do
begin
if todo<1 then
step := todo
else
step := 1;
BASS_ChannelGetLevelEx(decoder,level,step,BASS_LEVEL_STEREO); // scan peaks
if (peak[0]<level[0])then peak[0]:=level[0];
if (peak[1]<level[1])then peak[1]:=level[1];
Dec(todo,step);
end;
end
else
BASS_ChannelGetLevelEx(decoder,peak,spp,BASS_LEVEL_STEREO); // scan peaks
a := 0;
while a<peak[0]*(HEIGHT div 2) do
begin
wavebuf[(HEIGHT div 2-1-a)*WIDTH+pos]:=1+a;
Inc(a);
end;
a := 0;
while a<peak[1]*(HEIGHT div 2) do
begin
wavebuf[(HEIGHT div 2+1+a)*WIDTH+pos]=1+a; // draw right peak
Inc(a);
end;
Inc(pos);
if (pos>=WIDTH)then break; // reached end of display
if (BASS_ChannelIsActive(decoder) = 0)then break; // reached end of channel
end;
if (killscan = 0) then
begin
BASS_ChannelSetPosition(decoder,(QWORD)-1,BASS_POS_BYTE or BASS_POS_SCAN); // build seek table (scan to end)
size:=BASS_ChannelGetAttributeEx(decoder,BASS_ATTRIB_SCANINFO,0,0); // get seek table size
if (size)then // got it
begin
info := GetMemory(size); // allocate a buffer
BASS_ChannelGetAttributeEx(decoder,BASS_ATTRIB_SCANINFO,info,size); // get the seek table
BASS_ChannelSetAttributeEx(chan,BASS_ATTRIB_SCANINFO,info,size); // apply it to the playback channel
FreeMemory(info);
end;
end;
BASS_StreamFree(decoder); // free the decoder
scanthread:=0;
end;