Skip to content

Commit

Permalink
Cleanup console examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredvs committed Feb 22, 2016
1 parent 99352ea commit 368bf33
Show file tree
Hide file tree
Showing 5 changed files with 2,730 additions and 84 deletions.
83 changes: 45 additions & 38 deletions examples/consoleplay.pas
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
program consoleplay;

///WARNING : if FPC version < 2.7.1 => Do not forget to uncoment {$DEFINE ConsoleApp} in uos.pas and in uos_flat.pas !
///WARNING : if FPC version < 2.7.1 => Do not forget to uncoment {$DEFINE ConsoleApp} in define.inc !

{$mode objfpc}{$H+}
{$DEFINE UseCThreads}
uses {$IFDEF UNIX}
cthreads,
cthreads,
cwstring, {$ENDIF}
Classes,
SysUtils,
CustApp,
uos_flat,
ctypes { you can add units after this };
uos_flat;

type

Expand All @@ -23,32 +22,29 @@ TuosConsole = class(TCustomApplication)
protected
procedure doRun; override;
public
procedure Consoleclose;
constructor Create(TheOwner: TComponent); override;
end;


var
res: integer;
ordir, opath, sndfilename, PA_FileName, SF_FileName: string;
PlayerIndex1: cardinal;
In1Index : integer;

ordir, opath, SoundFilename, PA_FileName, SF_FileName: string;
PlayerIndex1 : integer;

{ TuosConsole }

procedure TuosConsole.ConsolePlay;
begin
ordir := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0)));

{$IFDEF Windows}
{$IFDEF Windows}
{$if defined(cpu64)}
PA_FileName := ordir + 'lib\Windows\64bit\LibPortaudio-64.dll';
SF_FileName := ordir + 'lib\Windows\64bit\LibSndFile-64.dll';
{$else}
{$else}
PA_FileName := ordir + 'lib\Windows\32bit\LibPortaudio-32.dll';
SF_FileName := ordir + 'lib\Windows\32bit\LibSndFile-32.dll';
{$endif}
sndfilename := ordir + 'sound\test.flac';
{$endif}
SoundFilename := ordir + 'sound\test.flac';
{$ENDIF}

{$IFDEF linux}
Expand All @@ -58,8 +54,8 @@ TuosConsole = class(TCustomApplication)
{$else}
PA_FileName := ordir + 'lib/Linux/32bit/LibPortaudio-32.so';
SF_FileName := ordir + 'lib/Linux/32bit/LibSndFile-32.so';
{$endif}
sndfilename := ordir + 'sound/test.flac';
{$endif}
SoundFilename := ordir + 'sound/test.flac';
{$ENDIF}

{$IFDEF freebsd}
Expand All @@ -69,20 +65,18 @@ TuosConsole = class(TCustomApplication)
{$else}
PA_FileName := ordir + 'lib/FreeBSD/32bit/libportaudio-32.so';
SF_FileName := ordir + 'lib/FreeBSD/32bit/libsndfile-32.so';
{$endif}
sndfilename := ordir + 'sound/test.flac';
{$endif}
SoundFilename := ordir + 'sound/test.flac';
{$ENDIF}


{$IFDEF Darwin}
{$IFDEF Darwin}
opath := ordir;
opath := copy(opath, 1, Pos('/UOS', opath) - 1);
PA_FileName := opath + '/lib/Mac/32bit/LibPortaudio-32.dylib';
SF_FileName := opath + '/lib/Mac/32bit/LibSndFile-32.dylib';
sndfilename := opath + '/sound/test.flac';
{$ENDIF}
PlayerIndex1 := 0;

SoundFilename := opath + '/sound/test.flac';
{$ENDIF}

// Load the libraries
// function uos_LoadLib(PortAudioFileName: Pchar; SndFileFileName: Pchar; Mpg123FileName: Pchar) : integer;

Expand All @@ -91,32 +85,45 @@ TuosConsole = class(TCustomApplication)
writeln('Result of loading (if 0 => ok ) : ' + IntToStr(res));

if res = 0 then begin
uos_CreatePlayer(PlayerIndex1); //// Create the player

In1Index := uos_AddFromFile(PlayerIndex1,(pchar(sndfilename)));
//// Create the player.
//// PlayerIndex : from 0 to what your computer can do !
//// If PlayerIndex exists already, it will be overwriten...

PlayerIndex1 := 0;
uos_CreatePlayer(PlayerIndex1);

uos_AddIntoDevOut(PlayerIndex1, -1, -1, uos_InputGetSampleRate(PlayerIndex1, In1Index), -1, -1, -1);
//// add a Input from audio-file with default parameters
//////////// PlayerIndex : Index of a existing Player
////////// FileName : filename of audio file
// result : -1 nothing created, otherwise Input Index in array

uos_AddFromFile(PlayerIndex1,(pchar(SoundFilename)));

//// add a Output into device with default parameters
//////////// PlayerIndex : Index of a existing Player
// result : -1 nothing created, otherwise Output Index in array

uos_AddIntoDevOut(PlayerIndex1);

/////// everything is ready, here we are, lets play it...

uos_Play(PlayerIndex1);

end;

end;
end;

procedure TuosConsole.doRun;
begin
ConsolePlay;
writeln('Press a key to exit...');
readln;
uos_unloadLib();
Terminate;
end;

procedure TuosConsole.ConsoleClose;
begin
readln;
uos_unloadLib();
Terminate;
end;

constructor TuosConsole.Create(TheOwner: TComponent);
constructor TuosConsole.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException := True;
Expand All @@ -127,6 +134,6 @@ TuosConsole = class(TCustomApplication)
begin
Application := TUOSConsole.Create(nil);
Application.Title := 'Console Player';
Application.Run;
Application.Run;
Application.Free;
end.
Loading

0 comments on commit 368bf33

Please sign in to comment.