0
0

Hi,

why is this Code so slow ?
If you want, you can take the ID3-Tags out … .
[code:2utvgvep]
var
frmMain : TfrmMain;
system : FMOD_SYSTEM;
sound1 : FMOD_SOUND;
Chan : FMOD_CHANNEL = nil;
result : FMOD_RESULT;
version : cardinal;
filename : String;

const
Genres : array[0..146] of string =
// ...

function TfrmMain.ReadID3Tag(FileName: string): TID3Tag;
var
FS: TFileStream;
Buffer: array [1..128] of Char;
begin
FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
FS.Seek(-128, soFromEnd);
FS.Read(Buffer, 128);
with Result do
begin
ID := Copy(Buffer, 1, 3);
Titel := Copy(Buffer, 4, 30);
Artist := Copy(Buffer, 34, 30);
Album := Copy(Buffer, 64, 30);
Year := Copy(Buffer, 94, 4);
Comment := Copy(Buffer, 98, 30);
Genre := Ord(Buffer[128]);
end;
finally
FS.Free;
end;
end;

procedure ErrCheck(result: FMOD_RESULT);
begin
if (result <> FMOD_OK) then begin
showmessage(’FMOD error! ‘ + FMOD_ErrorString(result));
end;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
result := FMOD_System_Create(system);
ErrCheck(result);
result := FMOD_System_GetVersion(system, version);
ErrCheck(result);
if (version < FMOD_VERSION) then begin
showmessage(Format(’Error! You are using an old version of FMOD %.8x. This program requires %.8x’, [version, FMOD_VERSION]));
end;

result := FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
end;

procedure TfrmMain.btnPlayClick(Sender: TObject);
var ItemIndex: Integer;
begin
if pList.ItemIndex = -1 then
exit;
ItemIndex := pList.ItemIndex;
p2.ItemIndex := ItemIndex;
filename := p2.Items.Strings[p2.ItemIndex];
result := FMOD_System_CreateSound(system, PChar(filename), FMOD_HARDWARE, nil, sound1);
result := FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound1, False, Chan);
ErrCheck(result);
end;

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if sound1 <> nil then begin
result := FMOD_Sound_Release(sound1);
ErrCheck(result);
end;
if system <> nil then begin
result := FMOD_System_Close(system);
ErrCheck(result);
result := FMOD_System_Release(system);
ErrCheck(result);
end;
end;

procedure TfrmMain.btnOpenClick(Sender: TObject);
begin
if op1.Execute then
begin
ErrCheck(result);

result := FMOD_Sound_SetMode(sound1, FMOD_LOOP_OFF);
ErrCheck(result);

end;
end;

procedure TfrmMain.btnAddClick(Sender: TObject);
begin
if op1.Execute then
begin
with ReadID3Tag(op1.FileName) do
begin
LlbID.Caption := ‘ID: ‘ + ID;
LlbTitel.Caption := ‘Titel: ‘ + Titel;
LlbArtist.Caption := ‘Artist: ‘ + Artist;
LlbAlbum.Caption := ‘Album: ‘ + Album;
LlbYear.Caption := ‘Year: ‘ + Year;
LlbComment.Caption := ‘Comment: ‘ + Comment;
if (Genre >= 0) and (Genre <=146) then
LlbGenre.Caption := ‘Genre: ‘ + Genres[Genre]
else
LlbGenre.Caption := ‘N/A’;
end;
p2.Items.Add(op1.FileName);
pList.Items.Add(ExtractFileName(op1.FileName));
end;
end;
[/code:2utvgvep]

  • You must to post comments
0
0

Try FMOD_System_CreateStream instead of FMOD_System_CreateSound.

  • You must to post comments
0
0

Thx, it runs fast now (open a song).

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.