diff --git a/components/fpsound/fpsound.pas b/components/fpsound/fpsound.pas index 92c18d2d0..73d60d4bd 100644 --- a/components/fpsound/fpsound.pas +++ b/components/fpsound/fpsound.pas @@ -16,11 +16,20 @@ uses Classes, SysUtils; type + TSoundDocument = class; + + TSoundFormat = (sfWav, sfMP3); + + TSoundReader = class + public + procedure ReadFromStream(AStream: TStream; ADest: TSoundDocument); virtual; abstract; + end; + TSoundPlayerKind = (spOpenAL, spMPlayer, spFMod, spExtra1); TSoundPlayer = class public - procedure Play; + procedure Play(ASound: TSoundDocument); virtual; abstract; end; { TSoundDocument } @@ -28,26 +37,50 @@ type TSoundDocument = class private AStream: TStream; + FPlayer: TSoundPlayer; public constructor Create; virtual; destructor Destroy; override; procedure LoadFromFile(AFileName: string); + procedure LoadFromFile(AFileName: string; AFormat: TSoundFormat); procedure Play; + procedure Pause; + procedure Seek(ANewPos: Double); procedure SetSoundPlayer(AKind: TSoundPlayerKind); 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 var 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 GSoundPlayers[AKind] := APlayer; 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 } constructor TSoundDocument.Create; @@ -61,6 +94,16 @@ begin end; 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 end; @@ -70,7 +113,17 @@ begin end; -procedure TSoundDocument.SetSoundPlayer(AKind: TFPSoundPlayerKind); +procedure TSoundDocument.Pause; +begin + +end; + +procedure TSoundDocument.Seek(ANewPos: Double); +begin + +end; + +procedure TSoundDocument.SetSoundPlayer(AKind: TSoundPlayerKind); begin end; diff --git a/components/fpsound/fpsound_openal.pas b/components/fpsound/fpsound_openal.pas index 572584c16..a69ab2d4d 100644 --- a/components/fpsound/fpsound_openal.pas +++ b/components/fpsound/fpsound_openal.pas @@ -20,9 +20,17 @@ var al_context : PALCcontext; type - TOpenALPlayer = class(TObject) + TOpenALPlayer = class(TSoundPlayer) 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; codec_bs : Longword; OPCSoundWasInitialized: Boolean; @@ -34,6 +42,8 @@ type al_readbuf : Pointer; al_rate : Longword; wave : TWaveReader; + public + //procedure OPCSoundPlayStreamEx(AStream: TStream); procedure OPCSoundOpenALPlay(); procedure OPCSoundOpenALLoadWavFromStream(AStream: TStream); procedure OPCSoundOpenALInitialize(); @@ -42,9 +52,10 @@ type function alProcess: Boolean; end; + implementation -type +(*type TWAVHeader = record RIFFHeader: array [1..4] of AnsiChar; FileSize: longint; @@ -59,17 +70,6 @@ type BitsPerSample: Word; 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; var size: LongInt; var freq: LongInt; var loop: LongInt): Boolean; var @@ -281,18 +281,18 @@ end; procedure TOpenALThread.DoOpenALPlay; begin OPCSoundPlayStreamEx(FAOwner); -end; +end;*) /// -procedure TOPCAudioPlayer.alStop; +procedure TOpenALPlayer.alStop; begin alSourceStop(al_source); alSourceRewind(al_source); alSourcei(al_source, AL_BUFFER, 0); end; -function TOPCAudioPlayer.alProcess: Boolean; +function TOpenALPlayer.alProcess: Boolean; var processed : ALint; buffer : ALuint; @@ -314,7 +314,7 @@ begin Result := True; end; -procedure TOPCAudioPlayer.OPCSoundOpenALPlay(); +procedure TOpenALPlayer.OPCSoundOpenALPlay(); var i: Integer; queued : Integer; @@ -350,7 +350,7 @@ begin until done; end; -procedure TOPCAudioPlayer.OPCSoundOpenALLoadWavFromStream(AStream: TStream); +procedure TOpenALPlayer.OPCSoundOpenALLoadWavFromStream(AStream: TStream); var Filename: String; queued : Integer; @@ -398,7 +398,7 @@ begin alProcess(); end; -procedure TOPCAudioPlayer.OPCSoundOpenALInitialize(); +procedure TOpenALPlayer.OPCSoundOpenALInitialize(); begin OPCSoundWasInitialized := True; @@ -409,7 +409,7 @@ begin GetMem(al_readbuf, al_bufsize); end; -procedure TOPCAudioPlayer.OPCSoundOpenALFinalize(); +procedure TOpenALPlayer.OPCSoundOpenALFinalize(); begin // finalize openal alDeleteSources(1, @al_source);