Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | daniel-mar | 1 | (* |
2 | * This unit is free software; you can redistribute it and modify it |
||
3 | * under the terms of the GNU Library General Public License as published |
||
4 | * by the Free Software Foundation; either version 2 of the license or |
||
5 | * (at your option) any later version. |
||
6 | * |
||
7 | * Author of CPP header file : Olivier Lapicque <olivierl@jps.net> |
||
8 | * Author of Delphi conversion : Dean Ellis <Dean_Ellis@sillex.freeserve.co.uk> |
||
9 | * |
||
10 | * NOTE : The Origonal C++ Class declarations anc constants have been left in place |
||
11 | * |
||
12 | *) |
||
13 | unit MpSndSys; |
||
14 | |||
15 | interface |
||
16 | |||
17 | uses Windows,Classes; |
||
18 | |||
19 | const |
||
20 | //#ifndef MPP_SND_SYS_H |
||
21 | //#define MPP_SND_SYS_H |
||
22 | |||
23 | //#ifndef MPPDLLEXPORT |
||
24 | //#define MPPDLLEXPORT |
||
25 | //#endif |
||
26 | |||
27 | //#define MPPAPI __stdcall |
||
28 | //#define MPPCDECL __cdecl |
||
29 | //#define MPPAPI_VERSION 0x0140 |
||
30 | |||
31 | //#define MPPAPI_VERSION 0x0140 |
||
32 | |||
33 | MPPAPI_VERSION = $0141; |
||
34 | |||
35 | // Version-specific functions |
||
36 | //#define MPPVERSION_HAS_NAVIGATION 0x0139 |
||
37 | //#define MPPVERSION_HAS_SONGTIME 0x0141 |
||
38 | |||
39 | MPPVERSION_HAS_NAVIGATION = $0139; |
||
40 | MPPVERSION_HAS_SONGTIME = $0141; |
||
41 | |||
42 | // Error codes |
||
43 | //typedef long MPPERR; |
||
44 | // |
||
45 | //enum { |
||
46 | // MPPERR_NOERROR=0, |
||
47 | // MPPERR_FAILED, |
||
48 | // MPPERR_INVALIDPARAM, |
||
49 | //}; |
||
50 | |||
51 | //enum { |
||
52 | // MPPSONG_INVALID=0, |
||
53 | // MPPSONG_MOD, |
||
54 | // MPPSONG_S3M, |
||
55 | // MPPSONG_XM, |
||
56 | // MPPSONG_IT, |
||
57 | // MPPSONG_MDL, |
||
58 | // MPPSONG_UNKNOWN=100 |
||
59 | //}; |
||
60 | MPPERR_NOERROR = 0; |
||
61 | MPPERR_FAILED = 1; |
||
62 | MPPERR_INVALIDPARAM = 2; |
||
63 | |||
64 | MPPSONG_INVALID = 0; |
||
65 | MPPSONG_MOD = 1; |
||
66 | MPPSONG_S3M = 2; |
||
67 | MPPSONG_XM = 3; |
||
68 | MPPSONG_IT = 4; |
||
69 | MPPSONG_MDL = 5; |
||
70 | MPPSONG_UNKNOWN = 100; |
||
71 | |||
72 | // Mixer Options MPPMIX_XXXX |
||
73 | //#define MPPMIX_NORESAMPLING 0x01 // Faster, but crappy quality |
||
74 | //#define MPPMIX_BASSEXPANSION 0x02 // Bass Expansion |
||
75 | //#define MPPMIX_SURROUND 0x04 // Surround Encoding |
||
76 | //#define MPPMIX_REVERB 0x08 // Reverb |
||
77 | //#define MPPMIX_LOOP 0x10 // Loop the song (backward jumps will be enabled) |
||
78 | //// v1.40+ flags |
||
79 | //#define MPPMIX_HIGHQUALITY 0x20 // HQ mixing (better resampling, dithering enabled) |
||
80 | //#define MPPMIX_GAINCONTROL 0x40 // Automatic Gain Control |
||
81 | //#define MPPMIX_NOISEREDUCTION 0x80 // Noise reduction (-6dB 22kHz lowpass filter) |
||
82 | |||
83 | MPPMIX_NORESAMPLING = $01; // Faster, but crappy quality |
||
84 | MPPMIX_BASSEXPANSION = $02; // Bass Expansion |
||
85 | MPPMIX_SURROUND = $04; // Surround Encoding |
||
86 | MPPMIX_REVERB = $08; // Reverb |
||
87 | MPPMIX_LOOP = $10; // Loop the song (backward jumps will be enabled) |
||
88 | // v1.40+ flags |
||
89 | MPPMIX_HIGHQUALITY = $20; // HQ mixing (better resampling, dithering enabled) |
||
90 | MPPMIX_GAINCONTROL = $40; // Automatic Gain Control |
||
91 | MPPMIX_NOISEREDUCTION = $80; // Noise reduction (-6dB 22kHz lowpass filter) |
||
92 | |||
93 | type |
||
94 | //========================== |
||
95 | //class MPPDLLEXPORT IModMixer |
||
96 | //========================== |
||
97 | (* { |
||
98 | public: |
||
99 | // Reference count: the initial reference count is 1, so you shouldn't have to call AddRef() |
||
100 | virtual unsigned long MPPAPI AddRef() = 0; |
||
101 | virtual unsigned long MPPAPI Release() = 0; |
||
102 | |||
103 | // API Version: you should refuse to continue if the returned value is smaller than MPPAPI_VERSION |
||
104 | virtual unsigned long MPPAPI GetVersion() = 0; |
||
105 | |||
106 | // Basic I/O Functions |
||
107 | virtual MPPERR MPPAPI LoadSong(const void *pmemfile, long len) = 0; |
||
108 | // Songs are always loaded from memory. The pointer pmemfile can be destroyed |
||
109 | // after the call to LoadSong. You can use memory-mapped files or a pointer returned |
||
110 | // by LockResource(), or whatever file in memory. |
||
111 | virtual MPPERR MPPAPI FreeSong() = 0; // Free the memory used by the song |
||
112 | |||
113 | // Audio Rendering Functions: example: (44100, 2, 16) for 44.1kHz, stereo, 16-bit |
||
114 | virtual MPPERR MPPAPI SetWaveFormat(long samplespersec, long channels, long bitspersample) = 0; |
||
115 | // return # of SAMPLES that have been written to the buffer, 0 if end has been reached |
||
116 | // Note: protect calls to Render() and SetMixerOptions() by a critical section, if they |
||
117 | // are used in different threads. |
||
118 | virtual long MPPAPI Render(void *pbuffer, unsigned long bufsize) = 0; |
||
119 | |||
120 | // Player Configuration: set of MPPMIX_XXXX |
||
121 | virtual MPPERR MPPAPI SetMixerOptions(unsigned long dwOptions) = 0; |
||
122 | virtual unsigned long MPPAPI GetMixerOptions() = 0; |
||
123 | |||
124 | // Song Information |
||
125 | virtual long MPPAPI GetSongType() = 0; // Return MPPSONG_XXXX |
||
126 | virtual void MPPAPI GetSongName(char *pszbuf) = 0; // pszbuf must be at least 32-bytes |
||
127 | |||
128 | ////////////////////////////////////////////////////////////////////////////////////// |
||
129 | // v1.39+: Navigation functions |
||
130 | // The order is the position in the pattern sequence list: this allows you to |
||
131 | // jump to a specific part of a song. It can be useful in a game with a song that |
||
132 | // uses pattern position jump effects (or pattern loops). |
||
133 | // These function will not be available if GetVersion() returns a value smaller than 0x139 (MPPVERSION_HAS_NAVIGATION) |
||
134 | virtual unsigned long MPPAPI GetNumOrders() = 0; |
||
135 | virtual unsigned long MPPAPI GetCurrentOrder() = 0; |
||
136 | virtual MPPERR MPPAPI SetCurrentOrder(unsigned long neworder) = 0; |
||
137 | |||
138 | }; |
||
139 | *) |
||
140 | MppError = longint; |
||
141 | |||
142 | PModMixer = ^IModMixer; |
||
143 | IModMixer = class |
||
144 | public |
||
145 | function AddRef:longint; virtual; stdcall; abstract; |
||
146 | function Release:longint; virtual; stdcall; abstract; |
||
147 | function GetVersion:longint; virtual; stdcall; abstract; |
||
148 | function LoadSong(const MemFile:pointer;Length:longint):MppError;virtual; stdcall; abstract; |
||
149 | function FreeSong:MppError;virtual; stdcall; abstract; |
||
150 | function SetWaveFormat(SamplesPerSec,channels,bitsPerSample:longint):MppError;virtual; stdcall; abstract; |
||
151 | function Render(Buffer:pointer;BufferSize:longint):MppError;virtual; stdcall; abstract; |
||
152 | function SetMixerOptions(dwOptions:longint):MppError;virtual; stdcall; abstract; |
||
153 | function GetMixerOptions:longint;virtual; stdcall; abstract; |
||
154 | function GetSongType:longint;virtual; stdcall; abstract; |
||
155 | procedure GetSongName(Buffer:PChar);virtual; stdcall; abstract; |
||
156 | function GetNumOrders:longint;virtual; stdcall; abstract; |
||
157 | function SetCurrentOrder(newOrder:longint):MppError;virtual; stdcall; abstract; |
||
158 | function GetSongLength:longint; virtual; stdcall; abstract; |
||
159 | end; |
||
160 | |||
161 | var |
||
162 | MppSdkLibLoaded:Boolean; |
||
163 | ModMixer:IModMixer; |
||
164 | |||
165 | implementation |
||
166 | |||
167 | const MppSdkLibrary = 'mppsdk.dll'; |
||
168 | |||
169 | var MppSdkLibHandle:THandle; |
||
170 | |||
171 | //#define MPP_GETMODAPIFUNCNAME "MPP_GetModAPI" |
||
172 | //typedef MPPERR (MPPCDECL * MPP_GETMODAPIFUNC)(IModMixer **); |
||
173 | GetModAPI : function(MODMixer:PModMixer):MppError;cdecl; |
||
174 | |||
175 | (* |
||
176 | * |
||
177 | * To get a pointer to the IModMixer interface, you can use the following functions: |
||
178 | * |
||
179 | * HMODULE hMPPSDK = (HMODULE)LoadLibrary("mppsdk.dll"); |
||
180 | * MPP_GETMODAPIFUNC pFunc = (MPP_GETMODAPIFUNC)GetProcAddress(hMPPSDK, MPP_GETMODAPIFUNCNAME); |
||
181 | * IModMixer *pMPPAPI; |
||
182 | * pFunc(&pMPPAPI); |
||
183 | * ... |
||
184 | * You can then access the MPP SDK API through the IModMixer interface |
||
185 | * |
||
186 | * When you are done: |
||
187 | * |
||
188 | * pMPPAPI->Release(); |
||
189 | * FreeLibrary(hMPPSDK); |
||
190 | * |
||
191 | *) |
||
192 | |||
193 | //#endif // MPP_SND_SYS_H |
||
194 | |||
195 | |||
196 | {----------------------------------------------------------------------------} |
||
197 | {InitLibrary - will try to load the Mppsdk.dll and get the ModMixer object} |
||
198 | {----------------------------------------------------------------------------} |
||
199 | function InitLibrary:Boolean; |
||
200 | begin |
||
201 | Result := False; |
||
202 | |||
203 | MppSdkLibHandle := LoadLibrary(MppSdkLibrary); |
||
204 | |||
205 | if MppSdkLibHandle = 0 then |
||
206 | begin |
||
207 | Exit; |
||
208 | end; |
||
209 | |||
210 | try |
||
211 | GetModAPI := GetProcAddress(MppSdkLibHandle,'MPP_GetModAPI'); |
||
212 | GetModAPI(@ModMixer); |
||
213 | Result := True; |
||
214 | except |
||
215 | Result := False; |
||
216 | end; |
||
217 | end; |
||
218 | {----------------------------------------------------------------------------} |
||
219 | {UnLoadLibrary - Will unload the Mppsdk.dll if it was loaded} |
||
220 | {----------------------------------------------------------------------------} |
||
221 | procedure UnLoadLibrary; |
||
222 | begin |
||
223 | if MppSdkLibLoaded then |
||
224 | begin |
||
225 | FreeLibrary(MppSdkLibHandle); |
||
226 | end; |
||
227 | end; |
||
228 | |||
229 | {----------------------------------------------------------------------------} |
||
230 | {Automatic initialization and finalization - comment out if you want to |
||
231 | do this manually} |
||
232 | {----------------------------------------------------------------------------} |
||
233 | initialization |
||
234 | MppSdkLibLoaded:=InitLibrary; |
||
235 | finalization |
||
236 | UnloadLibrary; |
||
237 | end. |