0
0

Hi.
I write simple CD player on Delphi.

Why i alway get error when i try to check function result? As you can see i comment lines that couse error, but functions that priors checks return result as they must.

This is example string in code that couse error msg:
// CheckFModError; //Errors here!!!

P.S. Sorry for bad english…

Here source codes:

  • You must to post comments
0
0

Class code:

[code:2xgve26z]
{*******************************************************}
{ }
{ Module : FMod_Classes.pas }
{ Copyright : (c) 2006 Vasily V. Altunin }
{ Discription : Classes for work with FMod API }
{ Developer : Vasily V. Altunin }
{ Email : skyr@users.sourceforge.net }
{ URL : http://sky3d.sourceforge.net }
{ Comments : You can use and change this code }
{ as long as this block remain on top. }
{ License agreement you can find }
{ in files ‘license’ and ‘license_rus’ }
{ }
{*******************************************************}

unit FMod_Classes;

interface

uses FMod;

type

{TFMod}

TFMod = class
private
FFModSystem : FMOD_SYSTEM;
FLast_FModResult : FMOD_RESULT;
public
constructor Create(MaxChannels : Integer; flags : FMOD_INITFLAGS);
destructor Destroy; override;

property FModSystem : FMOD_SYSTEM read FFModSystem write FFModSystem;

function GetVersion : Cardinal;

function CreateStream(const name_or_data: PChar; mode: Cardinal) : FMOD_Sound;

procedure CheckFModError;

procedure Update;

end;

{TFMod_Sound}

TFMod_Sound = class (TFMod)
private
FSound : FMOD_Sound;
public
destructor Destroy; override;
end;

{TFMod_Audio_CD}

TFMod_Audio_CD = class (TFMod_Sound)
private
FCDSound : FMOD_Sound;
FTrackNo : Integer;
FTrackCnt: Integer;
FChannel : FMOD_CHANNEL;
FPaused : FMOD_BOOL;
public

constructor Create(MaxChannels : Integer; flags : FMOD_INITFLAGS;
                                     const name_or_data: PChar; mode: Cardinal);

property CDSound : FMOD_Sound read FCDSound write FCDSound;
property TrackNo : Integer read FTrackNo write FTrackNo;
property TrackCnt : Integer read FTrackCnt write FTrackCnt;


function GetTracksCount : Integer;

function GetTotalTime : Cardinal;

procedure SetTrack(TrackNumber:Integer);
procedure PlayTrack(TrackNumber:Integer);

procedure Play;
procedure Pause;
procedure Next;
procedure Prev;
procedure First;
procedure Last;

procedure Stop;

function IsPlaying : FMOD_BOOL;
function CurrPlayTime : Cardinal;
function CurrFullPlayTime : Cardinal;

end;

implementation

{TFMod}

constructor TFMod.Create(MaxChannels : Integer; flags : FMOD_INITFLAGS);
begin
FLast_FModResult:=FMOD_System_Create(FFModSystem);
CheckFModError;
FLast_FModResult:=FMOD_System_Init(FFModSystem, maxchannels, flags, nil);
CheckFModError;
end;

destructor TFMod.Destroy;
begin
FLast_FModResult:=FMOD_System_Close(FFModSystem);
CheckFModError;

FLast_FModResult:=FMOD_System_Release(FFModSystem);
CheckFModError;

inherited Destroy;

end;

function TFMod.GetVersion : Cardinal;
begin
FLast_FModResult:=FMOD_System_GetVersion(FFModSystem,Result);
CheckFModError;
end;

function TFMod.CreateStream(const name_or_data: PChar; mode: Cardinal) : FMOD_Sound;
begin
FLast_FModResult:=FMOD_System_CreateStream(FFModSystem, name_or_data, mode, nil, Result);
CheckFModError;
end;

procedure TFMod.CheckFModError;
begin
CheckError(FLast_FModResult);
end;

procedure TFMod.Update;
begin
FMOD_System_Update(FFModSystem);
end;

{TFMod_Sound}

destructor TFMod_Sound.Destroy;
begin
FLast_FModResult:=FMOD_Sound_Release(FSound);
CheckFModError;
inherited Destroy;

end;

{TFMod_Audio_CD}

constructor TFMod_Audio_CD.Create(MaxChannels : Integer; flags : FMOD_INITFLAGS; const name_or_data: PChar; mode: Cardinal);
begin
inherited Create(MaxChannels, flags);
FCDSound:=CreateStream(name_or_data, mode);
FTrackNo:=0;
FTrackCnt:=GetTracksCount;
SetTrack(FTrackNo);
end;

function TFMod_Audio_CD.GetTracksCount : Integer;
begin
FLast_FModResult:=FMOD_Sound_GetNumSubSounds(FCDSound, Result);
CheckFModError;
end;

function TFMod_Audio_CD.GetTotalTime : Cardinal;
begin
FLast_FModResult:=FMOD_Sound_GetSubSound(FCDSound, 0, FSound);
CheckFModError;

FLast_FModResult:=FMOD_Sound_GetLength(CDSound, Result, FMOD_TIMEUNIT_MS);
CheckFModError;

end;

procedure TFMod_Audio_CD.SetTrack(TrackNumber:Integer);
begin
FLast_FModResult:=FMOD_Sound_GetSubSound(FCDSound, TrackNumber, FSound);
CheckFModError;
end;

procedure TFMod_Audio_CD.PlayTrack(TrackNumber:Integer);
begin
SetTrack(TrackNumber);
FLast_FModResult:=FMOD_System_PlaySound(FFModSystem, FMOD_CHANNEL_FREE, FSound, False, FChannel);
CheckFModError;
end;

procedure TFMod_Audio_CD.Play;
begin
FLast_FModResult:=FMOD_System_PlaySound(FFModSystem, FMOD_CHANNEL_FREE, FSound, False, FChannel);
CheckFModError;
end;

procedure TFMod_Audio_CD.Pause;
begin
FLast_FModResult:=FMOD_Channel_GetPaused(FChannel, FPaused);
CheckFModError;
FPaused:=not FPaused;
FLast_FModResult:=FMOD_Channel_SetPaused(FChannel, FPaused);
CheckFModError;
end;

procedure TFMod_Audio_CD.Next;
begin
if FTrackNo >= FTrackCnt-1 then
FTrackNo:=0
else
Inc(FTrackNo);
PlayTrack(FTrackNo);
end;

procedure TFMod_Audio_CD.Prev;
begin
if FTrackNo <= 0 then
FTrackNo:=FTrackCnt-1
else
Dec(FTrackNo);

PlayTrack(FTrackNo);

end;

procedure TFMod_Audio_CD.First;
begin
FTrackNo:=0;
PlayTrack(FTrackNo);
end;

procedure TFMod_Audio_CD.Last;
begin
FTrackNo:=FTrackCnt-1;
PlayTrack(FTrackNo);
end;

procedure TFMod_Audio_CD.Stop;
begin
if IsPlaying then
FMOD_Channel_Stop(FChannel);
end;

function TFMod_Audio_CD.IsPlaying : FMOD_BOOL;
begin
FLast_FModResult:=FMOD_Channel_IsPlaying(FChannel, Result);
// CheckFModError; //Errors here!!!
end;

function TFMod_Audio_CD.CurrPlayTime : Cardinal;
begin
FLast_FModResult:=FMOD_Channel_GetPosition(FChannel, Result, FMOD_TIMEUNIT_MS);
// CheckFModError; //Errors here!!!
end;

function TFMod_Audio_CD.CurrFullPlayTime : Cardinal;
begin
FLast_FModResult:=FMOD_Sound_GetLength(FSound, Result, FMOD_TIMEUNIT_MS);
// CheckFModError; //Errors here!!!
end;

end.
[/code:2xgve26z]

  • You must to post comments
0
0

Program Unit code:

[code:kp1di7rl]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,
FMod, ExtCtrls,
FMod_Classes;
type
TForm1 = class(TForm)
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Timer1: TTimer;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Button1: TButton;
Button3: TButton;
Button8: TButton;
Label10: TLabel;
Label11: TLabel;
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
CDPlayer : TFMod_Audio_CD;
Form1: TForm1;
Ver : Cardinal;
LenTracks : Cardinal;
CurrTrack : Cardinal;
FullCurrTrack : Cardinal;
IsStart : Boolean;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
VerStr : String;
begin
CDPlayer:=TFMod_Audio_CD.Create(1, FMOD_INIT_NORMAL, ‘e:’, FMOD_OPENONLY);

VerStr:=Format('%x',[CDPlayer.GetVersion]);
label1.Caption:='FMod version: '+Copy(VerStr,Length(VerStr)-4,1)+'.'+Copy(VerStr,Length(VerStr)-3,2)+'.'+Copy(VerStr,Length(VerStr)-1,2);

label2.Caption:=IntToStr(CDPlayer.GetTracksCount);

LenTracks:=CDPlayer.GetTotalTime;

label3.Caption:=Format('%2d',[LenTracks div 1000 div 60])+' : '+
                                Format('%2d',[LenTracks div 1000 mod 60]);

label6.Caption:=IntToStr(CDPlayer.TrackNo+1);

IsStart:=True;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
CDPlayer.Play;
label6.Caption:=IntToStr(CDPlayer.TrackNo+1);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
CDPlayer.Destroy;

Application.Terminate;

end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Button4Click(Self);
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
CDPlayer.Next;
label6.Caption:=IntToStr(CDPlayer.TrackNo+1);
IsStart:=False;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
CDPlayer.Prev;
label6.Caption:=IntToStr(CDPlayer.TrackNo+1);
IsStart:=False;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (not CDPlayer.IsPlaying) and (not IsStart) then
begin
CDPlayer.Next;
label6.Caption:=IntToStr(CDPlayer.TrackNo+1);
end;

CurrTrack:=CDPlayer.CurrPlayTime;
FullCurrTrack:=CDPlayer.CurrFullPlayTime;

label4.Caption:=Format('%2d',[CurrTrack div 1000 div 60])+' : '+
                                Format('%2d',[CurrTrack div 1000 mod 60]);
label10.Caption:=Format('%2d',[FullCurrTrack div 1000 div 60])+' : '+
                                Format('%2d',[FullCurrTrack div 1000 mod 60]);

CDPlayer.Update;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
CDPlayer.First;
label6.Caption:=IntToStr(CDPlayer.TrackNo+1);
IsStart:=False;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
CDPlayer.Last;
label6.Caption:=IntToStr(CDPlayer.TrackNo+1);
IsStart:=False;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
if not IsStart then
CDPlayer.Pause;
end;

end.
[/code:kp1di7rl]

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.