source: trunk/Packages/uos/uos_opusurl.pas

Last change on this file was 664, checked in by chronos, 3 days ago
  • Added: Ability to play music in background in start screen and in-game. Used uos as audio library.
  • Property svn:executable set to *
File size: 2.2 KB
Line 
1{This unit is part of United Openlibraries of Sound (uos)}
2
3{This is the Pascal Wrapper + Dynamic loading of OpusURL library.
4 Load library with ou_load() and release with ou_unload().
5 License : modified LGPL.
6 Fred van Stappen / fiens@hotmail.com}
7
8unit uos_Opusurl;
9
10{$mode objfpc}{$H+}
11
12interface
13
14uses
15 ctypes, uos_Opusfile, dynlibs, SysUtils;
16
17// Error Codes
18const
19 OP_FALSE = -1;
20 OP_HOLE = -3;
21 OP_EREAD = -128;
22 OP_EFAULT = -129;
23 OP_EIMPL = -130;
24 OP_EINVAL = -131;
25 OP_ENOTVORBIS = -132;
26 OP_EBADHEADER = -133;
27 OP_EVERSION = -134;
28 OP_ENOTAUDIO = -135;
29 OP_EBADPACKET = -136;
30 OP_EBADLINK = -137;
31 OP_ENOSEEK = -138;
32 OP_EBADTIMESTAMP = -139;
33
34var
35
36 op_open_url: function(path: PAnsiChar; out error: Integer): TOpusFile;
37 op_test_url: function(path: PAnsiChar; out error: Integer): TOpusFile;
38
39 ou_Handle:TLibHandle=dynlibs.NilHandle;
40
41 ReferenceCounter : cardinal = 0; // Reference counter
42
43 function ou_IsLoaded : boolean; inline;
44
45 Function ou_Load(const libfilename:string) :boolean; // load the lib
46
47 Procedure ou_Unload;
48
49implementation
50
51 function ou_IsLoaded: boolean;
52begin
53 Result := (ou_Handle <> dynlibs.NilHandle);
54end;
55
56Procedure ou_Unload;
57begin
58// < Reference counting
59 if ReferenceCounter > 0 then
60 dec(ReferenceCounter);
61 if ReferenceCounter > 0 then
62 exit;
63 // >
64 if ou_IsLoaded then
65 begin
66 DynLibs.UnloadLibrary(ou_Handle);
67 ou_Handle:=DynLibs.NilHandle;
68 end;
69end;
70
71Function ou_Load (const libfilename:string) :boolean;
72begin
73 Result := False;
74 if ou_Handle<>0 then
75begin
76 Inc(ReferenceCounter);
77 result:=true {is it already there ?}
78end else
79begin {go & load the library}
80 if Length(libfilename) = 0 then exit;
81 ou_Handle:=DynLibs.SafeLoadLibrary(libfilename); // obtain the handle we want
82 if ou_Handle <> DynLibs.NilHandle then
83begin {now we tie the functions to the VARs from above}
84Pointer(op_open_url):=DynLibs.GetProcedureAddress(OU_Handle,PChar('op_open_url'));
85Pointer(op_test_url):=DynLibs.GetProcedureAddress(OU_Handle,PChar('op_test_url'));
86end;
87 Result := ou_IsLoaded;
88 ReferenceCounter:=1;
89end;
90
91end;
92
93end.
Note: See TracBrowser for help on using the repository browser.