fpsound: Some more coding and skeleton building

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2133 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2011-11-14 21:00:46 +00:00
parent 2b0994f3cd
commit 51c54f54ac
2 changed files with 78 additions and 25 deletions

View File

@@ -16,11 +16,20 @@ uses
Classes, SysUtils; Classes, SysUtils;
type type
TSoundDocument = class;
TSoundFormat = (sfWav, sfMP3);
TSoundReader = class
public
procedure ReadFromStream(AStream: TStream; ADest: TSoundDocument); virtual; abstract;
end;
TSoundPlayerKind = (spOpenAL, spMPlayer, spFMod, spExtra1); TSoundPlayerKind = (spOpenAL, spMPlayer, spFMod, spExtra1);
TSoundPlayer = class TSoundPlayer = class
public public
procedure Play; procedure Play(ASound: TSoundDocument); virtual; abstract;
end; end;
{ TSoundDocument } { TSoundDocument }
@@ -28,26 +37,50 @@ type
TSoundDocument = class TSoundDocument = class
private private
AStream: TStream; AStream: TStream;
FPlayer: TSoundPlayer;
public public
constructor Create; virtual; constructor Create; virtual;
destructor Destroy; override; destructor Destroy; override;
procedure LoadFromFile(AFileName: string); procedure LoadFromFile(AFileName: string);
procedure LoadFromFile(AFileName: string; AFormat: TSoundFormat);
procedure Play; procedure Play;
procedure Pause;
procedure Seek(ANewPos: Double);
procedure SetSoundPlayer(AKind: TSoundPlayerKind); procedure SetSoundPlayer(AKind: TSoundPlayerKind);
end; end;
procedure RegisterSoundPlayer(APlayer: TSoundPlayer; AKind: TFPSoundPlayerKind); procedure RegisterSoundPlayer(APlayer: TSoundPlayer; AKind: TSoundPlayerKind);
procedure RegisterSoundReader(AReader: TSoundReader; AFormat: TSoundFormat);
function GetSoundPlayer(AKind: TSoundPlayerKind): TSoundPlayer;
function GetSoundReader(AFormat: TSoundFormat): TSoundReader;
implementation implementation
var var
GSoundPlayers: array[TSoundPlayerKind] of TSoundPlayer = (nil, nil, nil, nil); GSoundPlayers: array[TSoundPlayerKind] of TSoundPlayer = (nil, nil, nil, nil);
GSoundReader: array[TSoundFormat] of TSoundReader = (nil, nil);
// GSoundWriter: array[TSoundFormat] of TSoundWriter = (nil, nil);
procedure RegisterSoundPlayer(APlayer: TSoundPlayer; AKind: TFPSoundPlayerKind); procedure RegisterSoundPlayer(APlayer: TSoundPlayer; AKind: TSoundPlayerKind);
begin begin
GSoundPlayers[AKind] := APlayer; GSoundPlayers[AKind] := APlayer;
end; end;
procedure RegisterSoundReader(AReader: TSoundReader; AFormat: TSoundFormat);
begin
GSoundReader[AFormat] := AReader;
end;
function GetSoundPlayer(AKind: TSoundPlayerKind): TSoundPlayer;
begin
end;
function GetSoundReader(AFormat: TSoundFormat): TSoundReader;
begin
end;
{ TSoundDocument } { TSoundDocument }
constructor TSoundDocument.Create; constructor TSoundDocument.Create;
@@ -61,6 +94,16 @@ begin
end; end;
procedure TSoundDocument.LoadFromFile(AFileName: string); procedure TSoundDocument.LoadFromFile(AFileName: string);
var
lExt: String;
begin
lExt := ExtractFileExt(AFileName);
if CompareText(lExt, 'wav') = 0 then LoadFromFile(AFileName, sfWav)
else
raise Exception.Create(Format('[TSoundDocument.LoadFromFile] Unknown extension: %s', [lExt]));
end;
procedure TSoundDocument.LoadFromFile(AFileName: string; AFormat: TSoundFormat);
begin begin
end; end;
@@ -70,7 +113,17 @@ begin
end; end;
procedure TSoundDocument.SetSoundPlayer(AKind: TFPSoundPlayerKind); procedure TSoundDocument.Pause;
begin
end;
procedure TSoundDocument.Seek(ANewPos: Double);
begin
end;
procedure TSoundDocument.SetSoundPlayer(AKind: TSoundPlayerKind);
begin begin
end; end;

View File

@@ -20,9 +20,17 @@ var
al_context : PALCcontext; al_context : PALCcontext;
type type
TOpenALPlayer = class(TObject) TOpenALPlayer = class(TSoundPlayer)
private private
public { buffer : Cardinal;
sourcepos: array [0..2] of Single=(0.0, 0.0, 0.0);
sourcevel: array [0..2] of Single=(0.0, 0.0, 0.0);
listenerpos: array [0..2] of Single=(0.0, 0.0, 0.0);
listenervel: array [0..2] of Single=(0.0, 0.0, 0.0);
listenerori: array [0..5] of Single=(0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
Context: PALCcontext;
Device: PALCdevice;}
//
source : TStream; source : TStream;
codec_bs : Longword; codec_bs : Longword;
OPCSoundWasInitialized: Boolean; OPCSoundWasInitialized: Boolean;
@@ -34,6 +42,8 @@ type
al_readbuf : Pointer; al_readbuf : Pointer;
al_rate : Longword; al_rate : Longword;
wave : TWaveReader; wave : TWaveReader;
public
//procedure OPCSoundPlayStreamEx(AStream: TStream);
procedure OPCSoundOpenALPlay(); procedure OPCSoundOpenALPlay();
procedure OPCSoundOpenALLoadWavFromStream(AStream: TStream); procedure OPCSoundOpenALLoadWavFromStream(AStream: TStream);
procedure OPCSoundOpenALInitialize(); procedure OPCSoundOpenALInitialize();
@@ -42,9 +52,10 @@ type
function alProcess: Boolean; function alProcess: Boolean;
end; end;
implementation implementation
type (*type
TWAVHeader = record TWAVHeader = record
RIFFHeader: array [1..4] of AnsiChar; RIFFHeader: array [1..4] of AnsiChar;
FileSize: longint; FileSize: longint;
@@ -59,17 +70,6 @@ type
BitsPerSample: Word; BitsPerSample: Word;
end; end;
var
buffer : Cardinal;
source : Cardinal;
sourcepos: array [0..2] of Single=(0.0, 0.0, 0.0);
sourcevel: array [0..2] of Single=(0.0, 0.0, 0.0);
listenerpos: array [0..2] of Single=(0.0, 0.0, 0.0);
listenervel: array [0..2] of Single=(0.0, 0.0, 0.0);
listenerori: array [0..5] of Single=(0.0, 0.0, -1.0, 0.0, 1.0, 0.0);
Context: PALCcontext;
Device: PALCdevice;
function LoadWavStream(Stream: TStream; var format: integer; var data: Pointer; function LoadWavStream(Stream: TStream; var format: integer; var data: Pointer;
var size: LongInt; var freq: LongInt; var loop: LongInt): Boolean; var size: LongInt; var freq: LongInt; var loop: LongInt): Boolean;
var var
@@ -281,18 +281,18 @@ end;
procedure TOpenALThread.DoOpenALPlay; procedure TOpenALThread.DoOpenALPlay;
begin begin
OPCSoundPlayStreamEx(FAOwner); OPCSoundPlayStreamEx(FAOwner);
end; end;*)
/// ///
procedure TOPCAudioPlayer.alStop; procedure TOpenALPlayer.alStop;
begin begin
alSourceStop(al_source); alSourceStop(al_source);
alSourceRewind(al_source); alSourceRewind(al_source);
alSourcei(al_source, AL_BUFFER, 0); alSourcei(al_source, AL_BUFFER, 0);
end; end;
function TOPCAudioPlayer.alProcess: Boolean; function TOpenALPlayer.alProcess: Boolean;
var var
processed : ALint; processed : ALint;
buffer : ALuint; buffer : ALuint;
@@ -314,7 +314,7 @@ begin
Result := True; Result := True;
end; end;
procedure TOPCAudioPlayer.OPCSoundOpenALPlay(); procedure TOpenALPlayer.OPCSoundOpenALPlay();
var var
i: Integer; i: Integer;
queued : Integer; queued : Integer;
@@ -350,7 +350,7 @@ begin
until done; until done;
end; end;
procedure TOPCAudioPlayer.OPCSoundOpenALLoadWavFromStream(AStream: TStream); procedure TOpenALPlayer.OPCSoundOpenALLoadWavFromStream(AStream: TStream);
var var
Filename: String; Filename: String;
queued : Integer; queued : Integer;
@@ -398,7 +398,7 @@ begin
alProcess(); alProcess();
end; end;
procedure TOPCAudioPlayer.OPCSoundOpenALInitialize(); procedure TOpenALPlayer.OPCSoundOpenALInitialize();
begin begin
OPCSoundWasInitialized := True; OPCSoundWasInitialized := True;
@@ -409,7 +409,7 @@ begin
GetMem(al_readbuf, al_bufsize); GetMem(al_readbuf, al_bufsize);
end; end;
procedure TOPCAudioPlayer.OPCSoundOpenALFinalize(); procedure TOpenALPlayer.OPCSoundOpenALFinalize();
begin begin
// finalize openal // finalize openal
alDeleteSources(1, @al_source); alDeleteSources(1, @al_source);