procedure TForm1.SampleAudioStream(FileName:
String);
Const
BUFFER_SIZE = 256;
var
Buffer:
array of Single;
Info: BASS_CHANNELINFO;
i: integer;
Progress: integer;
H, S, L: double;
Value: double;
StreamLength: Int64;
ScanLines: TArray<PRGBTriple>;
P: PRGBTriple;
R, G, B: Byte;
pcFrequency: Int64;
// <--------------------- Zeitmessung
timeAll0, timeAll1, timeAll: Int64;
// <----- Zeitmessung
timeDraw0, timeDraw1, timeDraw: Int64;
// <-- Zeitmessung
begin
Channel := BASS_MusicLoad(false, PChar(FileName), 0, 0,
BASS_MUSIC_DECODE
OR BASS_MUSIC_STOPBACK
OR BASS_MUSIC_CALCLEN
{$IFDEF UNICODE} OR BASS_UNICODE
{$ENDIF} OR BASS_SAMPLE_FLOAT, 0);
if Channel = 0
then
begin
Channel := BASS_StreamCreateFile(false, PChar(FileName), 0, 0,
BASS_STREAM_DECODE
OR BASS_MP3_SETPOS
OR BASS_SAMPLE_FLOAT
{$IFDEF UNICODE} OR BASS_UNICODE
{$ENDIF});
end;
if Channel = 0
then
begin
Exit;
end;
Form2.ProgressBar1.position := 0;
Form2.Show;
BASS_ChannelGetInfo(Channel, Info);
StreamLength := BASS_ChannelGetLength(Channel, BASS_POS_BYTE);
Bitmap.Height := 256;
Bitmap.Width := (StreamLength
div 512
div 4)
div Info.chans;
PB.Width := Bitmap.Width;
PB.Height := Bitmap.Height;
PB.Parent.DoubleBuffered := true;
S := 0.9;
SetLength(Buffer, BUFFER_SIZE);
ColumnCounter := 0;
QueryPerformanceFrequency(pcFrequency);
// <------ Zeitmessung
QueryPerformanceCounter(timeAll0);
// <----------- Zeitmessung
timeDraw := 0;
// <------------------------------- Zeitmessung
if RadioButton1.Checked
then
begin
SetLength(ScanLines, Bitmap.Height);
for i := 0
to Length(ScanLines) - 1
do
ScanLines[i] := Bitmap.Scanline[i];
end;
while BASS_ChannelIsActive(Channel) <> BASS_ACTIVE_STOPPED
do
begin
BASS_ChannelGetData(Channel, Pointer(Buffer), BASS_DATA_FFT512);
for i := 0
to BUFFER_SIZE - 1
do
begin
Value := SQRT(SQRT(Buffer[i]));
H := 0 + Value / 1.5;
L := Value;
if RadioButton1.Checked
then
begin
QueryPerformanceCounter(timeDraw0);
// <-------------------- Zeitmessung
P := ScanLines[BUFFER_SIZE - i];
if Assigned(P)
then
HSLtoRGB(H, S, L, P^.rgbtRed, P^.rgbtGreen, P^.rgbtBlue);
QueryPerformanceCounter(timeDraw1);
// <------------------- Zeitmessung
timeDraw := timeDraw + (timeDraw1-timeDraw0);
// <--------- Zeitmessung
end
else
begin
QueryPerformanceCounter(timeDraw0);
// <------------------- Zeitmessung
HSLtoRGB(H, S, L, R, G, B);
Bitmap.Canvas.Pixels[ColumnCounter, BUFFER_SIZE - i] :=
RGB(R, G, B)
QueryPerformanceCounter(timeDraw1);
// <------------------- Zeitmessung
timeDraw := timeDraw + (timeDraw1-timeDraw0);
// <--------- Zeitmessung
end;
end;
if RadioButton1.Checked
then
begin
for i := 0
to Length(ScanLines) - 1
do
Inc(ScanLines[i]);
end
else
Inc(ColumnCounter);
Progress := trunc(100 * (Bass_ChannelGetPosition(Channel, BASS_POS_BYTE) / BASS_ChannelGetLength
(Channel, BASS_POS_BYTE)));
if (Form2.ProgressBar1.position <> Progress)
then
begin
Form2.ProgressBar1.position := Progress;
PB.Refresh;
end;
end;
QueryPerformanceCounter(timeAll1);
// <-------------------------------------------------- Zeitmessung
timeAll := timeAll1-timeAll0;
// <------------------------------------------------------- Zeitmessung
Label1.Caption := '
Gesamtzeit: '+FloatToStrF(timeAll/pcFrequency, ffFixed, 8, 3);
// <--- Zeitmessung
Label2.Caption := '
Draw-Zeit: '+FloatToStrF(timeDraw/pcFrequency, ffFixed, 8, 3);
// <--- Zeitmessung
Form2.Hide;
Bass_StreamFree(Channel);
Channel := BASS_StreamCreateFile(false, PChar(FileName), 0, 0, 0
{$IFDEF UNICODE} or BASS_UNICODE
{$ENDIF});
if Channel = 0
then
begin
Channel := BASS_MusicLoad(false, PChar(FileName), 0, 0,
BASS_MUSIC_RAMPS
or BASS_MUSIC_POSRESET
or BASS_MUSIC_PRESCAN
{$IFDEF UNICODE} or BASS_UNICODE
{$ENDIF}, 0);
if (Channel = 0)
then
Exit;
end;
DestBitmap.Width := PB.Width;
DestBitmap.Height := PB.Height;
BitBlt(DestBitmap.Canvas.handle, 0, 0, PB.Width, PB.Height, Bitmap.Canvas.handle, 0, 0, SrcCopy);
bpp := BASS_ChannelGetLength(Channel, BASS_POS_BYTE)
div PB.Width;
BASS_ChannelSetSync(Channel, BASS_SYNC_END
or BASS_SYNC_MIXTIME, 0, LoopSyncProc,
nil);
BASS_ChannelPlay(Channel, false);
Timer1.Enabled := true;
end;