aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Game/Code/Classes')
-rw-r--r--Game/Code/Classes/UMusic.pas107
-rw-r--r--Game/Code/Classes/UTime.pas11
2 files changed, 113 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.
diff --git a/Game/Code/Classes/UTime.pas b/Game/Code/Classes/UTime.pas
index d06628cc..c197a70f 100644
--- a/Game/Code/Classes/UTime.pas
+++ b/Game/Code/Classes/UTime.pas
@@ -43,6 +43,17 @@ uses
// who knows how fast or slow that function is !
// but this gets a compile for now .. :)
+(*
+msec( )
+{
+ struct timeval tv;
+ gettimeofday( &tv, NULL );
+ return (int64_t)tv.tv_sec * (int64_t)1000000 + (int64_t)tv.tv_usec;
+}
+
+*)
+
+
constructor TTime.Create;
begin
CountSkipTimeSet;