2 * asap.h - public interface of the ASAP engine
4 * Copyright (C) 2005-2008 Piotr Fusik
6 * This file is part of ASAP (Another Slight Atari Player),
7 * see http://asap.sourceforge.net
9 * ASAP is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * ASAP is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with ASAP; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 #define ASAP_VERSION_MAJOR 1
33 #define ASAP_VERSION_MINOR 2
34 #define ASAP_VERSION_MICRO 0
35 #define ASAP_VERSION "1.2.0"
37 /* Short credits of the ASAP engine. */
38 #define ASAP_YEARS "2005-2008"
39 #define ASAP_CREDITS \
40 "Another Slight Atari Player (C) 2005-2008 Piotr Fusik\n" \
41 "CMC, MPT, TMC players (C) 1994-2005 Marcin Lewandowski\n" \
42 "RMT player (C) 2002-2005 Radek Sterba\n"
45 Display after the credits. */
46 #define ASAP_COPYRIGHT \
47 "This program is free software; you can redistribute it and/or modify\n" \
48 "it under the terms of the GNU General Public License as published\n" \
49 "by the Free Software Foundation; either version 2 of the License,\n" \
50 "or (at your option) any later version."
52 /* Useful type definitions. */
60 typedef unsigned char byte
;
62 /* Information about a file. */
64 char author
[128]; /* author's name */
65 char name
[128]; /* title */
66 char date
[128]; /* creation date */
67 int channels
; /* 1 for mono or 2 for stereo */
68 int songs
; /* number of subsongs */
69 int default_song
; /* 0-based index of the "main" subsong */
70 int durations
[32]; /* lengths of songs, in milliseconds, -1 = unspecified */
71 abool loops
[32]; /* whether songs repeat or not */
72 /* the following technical information should not be used outside ASAP. */
83 Not for use outside the ASAP engine. */
120 signed char delta_buffer
[888];
124 Only module_info is meant to be read outside the ASAP engine. */
136 int nearest_event_cycle
;
137 int next_scanline_cycle
;
142 int extra_pokey_mask
;
143 PokeyState base_pokey
;
144 PokeyState extra_pokey
;
150 ASAP_ModuleInfo module_info
;
152 int tmc_per_frame_counter
;
154 int current_duration
;
157 int silence_cycles_counter
;
158 byte poly9_lookup
[511];
159 byte poly17_lookup
[16385];
163 /* Maximum length of a "mm:ss.xxx" string including the terminator. */
164 #define ASAP_DURATION_CHARS 10
166 /* Maximum length of a supported input file.
167 You can assume that files longer than this are not supported by ASAP. */
168 #define ASAP_MODULE_MAX 65000
170 /* Output sample rate. */
171 #define ASAP_SAMPLE_RATE 44100
173 /* Output formats. */
175 ASAP_FORMAT_U8
= 8, /* unsigned char */
176 ASAP_FORMAT_S16_LE
= 16, /* signed short, little-endian */
177 ASAP_FORMAT_S16_BE
= -16 /* signed short, big-endian */
180 /* Parses the string in the "mm:ss.xxx" format
181 and returns the number of milliseconds or -1 if an error occurs. */
182 int ASAP_ParseDuration(const char *s
);
184 /* Converts number of milliseconds to a string in the "mm:ss.xxx" format. */
185 void ASAP_DurationToString(char *s
, int duration
);
187 /* Checks whether the extension of the passed filename is known to ASAP. */
188 abool
ASAP_IsOurFile(const char *filename
);
190 /* Checks whether the filename extension is known to ASAP. */
191 abool
ASAP_IsOurExt(const char *ext
);
193 /* Changes the filename extension, returns true on success. */
194 abool
ASAP_ChangeExt(char *filename
, const char *ext
);
196 /* Gets information about a module.
197 "module_info" is the structure where the information is returned.
198 "filename" determines file format.
199 "module" is the music data (contents of the file).
200 "module_len" is the number of data bytes.
201 ASAP_GetModuleInfo() returns true on success. */
202 abool
ASAP_GetModuleInfo(ASAP_ModuleInfo
*module_info
, const char *filename
,
203 const byte module
[], int module_len
);
206 "as" is the destination structure.
207 "filename" determines file format.
208 "module" is the music data (contents of the file).
209 "module_len" is the number of data bytes.
210 ASAP does not make copies of the passed pointers. You can overwrite
211 or free "filename" and "module" once this function returns.
212 ASAP_Load() returns true on success.
213 If false is returned, the structure is invalid and you cannot
214 call the following functions. */
215 abool
ASAP_Load(ASAP_State
*as
, const char *filename
,
216 const byte module
[], int module_len
);
218 /* Enables silence detection.
219 Makes ASAP finish playing after the specified period of silence.
220 "as" is ASAP state initialized by ASAP_Load().
221 "seconds" is the minimum length of silence that ends playback. */
222 void ASAP_DetectSilence(ASAP_State
*as
, int seconds
);
224 /* Prepares ASAP to play the specified song of the loaded module.
225 "as" is ASAP state initialized by ASAP_Load().
226 "song" is a zero-based index which must be less than the "songs" field
227 of the ASAP_ModuleInfo structure.
228 "duration" is playback time in milliseconds - use durations[song]
229 unless you want to override it. -1 means indefinitely. */
230 void ASAP_PlaySong(ASAP_State
*as
, int song
, int duration
);
232 /* Mutes the selected POKEY channels.
233 This is only useful for people who want to grab samples of individual
235 "as" is ASAP state after calling ASAP_PlaySong().
236 "mask" is a bit mask which selects POKEY channels to be muted.
237 Bits 0-3 control the base POKEY channels,
238 bits 4-7 control the extra POKEY channels. */
239 void ASAP_MutePokeyChannels(ASAP_State
*as
, int mask
);
241 /* Rewinds the current song.
242 "as" is ASAP state initialized by ASAP_PlaySong().
243 "position" is the requested absolute position in milliseconds. */
244 void ASAP_Seek(ASAP_State
*as
, int position
);
246 /* Fills the specified buffer with generated samples.
247 "as" is ASAP state initialized by ASAP_PlaySong().
248 "buffer" is the destination buffer.
249 "buffer_len" is the length of this buffer in bytes.
250 "format" is the format of samples.
251 ASAP_Generate() returns number of bytes actually written
252 (less than buffer_len if reached the end of the song).
253 Normally you use a buffer of a few kilobytes or less,
254 and call ASAP_Generate() in a loop or via a callback. */
255 int ASAP_Generate(ASAP_State
*as
, void *buffer
, int buffer_len
,
256 ASAP_SampleFormat format
);
258 /* Checks whether information in the specified file can be edited. */
259 abool
ASAP_CanSetModuleInfo(const char *filename
);
261 /* Updates the specified module with author, name, date, stereo
262 and song durations as specified in "module_info".
263 "module_info" contains the new module information.
264 "module" is the source file contents.
265 "module_len" is the source file length.
266 "out_module" is the destination buffer of size ASAP_MODULE_MAX.
267 ASAP_SetModuleInfo() returns the resulting file length (number of bytes
268 written to "out_module") or -1 if illegal characters were found. */
269 int ASAP_SetModuleInfo(const ASAP_ModuleInfo
*module_info
, const byte module
[],
270 int module_len
, byte out_module
[]);
272 /* Checks whether the specified module can be converted to another format.
273 "filename" determines the source format.
274 "module_info" contains the information about the source module,
275 with possibly modified public fields.
276 "module" is the source file contents.
277 "module_len" is the source file length.
278 ASAP_CanConvert() returns the extension of the target format
279 or NULL if there's no possible conversion. */
280 const char *ASAP_CanConvert(const char *filename
, const ASAP_ModuleInfo
*module_info
,
281 const byte module
[], int module_len
);
283 /* Converts the specified module to the format returned by ASAP_CanConvert().
284 "filename" determines the source format.
285 "module_info" contains the information about the source module,
286 with possibly modified public fields.
287 "module" is the source file contents.
288 "module_len" is the source file length.
289 "out_module" is the destination buffer of size ASAP_MODULE_MAX.
290 ASAP_Convert() returns the resulting file length (number of bytes
291 written to "out_module") or -1 on error. */
292 int ASAP_Convert(const char *filename
, const ASAP_ModuleInfo
*module_info
,
293 const byte module
[], int module_len
, byte out_module
[]);