29#include "debug_printf.h"
55 buffer = AllocSysMemory(ALLOC_FIRST,
sizeof(
adpcm_list_t), NULL);
68 for (p = adpcm_list_head; p != NULL; p = q)
74 adpcm_list_head = NULL;
75 adpcm_list_tail = NULL;
106 parent->next = adpcm->next;
108 if (adpcm_list_head == adpcm)
109 adpcm_list_head = adpcm->next;
111 if (adpcm_list_tail == adpcm)
112 adpcm_list_tail = parent;
116 FreeSysMemory(adpcm);
149 adpcm->pitch = buffer[2];
150 adpcm->loop = (buffer[1] >> 16) & 0xFF;
151 adpcm->channels = (buffer[1] >> 8) & 0xFF;
167 int spu2_addr = 0x5010;
168 if (adpcm_list_tail != NULL)
170 spu2_addr = adpcm_list_tail->spu2_addr + adpcm_list_tail->size;
172 if (spu2_addr + size - 16 > 2097152)
174 sbuffer[0] = -AUDSRV_ERR_OUT_OF_MEMORY;
180 adpcm->spu2_addr = spu2_addr;
181 adpcm->size = size - 16;
186 if (adpcm_list_head == NULL)
189 adpcm_list_head = adpcm;
190 adpcm_list_tail = adpcm_list_head;
195 adpcm_list_tail->next = adpcm;
196 adpcm_list_tail = adpcm;
200 sceSdVoiceTrans(AUDSRV_VOICE_DMA_CH, SD_TRANS_WRITE | SD_TRANS_MODE_DMA, ((u8*)buffer)+16, (u32*)adpcm->spu2_addr, adpcm->size);
201 sceSdVoiceTransStatus(AUDSRV_VOICE_DMA_CH, 1);
205 sbuffer[1] = adpcm->pitch;
206 sbuffer[2] = adpcm->loop;
207 sbuffer[3] = adpcm->channels;
219 endx = sceSdGetSwitch(SD_CORE_1 | SD_SWITCH_ENDX);
220 if ((endx & (1 << ch)) != 0)
227 return AUDSRV_ERR_ARGS;
230 return a->spu2_addr == sceSdGetAddr(SD_CORE_1 | (ch << 1) | SD_VOICE_START);
233static int audsrv_adpcm_alloc_channel(
void)
238 endx = sceSdGetSwitch(SD_CORE_1 | SD_SWITCH_ENDX);
242 return -AUDSRV_ERR_NO_MORE_CHANNELS;
248 while ((channel < 0) && (i < 24))
261 return -AUDSRV_ERR_NO_MORE_CHANNELS;
287 return AUDSRV_ERR_ARGS;
291 if (ch >= 0 && ch < 24)
293 endx = sceSdGetSwitch(SD_CORE_1 | SD_SWITCH_ENDX);
294 if (!(endx & (1 << ch)))
297 return -AUDSRV_ERR_NO_MORE_CHANNELS;
304 channel = audsrv_adpcm_alloc_channel();
309 sceSdSetParam(SD_CORE_1 | (channel << 1) | SD_VPARAM_PITCH, a->pitch);
310 sceSdSetAddr(SD_CORE_1 | (channel << 1) | SD_VOICE_START, a->spu2_addr);
311 sceSdSetSwitch(SD_CORE_1 | SD_SWITCH_KON, (1 << channel));
323 printf(
"audsrv_adpcm_init()\n");
325 for (voice = 0; voice < 24; voice++)
327 sceSdSetSwitch(SD_CORE_1 | SD_SWITCH_KOFF, (1 << voice));
328 sceSdSetParam(SD_CORE_1 | (voice << 1) | SD_VPARAM_VOLL, 0x3fff);
329 sceSdSetParam(SD_CORE_1 | (voice << 1) | SD_VPARAM_VOLR, 0x3fff);
332 if (adpcm_list_head != NULL)
347int audsrv_adpcm_set_volume(
int ch,
int voll,
int volr)
352 return AUDSRV_ERR_ARGS;
355 sceSdSetParam(SD_CORE_1 | (ch << 1) | SD_VPARAM_VOLL, voll);
356 sceSdSetParam(SD_CORE_1 | (ch << 1) | SD_VPARAM_VOLR, volr);
int audsrv_is_adpcm_playing(int ch, audsrv_adpcm_t *adpcm)
#define AUDSRV_ERR_NOERROR
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)
static void audsrv_read_adpcm_header(adpcm_list_t *adpcm, const u32 *buffer)
void * audsrv_load_adpcm(u32 *buffer, int size, int id)
static adpcm_list_t * alloc_new_sample(void)
int audsrv_ch_play_adpcm(int ch, u32 id)
static adpcm_list_t * adpcm_loaded(int id)
static void free_all_samples()