aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UMusic.pas
diff options
context:
space:
mode:
authorjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-10-08 06:45:19 +0000
committerjaybinks <jaybinks@b956fd51-792f-4845-bead-9b4dfca2ff2c>2007-10-08 06:45:19 +0000
commitef07574805b0fb247cfa91f0e6bbb234c0dbd22a (patch)
treec942b36837fa81d456aee8e78eb7f9a667c78759 /Game/Code/Classes/UMusic.pas
parent4d693075a4b5078a9e08430d003e2bdb918b68c2 (diff)
downloadusdx-ef07574805b0fb247cfa91f0e6bbb234c0dbd22a.tar.gz
usdx-ef07574805b0fb247cfa91f0e6bbb234c0dbd22a.tar.xz
usdx-ef07574805b0fb247cfa91f0e6bbb234c0dbd22a.zip
minor changes to faciliate ffmpeg audio playback
jira#USDX-123 git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@470 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/Classes/UMusic.pas')
-rw-r--r--Game/Code/Classes/UMusic.pas107
1 files changed, 102 insertions, 5 deletions
diff --git a/Game/Code/Classes/UMusic.pas b/Game/Code/Classes/UMusic.pas
index b3729e69..bdd0be83 100644
--- a/Game/Code/Classes/UMusic.pas
+++ b/Game/Code/Classes/UMusic.pas
@@ -41,8 +41,48 @@ type
Handle : hStream;
end;
+ IAudioPlayback = Interface
+ procedure InitializePlayback;
+
+ procedure SetVolume(Volume: integer);
+ procedure SetMusicVolume(Volume: integer);
+ procedure SetLoop(Enabled: boolean);
+
+ function Open(Name: string): boolean; // true if succeed
+
+ procedure Play;
+ procedure Pause; //Pause Mod
+ procedure Stop;
- TMusic = class
+ procedure Rewind;
+ procedure MoveTo(Time: real);
+ procedure Close;
+
+ function Finished: boolean;
+ function Length: real;
+ function Position: real;
+
+ procedure PlayStart;
+ procedure PlayBack;
+ procedure PlaySwoosh;
+ procedure PlayChange;
+ procedure PlayOption;
+ procedure PlayClick;
+ procedure PlayDrum;
+ procedure PlayHihat;
+ procedure PlayClap;
+ procedure PlayShuffle;
+ procedure StopShuffle;
+
+ function LoadSoundFromFile(var hStream: hStream; Name: string): boolean;
+
+ //Custom Sounds
+ function LoadCustomSound(const Filename: String): Cardinal;
+ procedure PlayCustomSound(const Index: Cardinal);
+ end;
+
+
+ TMusic = class( TInterfacedObject, IAudioPlayback )
private
BassStart: hStream; // Wait, I've replaced this with BASS
BassBack: hStream; // It has almost all features we need
@@ -59,6 +99,8 @@ type
CustomSounds: array of TCustomSoundEntry;
+ function FFMPeg_StreamCreateFile(abool : boolean; aFileName : pchar ): THandle;
+
Loaded: boolean;
Loop: boolean;
public
@@ -101,7 +143,6 @@ type
//Custom Sounds
function LoadCustomSound(const Filename: String): Cardinal;
procedure PlayCustomSound(const Index: Cardinal);
-
end;
const
@@ -202,6 +243,11 @@ uses
{$IFDEF FPC}
lclintf,
{$ENDIF}
+
+ avcodec,
+ avformat,
+ avutil,
+
UGraphic,
URecord,
UFiles,
@@ -265,7 +311,8 @@ begin
// LoadSoundFromFile(BassShuffle, SoundPath + 'Shuffle.mp3');
- Log.BenchmarkEnd(4); Log.LogBenchmark('--> Loading Sounds', 4);
+ Log.BenchmarkEnd(4);
+ Log.LogBenchmark('--> Loading Sounds', 4);
end;
procedure TMusic.InitializeRecord;
@@ -663,14 +710,19 @@ function TMusic.LoadSoundFromFile(var hStream: hStream; Name: string): boolean;
var
L: Integer;
begin
- if FileExists(Name) then begin
+ if FileExists(Name) then
+ begin
Log.LogStatus('Loading Sound: "' + Name + '"', 'LoadSoundFromFile');
try
{$IFDEF useBASS}
// TODO : jb_linux replace with something other than bass
hStream := BASS_StreamCreateFile(False, pchar(Name), 0, 0, 0);
+ {$ELSE}
+ hStream := FFMPeg_StreamCreateFile(False, pchar(Name) );
{$ENDIF}
+
+
//Add CustomSound
L := High(CustomSounds) + 1;
SetLength (CustomSounds, L + 1);
@@ -679,7 +731,9 @@ begin
except
Log.LogError('Failed to open using BASS', 'LoadSoundFromFile');
end;
- end else begin
+ end
+ else
+ begin
Log.LogError('Sound not found: "' + Name + '"', 'LoadSoundFromFile');
exit;
end;
@@ -735,4 +789,47 @@ begin
end;
+{*
+
+Sorry guys... this is my mess :(
+Im going to try and get ffmpeg to handle audio playback ( at least for linux )
+and Im going to implement it nicly along side BASS, in TMusic ( where I can )
+
+http://www.dranger.com/ffmpeg/ffmpeg.html
+http://www.dranger.com/ffmpeg/ffmpegtutorial_all.html
+
+http://www.inb.uni-luebeck.de/~boehme/using_libavcodec.html
+
+*}
+function TMusic.FFMPeg_StreamCreateFile(abool : boolean; aFileName : pchar ): THandle;
+var
+ lFormatCtx : PAVFormatContext;
+begin
+
+(*
+ if(SDL_OpenAudio(&wanted_spec, &spec) < 0)
+ begin
+ fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError());
+ writeln( 'SDL_OpenAudio' );
+ exit;
+ end;
+*)
+
+(*
+ if ( av_open_input_file( lFormatCtx, aFileName, NULL, 0, NULL ) <> 0 )
+ begin
+ writeln( 'Unable to open file '+ aFileName );
+ exit;
+ end;
+
+ // Retrieve stream information
+ if ( av_find_stream_info(pFormatCtx) < 0 )
+ begin
+ writeln( 'Unable to Retrieve stream information' );
+ exit;
+ end;
+*)
+
+end;
+
end.