6 #include "rpage/aos/inc.prl" 8 #include <intuition/intuition.h> 9 #include <graphics/gfxbase.h> 10 #include <hardware/dmabits.h> 11 #include <hardware/intbits.h> 12 #include <hardware/custom.h> 13 #include <graphics/gfxmacros.h> 32 struct Library *PTReplayBase = NULL;
33 struct Module *protracker_mod_playing = NULL;
34 UBYTE *protracker_mod_data = NULL;
35 ULONG protracker_mod_size = 0;
36 BYTE protracker_SigBit;
37 ULONG protracker_SigMask;
39 short protracker_mod_volume = 0;
40 short protracker_fade_min_volume = 0;
41 short protracker_fade_max_volume = 0;
42 short protracker_fade_speed = 0;
47 extern struct ExecBase *SysBase;
48 extern struct DosLibrary *
DOSBase;
49 extern struct Custom far custom;
51 BOOL init_protracker_player(
void)
53 #ifdef DEBUG_ENABLE_AUDIO 54 if (SysBase->LibNode.lib_Version >= 36)
55 if (!AssignPath(
"Libs",
"Libs"))
56 printf(
"/!\\Cannot assign local Libs: folder. The Ptreplay library might not load properly!\n");
58 if (!(PTReplayBase = OpenLibrary((
UBYTE *)
"ptreplay.library", 0)))
65 protracker_fade_speed = 0;
66 protracker_fade_min_volume = 0;
67 protracker_fade_max_volume = 64;
68 protracker_mod_volume = protracker_fade_max_volume;
76 void uninit_protracker_player(
void)
78 #ifdef DEBUG_ENABLE_AUDIO 79 unload_protacker_music();
83 CloseLibrary(PTReplayBase);
89 void load_protacker_music(
char *filename,
int filesize)
91 #ifdef DEBUG_ENABLE_AUDIO 94 filesize = file_get_size(filename);
95 printf(
"load_protacker_music(), guessed module file size : %d\n", filesize);
98 protracker_mod_data = load_raw_to_mem((
UBYTE *)filename, (
ULONG)filesize,
TRUE);
99 protracker_mod_size = filesize;
100 printf(
"load_protacker_music(%s) loaded at %x.\n", filename, (
unsigned int)protracker_mod_data);
104 void save_protracker_music(
char *filename)
106 #ifdef DEBUG_ENABLE_AUDIO 108 if (protracker_mod_data != NULL)
117 void load_imploded_protracker_music(
char *filename,
UBYTE *unpacking_sample_buffer,
char *asset_path)
119 #ifdef DEBUG_ENABLE_AUDIO 120 int unpacked_block_size, packed_block_size, i;
121 BYTE *packed_block, *unpacked_block, *smpl_list_ptr, *smpl_ptr_save;
127 if ((fileHandle = Open(filename, MODE_OLDFILE)))
129 Read(fileHandle, &tag, 4);
130 if (strncmp(tag,
"IMPK", 4) == 0)
132 Read(fileHandle, &tag, 4);
133 if (strncmp(tag,
"SIZE", 4) == 0)
135 Read(fileHandle, &unpacked_block_size, 4);
136 unpacked_block = AllocMem(unpacked_block_size, MEMF_CHIP);
138 Read(fileHandle, &tag, 4);
139 if (strncmp(tag,
"MINZ", 4) == 0)
141 Read(fileHandle, &tag, 4);
142 if (strncmp(tag,
"SIZE", 4) == 0)
144 Read(fileHandle, &packed_block_size, 4);
145 packed_block = AllocMem(packed_block_size, 0L);
146 Read(fileHandle, packed_block, packed_block_size);
148 printf(
"!!!!MINIZ block size: %d\n", packed_block_size);
151 FreeMem(packed_block, packed_block_size);
154 smpl_list_ptr = unpacked_block;
155 while((
int)(smpl_list_ptr - unpacked_block) < unpacked_block_size && strncmp(smpl_list_ptr,
"SMPL", 4))
158 smpl_ptr_save = smpl_list_ptr;
161 for(i = 0; i < 32; i++)
164 if (smpl_list_ptr[0] | smpl_list_ptr[1] | smpl_list_ptr[2] | smpl_list_ptr[3])
166 spl_files[i] = (
char *)calloc(5,
sizeof(
char));
167 strncpy(spl_files[i], smpl_list_ptr, 4);
168 printf(
"Sample #%d: '%s.pak'.\n", i, spl_files[i]);
178 smpl_list_ptr = smpl_ptr_save;
180 for(i = 0; i < 32; i++)
188 sprintf(_file,
"%s%s.pak", asset_path, spl_files[i]);
189 sfx = LoadPackedSound(_file, unpacking_sample_buffer, smpl_list_ptr);
190 smpl_list_ptr += sfx->FileLength;
191 printf(
"Sample #%d: '%s.pak, %X bytes'.\n", i, spl_files[i], sfx->FileLength);
192 RemoveSoundStruct(sfx);
196 protracker_mod_data = unpacked_block;
197 protracker_mod_size = unpacked_block_size;
210 void load_packed_protacker_music(
char *filename)
212 #ifdef DEBUG_ENABLE_AUDIO 213 int unpacked_block_size, packed_block_size;
217 BYTE *packed_block, *unpacked_block;
219 if ((fileHandle = Open(filename, MODE_OLDFILE)))
221 Read(fileHandle, &tag, 4);
222 if (strncmp(tag,
"PTPK", 4) == 0)
225 Read(fileHandle, &unpacked_block_size, 4);
226 unpacked_block = AllocMem(unpacked_block_size, MEMF_CHIP);
228 Read(fileHandle, &tag, 4);
229 if (strncmp(tag,
"MINZ", 4) == 0)
231 Read(fileHandle, &tag, 4);
232 if (strncmp(tag,
"SIZE", 4) == 0)
234 Read(fileHandle, &packed_block_size, 4);
235 packed_block = AllocMem(packed_block_size, 0L);
236 Read(fileHandle, packed_block, packed_block_size);
238 printf(
"!!!!MINIZ block size: %d\n", packed_block_size);
241 FreeMem(packed_block, packed_block_size);
246 else if (strncmp(tag,
"SHRK", 4) == 0)
248 Read(fileHandle, &tag, 4);
249 if (strncmp(tag,
"SIZE", 4) == 0)
251 Read(fileHandle, &packed_block_size, 4);
252 packed_block = AllocMem(packed_block_size, 0L);
253 Read(fileHandle, packed_block, packed_block_size);
255 printf(
"!!!!SHRK block size: %d\n", packed_block_size);
257 ShrinklerDecompress(packed_block, unpacked_block, NULL, NULL);
258 FreeMem(packed_block, packed_block_size);
263 else if (strncmp(tag,
"NRV2", 4) == 0)
265 Read(fileHandle, &tag, 4);
266 if (strncmp(tag,
"SIZE", 4) == 0)
268 Read(fileHandle, &packed_block_size, 4);
269 packed_block = AllocMem(packed_block_size, 0L);
270 Read(fileHandle, packed_block, packed_block_size);
272 printf(
"!!!!NRV2X block size: %d\n", packed_block_size);
274 nrv2s_unpack(packed_block, unpacked_block);
275 FreeMem(packed_block, packed_block_size);
283 FreeMem(unpacked_block, unpacked_block_size);
284 unpacked_block = NULL;
285 unpacked_block_size = 0;
291 printf(
"!Not a Protracker Packed File!\n");
296 protracker_mod_data = unpacked_block;
297 protracker_mod_size = unpacked_block_size;
301 void unload_protacker_music(
void)
303 #ifdef DEBUG_ENABLE_AUDIO 304 if (protracker_mod_data != NULL && protracker_mod_playing != NULL)
307 PTStop(protracker_mod_playing);
310 FreeSignal(protracker_SigBit);
314 FreeMem(protracker_mod_data, protracker_mod_size);
316 protracker_mod_playing = NULL;
317 protracker_mod_data = NULL;
322 void play_protracker_music(
void)
324 #ifdef DEBUG_ENABLE_AUDIO 326 if (protracker_mod_data != NULL && protracker_mod_playing == NULL)
328 if((protracker_SigBit=AllocSignal(-1)) != -1)
330 protracker_mod_playing =
PTSetupMod((APTR)protracker_mod_data);
331 PTInstallBits(protracker_mod_playing, protracker_SigBit, -1, -1, -1);
332 PTSetVolume(protracker_mod_playing, protracker_mod_volume);
333 PTPlay(protracker_mod_playing);
336 printf(
"play_protracker_music() Couldn't allocate signal!\n");
344 void protracker_update_state(
void)
346 #ifdef DEBUG_ENABLE_AUDIO 349 if (protracker_mod_data != NULL)
351 if (protracker_fade_speed != 0)
353 protracker_mod_volume =
min(protracker_fade_max_volume,
max(protracker_fade_min_volume, protracker_mod_volume + protracker_fade_speed));
354 PTSetVolume(protracker_mod_playing, protracker_mod_volume);
355 if (protracker_auto_stop && protracker_mod_volume <= 0)
356 unload_protacker_music();
363 void protracker_set_fade_speed(
short fade_speed)
365 #ifdef DEBUG_ENABLE_AUDIO 366 protracker_fade_speed = fade_speed;
const char * err_unknown_tag
ULONG PTStop(struct Module *)
void rpage_file_close(rpage_file file)
Close a current file.
void PTFreeMod(struct Module *)
const char * err_no_size_found
struct Module * PTSetupMod(APTR)
rpage_file rpage_file_open(char *filename, long mode)
void rpage_system_alert(char *alert_message)
Opens a GURU MEDITATION message.
void PTInstallBits(struct Module *, BYTE, BYTE, BYTE, BYTE)
VOID PTSetVolume(struct Module *, UBYTE)
struct DosLibrary * DOSBase
size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags)
long rpage_file_write(rpage_file file, void *buffer, long len)
Write a data buffer into the file.
ULONG PTPlay(struct Module *)