You've already forked lazarus-ccr
fpsound: develops further, still only noise
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2271 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -13,7 +13,7 @@ object Form1: TForm1
|
||||
Height = 25
|
||||
Top = 48
|
||||
Width = 292
|
||||
Caption = 'Open, Play and Close'
|
||||
Caption = 'Load and Play'
|
||||
OnClick = btnOpenPlayAndCloseClick
|
||||
TabOrder = 0
|
||||
end
|
||||
|
@@ -35,13 +35,10 @@ uses fpsound, fpsound_wav, fpsound_openal;
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.btnOpenPlayAndCloseClick(Sender: TObject);
|
||||
var
|
||||
lSoundDoc: TSoundDocument;
|
||||
begin
|
||||
lSoundDoc := TSoundDocument.Create;
|
||||
lSoundDoc.LoadFromFile(pathEdit.FileName);
|
||||
lSoundDoc.SetSoundPlayer(spOpenAL);
|
||||
lSoundDoc.Play;
|
||||
SoundPlayer.LoadFromFile(pathEdit.FileName);
|
||||
SoundPlayer.SetSoundPlayer(spOpenAL);
|
||||
SoundPlayer.Play;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
|
@@ -28,11 +28,13 @@ type
|
||||
procedure ReadFromStream(AStream: TStream; ADest: TSoundDocument); virtual; abstract;
|
||||
end;
|
||||
|
||||
TSoundPlayerKind = (spOpenAL, spMPlayer, spFMod, spExtra1, spExtra2);
|
||||
TSoundPlayerKind = (spNone, spOpenAL, spMPlayer, spFMod, spExtra1, spExtra2);
|
||||
|
||||
{ TSoundPlayer }
|
||||
|
||||
TSoundPlayer = class
|
||||
protected
|
||||
FInitialized: Boolean;
|
||||
public
|
||||
constructor Create; virtual;
|
||||
procedure Initialize; virtual; abstract;
|
||||
@@ -79,6 +81,7 @@ type
|
||||
private
|
||||
AStream: TStream;
|
||||
FPlayer: TSoundPlayer;
|
||||
FPlayerKind: TSoundPlayerKind;
|
||||
FCurElementIndex: Integer;
|
||||
FSoundData: TFPList; // of TSoundElement
|
||||
public
|
||||
@@ -103,6 +106,9 @@ type
|
||||
procedure SetSoundPlayer(AKind: TSoundPlayerKind);
|
||||
end;
|
||||
|
||||
var
|
||||
SoundPlayer: TSoundDocument;
|
||||
|
||||
procedure RegisterSoundPlayer(APlayer: TSoundPlayer; AKind: TSoundPlayerKind);
|
||||
procedure RegisterSoundReader(AReader: TSoundReader; AFormat: TSoundFormat);
|
||||
function GetSoundPlayer(AKind: TSoundPlayerKind): TSoundPlayer;
|
||||
@@ -111,7 +117,7 @@ function GetSoundReader(AFormat: TSoundFormat): TSoundReader;
|
||||
implementation
|
||||
|
||||
var
|
||||
GSoundPlayers: array[TSoundPlayerKind] of TSoundPlayer = (nil, nil, nil, nil, nil);
|
||||
GSoundPlayers: array[TSoundPlayerKind] of TSoundPlayer = (nil, nil, nil, nil, nil, nil);
|
||||
GSoundReaders: array[TSoundFormat] of TSoundReader = (nil, nil, nil, nil, nil, nil, nil);
|
||||
// GSoundWriter: array[TSoundFormat] of TSoundWriter = (nil, nil, nil, nil, nil, nil, nil);
|
||||
|
||||
@@ -168,6 +174,7 @@ end;
|
||||
destructor TSoundDocument.Destroy;
|
||||
begin
|
||||
FSoundData.Free;
|
||||
if FPlayer <> nil then FPlayer.Finalize;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@@ -272,6 +279,8 @@ end;
|
||||
|
||||
procedure TSoundDocument.SetSoundPlayer(AKind: TSoundPlayerKind);
|
||||
begin
|
||||
if AKind = FPlayerKind then Exit;
|
||||
FPlayerKind := AKind;
|
||||
Stop;
|
||||
FPlayer := GSoundPlayers[AKind];
|
||||
end;
|
||||
@@ -280,7 +289,12 @@ var
|
||||
lReaderIndex: TSoundFormat;
|
||||
lPlayerIndex: TSoundPlayerKind;
|
||||
|
||||
initialization
|
||||
SoundPlayer := TSoundDocument.Create;
|
||||
|
||||
finalization
|
||||
SoundPlayer.Free;
|
||||
|
||||
for lReaderIndex := Low(TSoundFormat) to High(TSoundFormat) do
|
||||
if GSoundReaders[lReaderIndex] <> nil then GSoundReaders[lReaderIndex].Free;
|
||||
|
||||
|
@@ -1,4 +1,12 @@
|
||||
{
|
||||
OpenAL player for the fpsound library
|
||||
|
||||
License: The same modified LGPL as the LCL
|
||||
|
||||
Authors:
|
||||
|
||||
JiXian Yang
|
||||
Felipe Monteiro de Carvalho
|
||||
}
|
||||
unit fpsound_openal;
|
||||
|
||||
@@ -103,6 +111,8 @@ end;
|
||||
|
||||
procedure TOpenALPlayer.Initialize;
|
||||
begin
|
||||
if FInitialized then Exit;
|
||||
|
||||
al_device := alcOpenDevice(nil);
|
||||
al_context := alcCreateContext(al_device, nil);
|
||||
alcMakeContextCurrent(al_context);
|
||||
@@ -122,6 +132,8 @@ begin
|
||||
// alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
||||
al_bufcount := 1;
|
||||
alGenBuffers(al_bufcount, @al_buffers);
|
||||
|
||||
FInitialized := True;
|
||||
end;
|
||||
|
||||
procedure TOpenALPlayer.Finalize;
|
||||
@@ -132,6 +144,7 @@ begin
|
||||
if al_readbuf <> nil then FreeMem(al_readbuf);
|
||||
alcDestroyContext(al_context);
|
||||
alcCloseDevice(al_device);
|
||||
FInitialized := False;
|
||||
end;
|
||||
|
||||
procedure TOpenALPlayer.Play(ASound: TSoundDocument);
|
||||
@@ -140,7 +153,7 @@ var
|
||||
done : Boolean;
|
||||
lKeyElement: TSoundKeyElement;
|
||||
begin
|
||||
Initialize();
|
||||
Initialize;
|
||||
|
||||
// First adjust to the first key element
|
||||
lKeyElement := ASound.GetFirstSoundElement();
|
||||
@@ -162,10 +175,7 @@ end;
|
||||
|
||||
procedure TOpenALPlayer.AdjustToKeyElement(ASound: TSoundDocument; AKeyElement: TSoundKeyElement);
|
||||
begin
|
||||
// define codec
|
||||
//source := AStream;
|
||||
|
||||
// inittialize codec
|
||||
// initialize codec
|
||||
if AKeyElement.Channels = 1 then
|
||||
begin
|
||||
if AKeyElement.BitsPerSample=8 then al_format:=AL_FORMAT_MONO8
|
||||
|
Reference in New Issue
Block a user