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
|
Height = 25
|
||||||
Top = 48
|
Top = 48
|
||||||
Width = 292
|
Width = 292
|
||||||
Caption = 'Open, Play and Close'
|
Caption = 'Load and Play'
|
||||||
OnClick = btnOpenPlayAndCloseClick
|
OnClick = btnOpenPlayAndCloseClick
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
|
@@ -35,13 +35,10 @@ uses fpsound, fpsound_wav, fpsound_openal;
|
|||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
procedure TForm1.btnOpenPlayAndCloseClick(Sender: TObject);
|
procedure TForm1.btnOpenPlayAndCloseClick(Sender: TObject);
|
||||||
var
|
|
||||||
lSoundDoc: TSoundDocument;
|
|
||||||
begin
|
begin
|
||||||
lSoundDoc := TSoundDocument.Create;
|
SoundPlayer.LoadFromFile(pathEdit.FileName);
|
||||||
lSoundDoc.LoadFromFile(pathEdit.FileName);
|
SoundPlayer.SetSoundPlayer(spOpenAL);
|
||||||
lSoundDoc.SetSoundPlayer(spOpenAL);
|
SoundPlayer.Play;
|
||||||
lSoundDoc.Play;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.FormCreate(Sender: TObject);
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
|
@@ -28,11 +28,13 @@ type
|
|||||||
procedure ReadFromStream(AStream: TStream; ADest: TSoundDocument); virtual; abstract;
|
procedure ReadFromStream(AStream: TStream; ADest: TSoundDocument); virtual; abstract;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TSoundPlayerKind = (spOpenAL, spMPlayer, spFMod, spExtra1, spExtra2);
|
TSoundPlayerKind = (spNone, spOpenAL, spMPlayer, spFMod, spExtra1, spExtra2);
|
||||||
|
|
||||||
{ TSoundPlayer }
|
{ TSoundPlayer }
|
||||||
|
|
||||||
TSoundPlayer = class
|
TSoundPlayer = class
|
||||||
|
protected
|
||||||
|
FInitialized: Boolean;
|
||||||
public
|
public
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
procedure Initialize; virtual; abstract;
|
procedure Initialize; virtual; abstract;
|
||||||
@@ -79,6 +81,7 @@ type
|
|||||||
private
|
private
|
||||||
AStream: TStream;
|
AStream: TStream;
|
||||||
FPlayer: TSoundPlayer;
|
FPlayer: TSoundPlayer;
|
||||||
|
FPlayerKind: TSoundPlayerKind;
|
||||||
FCurElementIndex: Integer;
|
FCurElementIndex: Integer;
|
||||||
FSoundData: TFPList; // of TSoundElement
|
FSoundData: TFPList; // of TSoundElement
|
||||||
public
|
public
|
||||||
@@ -103,6 +106,9 @@ type
|
|||||||
procedure SetSoundPlayer(AKind: TSoundPlayerKind);
|
procedure SetSoundPlayer(AKind: TSoundPlayerKind);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
SoundPlayer: TSoundDocument;
|
||||||
|
|
||||||
procedure RegisterSoundPlayer(APlayer: TSoundPlayer; AKind: TSoundPlayerKind);
|
procedure RegisterSoundPlayer(APlayer: TSoundPlayer; AKind: TSoundPlayerKind);
|
||||||
procedure RegisterSoundReader(AReader: TSoundReader; AFormat: TSoundFormat);
|
procedure RegisterSoundReader(AReader: TSoundReader; AFormat: TSoundFormat);
|
||||||
function GetSoundPlayer(AKind: TSoundPlayerKind): TSoundPlayer;
|
function GetSoundPlayer(AKind: TSoundPlayerKind): TSoundPlayer;
|
||||||
@@ -111,7 +117,7 @@ function GetSoundReader(AFormat: TSoundFormat): TSoundReader;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
var
|
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);
|
GSoundReaders: array[TSoundFormat] of TSoundReader = (nil, nil, nil, nil, nil, nil, nil);
|
||||||
// GSoundWriter: array[TSoundFormat] of TSoundWriter = (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;
|
destructor TSoundDocument.Destroy;
|
||||||
begin
|
begin
|
||||||
FSoundData.Free;
|
FSoundData.Free;
|
||||||
|
if FPlayer <> nil then FPlayer.Finalize;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -272,6 +279,8 @@ end;
|
|||||||
|
|
||||||
procedure TSoundDocument.SetSoundPlayer(AKind: TSoundPlayerKind);
|
procedure TSoundDocument.SetSoundPlayer(AKind: TSoundPlayerKind);
|
||||||
begin
|
begin
|
||||||
|
if AKind = FPlayerKind then Exit;
|
||||||
|
FPlayerKind := AKind;
|
||||||
Stop;
|
Stop;
|
||||||
FPlayer := GSoundPlayers[AKind];
|
FPlayer := GSoundPlayers[AKind];
|
||||||
end;
|
end;
|
||||||
@@ -280,7 +289,12 @@ var
|
|||||||
lReaderIndex: TSoundFormat;
|
lReaderIndex: TSoundFormat;
|
||||||
lPlayerIndex: TSoundPlayerKind;
|
lPlayerIndex: TSoundPlayerKind;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
SoundPlayer := TSoundDocument.Create;
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
|
SoundPlayer.Free;
|
||||||
|
|
||||||
for lReaderIndex := Low(TSoundFormat) to High(TSoundFormat) do
|
for lReaderIndex := Low(TSoundFormat) to High(TSoundFormat) do
|
||||||
if GSoundReaders[lReaderIndex] <> nil then GSoundReaders[lReaderIndex].Free;
|
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;
|
unit fpsound_openal;
|
||||||
|
|
||||||
@@ -103,6 +111,8 @@ end;
|
|||||||
|
|
||||||
procedure TOpenALPlayer.Initialize;
|
procedure TOpenALPlayer.Initialize;
|
||||||
begin
|
begin
|
||||||
|
if FInitialized then Exit;
|
||||||
|
|
||||||
al_device := alcOpenDevice(nil);
|
al_device := alcOpenDevice(nil);
|
||||||
al_context := alcCreateContext(al_device, nil);
|
al_context := alcCreateContext(al_device, nil);
|
||||||
alcMakeContextCurrent(al_context);
|
alcMakeContextCurrent(al_context);
|
||||||
@@ -122,6 +132,8 @@ begin
|
|||||||
// alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
// alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
|
||||||
al_bufcount := 1;
|
al_bufcount := 1;
|
||||||
alGenBuffers(al_bufcount, @al_buffers);
|
alGenBuffers(al_bufcount, @al_buffers);
|
||||||
|
|
||||||
|
FInitialized := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TOpenALPlayer.Finalize;
|
procedure TOpenALPlayer.Finalize;
|
||||||
@@ -132,6 +144,7 @@ begin
|
|||||||
if al_readbuf <> nil then FreeMem(al_readbuf);
|
if al_readbuf <> nil then FreeMem(al_readbuf);
|
||||||
alcDestroyContext(al_context);
|
alcDestroyContext(al_context);
|
||||||
alcCloseDevice(al_device);
|
alcCloseDevice(al_device);
|
||||||
|
FInitialized := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TOpenALPlayer.Play(ASound: TSoundDocument);
|
procedure TOpenALPlayer.Play(ASound: TSoundDocument);
|
||||||
@@ -140,7 +153,7 @@ var
|
|||||||
done : Boolean;
|
done : Boolean;
|
||||||
lKeyElement: TSoundKeyElement;
|
lKeyElement: TSoundKeyElement;
|
||||||
begin
|
begin
|
||||||
Initialize();
|
Initialize;
|
||||||
|
|
||||||
// First adjust to the first key element
|
// First adjust to the first key element
|
||||||
lKeyElement := ASound.GetFirstSoundElement();
|
lKeyElement := ASound.GetFirstSoundElement();
|
||||||
@@ -162,10 +175,7 @@ end;
|
|||||||
|
|
||||||
procedure TOpenALPlayer.AdjustToKeyElement(ASound: TSoundDocument; AKeyElement: TSoundKeyElement);
|
procedure TOpenALPlayer.AdjustToKeyElement(ASound: TSoundDocument; AKeyElement: TSoundKeyElement);
|
||||||
begin
|
begin
|
||||||
// define codec
|
// initialize codec
|
||||||
//source := AStream;
|
|
||||||
|
|
||||||
// inittialize codec
|
|
||||||
if AKeyElement.Channels = 1 then
|
if AKeyElement.Channels = 1 then
|
||||||
begin
|
begin
|
||||||
if AKeyElement.BitsPerSample=8 then al_format:=AL_FORMAT_MONO8
|
if AKeyElement.BitsPerSample=8 then al_format:=AL_FORMAT_MONO8
|
||||||
|
Reference in New Issue
Block a user