11#include "irx_imports.h"
18#define MODNAME "AHXplayer"
19#define MODVERSION "1.0b"
20#define MODAUTHOR "Raizor"
21#define M_PRINTF(format, args...) printf(MODNAME ": " format, ##args)
36#define AHX_IRX 0xC001D0E
41#define AHX_LOADSONG 0x05
42#define AHX_SETVOLUME 0x06
43#define AHX_SETBOOST 0x07
44#define AHX_OVERSAMPLE 0x08
45#define AHX_SUBSONG 0x09
46#define TH_C 0x02000000
53int oversample_enabled = 0;
54u16 SPU2_Volume = 0x3fff;
55char mod_buffer[50 * 1024];
60extern void wmemcpy(
void *dest,
void *src,
int numwords);
61static unsigned int buffer[0x80]
__attribute__((__aligned__(4)));
64void AHX_Thread(
void *param);
65void AHX_PlayThread(
void *param);
66static int AHX_TransCallback(
void *param);
67void AHX_SetVol(u16 vol);
68void AHX_ResetPlayThread();
69void AHX_ClearSoundBuffers();
70void *AHX_rpc_server(
unsigned int funcno,
void *data,
int size);
87int _start(
int argc,
char *argv[])
99 param.thread = AHX_Thread;
101 param.stacksize = 0x800;
103 th = CreateThread(¶m);
106 return MODULE_RESIDENT_END;
108 return MODULE_NO_RESIDENT_END;
120void AHX_Thread(
void *param)
131 transfer_sema = CreateSema(&sema);
134 if (transfer_sema <= 0) {
136 M_PRINTF(
"FATAL - Failed to create semaphore!\n");
142 spubuf = AllocSysMemory(0, 0x800, NULL);
143 pcmbuf = AllocSysMemory(0, 0xF00 * 8, NULL);
144 if (spubuf == NULL) {
146 M_PRINTF(
"FATAL - Failed to allocate memory for sound buffer!\n");
153 M_PRINTF(
"AHXplayer %s Started\n", MODVERSION);
156 AHX_ClearSoundBuffers();
159 M_PRINTF(
"Memory Allocated. %d bytes left.\n", QueryTotalFreeMemSize());
164 SifSetRpcQueue(&qd, GetThreadId());
165 SifRegisterRpc(&Sd0, AHX_IRX, (
void *)AHX_rpc_server, (
void *)&buffer[0], 0, 0, &qd);
176void AHX_PlayThread(
void *param)
184 AHX_ResetPlayThread();
192 for (i = 0; i < 7; i++) {
194 if (readpos >= 0xF00 * (i + 1) && readpos <= 0xF00 * (i + 2) && !seg_done[i]) {
196 AHXOutput_MixBuffer((
short *)(pcmbuf + (0xF00 * i)));
208 WaitSema(transfer_sema);
216 chunk = 1 - (sceSdBlockTransStatus(1, 0) >> 24);
218 wmemcpy(spubuf + (1024 * chunk), pcmbuf + readpos, 512);
219 wmemcpy(spubuf + (1024 * chunk) + 512, pcmbuf + readpos, 512);
228 if (readpos >= 0xF00 * 8) {
230 AHXOutput_MixBuffer((
short *)(pcmbuf + (0xF00 * 7)));
245static int AHX_TransCallback(
void *param)
252 iSignalSema(transfer_sema);
261void AHX_SetVol(u16 vol)
263 sceSdSetParam(SD_CORE_1 | SD_PARAM_BVOLL, vol);
264 sceSdSetParam(SD_CORE_1 | SD_PARAM_BVOLR, vol);
271void AHX_ResetPlayThread()
276 for (i = 0; i < 8; i++) {
288void AHX_ClearSoundBuffers()
291 memset(spubuf, 0, 0x800);
292 memset(pcmbuf, 0, 0xF00 * 8);
301void *AHX_rpc_server(
unsigned int funcno,
void *data,
int size)
341 printf(
"AHX INIT DONE!\n");
345 sceSdInit(SD_INIT_COLD);
348 sceSdSetParam(SD_CORE_1 | SD_PARAM_MVOLL, 0x3fff);
349 sceSdSetParam(SD_CORE_1 | SD_PARAM_MVOLR, 0x3fff);
352 sceSdBlockTrans(1, SD_TRANS_LOOP, spubuf, 0x800, 0);
355 sceSdSetTransCallback(1, (
void *)AHX_TransCallback);
365 StartThread(play_tid, 0);
368 M_PRINTF(
"FATAL - Failed to start playing thread!\n");
377 sbuff[1] = (unsigned)mod_buffer;
394 AHX_ResetPlayThread();
397 printf(
"Loading song - oversampling = %d, boost = %d\n", oversample_enabled, boost_val);
401 sbuff[1] = (unsigned)AHXPlayer_LoadSongBuffer(mod_buffer, (
int)sbuff[0]);
404 WaitSema(transfer_sema);
406 AHX_ClearSoundBuffers();
409 AHXPlayer_InitSubsong(0);
414 M_PRINTF(
"Memory Allocated. %d bytes left.\n", QueryTotalFreeMemSize());
426 AHX_SetVol(SPU2_Volume);
448 SPU2_Volume = (u16)(0x3fff * (u16)sbuff[1]) / 100;
449 AHX_SetVol(SPU2_Volume);
461 boost_val = (int)sbuff[0];
462 AHXPlayer_SetBoost(boost_val);
474 oversample_enabled = oversample_enabled ? 0 : 1;
475 AHXPlayer_SetOversampling(oversample_enabled);
487 AHXPlayer_InitSubsong((
int)sbuff[0]);
497 sceSdSetTransCallback(1, NULL);
498 sceSdBlockTrans(1, SD_TRANS_STOP, 0, 0, 0);
500 TerminateThread(play_tid);
501 DeleteThread(play_tid);
503 DeleteSema(transfer_sema);
int AHX_SetBoost(int boostValue)
int AHX_SetVolume(int volumePercentage)
int AHX_SubSong(int songNo)
int AHX_ToggleOversampling()
int AHX_LoadSong(char *filename)
static void play_thread(void *arg)
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)