commit
8295a173b8
|
@ -29,36 +29,38 @@ typedef struct psp1_audio
|
||||||
uint32_t* zeroBuffer;
|
uint32_t* zeroBuffer;
|
||||||
SceUID thread;
|
SceUID thread;
|
||||||
int rate;
|
int rate;
|
||||||
uint16_t readPos;
|
volatile uint16_t readPos;
|
||||||
uint16_t writePos;
|
volatile uint16_t writePos;
|
||||||
} psp1_audio_t;
|
} psp1_audio_t;
|
||||||
|
|
||||||
#define AUDIO_OUT_COUNT 128
|
#define AUDIO_OUT_COUNT 128u
|
||||||
|
#define AUDIO_BUFFER_SIZE (1u<<11u)
|
||||||
#define AUDIO_BUFFER_SIZE (1u<<12u)
|
|
||||||
#define AUDIO_BUFFER_SIZE_MASK (AUDIO_BUFFER_SIZE-1)
|
#define AUDIO_BUFFER_SIZE_MASK (AUDIO_BUFFER_SIZE-1)
|
||||||
|
|
||||||
static int audioMainLoop(SceSize args, void* argp)
|
static int audioMainLoop(SceSize args, void* argp)
|
||||||
{
|
{
|
||||||
psp1_audio_t* psp = *((psp1_audio_t**)argp);
|
psp1_audio_t* psp = *((psp1_audio_t**)argp);
|
||||||
|
|
||||||
sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);
|
sceAudioSRCChReserve(AUDIO_OUT_COUNT, psp->rate, 2);
|
||||||
|
|
||||||
while (psp->running)
|
while (psp->running)
|
||||||
{
|
{
|
||||||
if (((uint16_t)(psp->writePos - psp->readPos) & AUDIO_BUFFER_SIZE_MASK) < (uint16_t)AUDIO_OUT_COUNT * 2)
|
uint16_t readPos = psp->readPos; // get a non volatile copy
|
||||||
|
|
||||||
|
if (((uint16_t)(psp->writePos - readPos) & AUDIO_BUFFER_SIZE_MASK) < (AUDIO_OUT_COUNT * 2))
|
||||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->zeroBuffer);
|
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->zeroBuffer);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->buffer + psp->readPos);
|
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->buffer + readPos);
|
||||||
psp->readPos += AUDIO_OUT_COUNT;
|
readPos += AUDIO_OUT_COUNT;
|
||||||
psp->readPos &= AUDIO_BUFFER_SIZE_MASK;
|
readPos &= AUDIO_BUFFER_SIZE_MASK;
|
||||||
|
psp->readPos = readPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sceAudioSRCChRelease();
|
sceAudioSRCChRelease();
|
||||||
sceKernelExitThread(0);
|
sceKernelExitThread(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
|
static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||||
|
@ -71,12 +73,16 @@ static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
|
||||||
if (!psp)
|
if (!psp)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
psp->buffer = (uint32_t*)calloc(AUDIO_BUFFER_SIZE, sizeof(uint32_t));
|
psp->buffer = (uint32_t*)memalign(64, AUDIO_BUFFER_SIZE * sizeof(uint32_t)); // cache aligned, not necessary but helpful
|
||||||
|
memset(psp->buffer, 0, AUDIO_BUFFER_SIZE * sizeof(uint32_t));
|
||||||
|
|
||||||
|
psp->zeroBuffer = (uint32_t*)memalign(64, AUDIO_OUT_COUNT * sizeof(uint32_t));
|
||||||
|
memset(psp->zeroBuffer, 0, AUDIO_OUT_COUNT * sizeof(uint32_t));
|
||||||
|
|
||||||
psp->readPos = 0;
|
psp->readPos = 0;
|
||||||
psp->writePos = 0;
|
psp->writePos = 0;
|
||||||
psp->zeroBuffer = (uint32_t*)calloc(AUDIO_OUT_COUNT, sizeof(uint32_t));
|
|
||||||
psp->rate = rate;
|
psp->rate = rate;
|
||||||
psp->thread = sceKernelCreateThread ("audioMainLoop", audioMainLoop, 0x12, 0x10000, 0, NULL);
|
psp->thread = sceKernelCreateThread ("audioMainLoop", audioMainLoop, 0x08, 0x10000, 0, NULL);
|
||||||
psp->nonblocking = false;
|
psp->nonblocking = false;
|
||||||
|
|
||||||
psp->running = true;
|
psp->running = true;
|
||||||
|
@ -105,29 +111,26 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
|
||||||
{
|
{
|
||||||
uint16_t sampleCount;
|
uint16_t sampleCount;
|
||||||
psp1_audio_t* psp = (psp1_audio_t*)data;
|
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||||
|
uint16_t writePos = psp->writePos;
|
||||||
|
|
||||||
sampleCount= size / sizeof(uint32_t);
|
sampleCount= size / sizeof(uint32_t);
|
||||||
|
|
||||||
printf("size: %i sampleCount %i\n",(int)size , (int) sampleCount);
|
// if (psp->nonblocking)
|
||||||
|
// {
|
||||||
|
// /* TODO */
|
||||||
|
// }
|
||||||
|
|
||||||
if (psp->nonblocking)
|
if((writePos + sampleCount) > AUDIO_BUFFER_SIZE)
|
||||||
{
|
{
|
||||||
/* TODO */
|
memcpy(psp->buffer + writePos, buf, (AUDIO_BUFFER_SIZE - writePos) * sizeof(uint32_t));
|
||||||
|
memcpy(psp->buffer, (uint32_t*) buf + (AUDIO_BUFFER_SIZE - writePos), (writePos + sampleCount - AUDIO_BUFFER_SIZE) * sizeof(uint32_t));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
memcpy(psp->buffer + writePos, buf, size);
|
||||||
if((psp->writePos + sampleCount) > AUDIO_BUFFER_SIZE)
|
|
||||||
{
|
|
||||||
memcpy(psp->buffer + psp->writePos, buf, (AUDIO_BUFFER_SIZE - psp->writePos) * sizeof(uint32_t));
|
|
||||||
memcpy(psp->buffer, buf, (psp->writePos + sampleCount - AUDIO_BUFFER_SIZE) * sizeof(uint32_t));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
memcpy(psp->buffer + psp->writePos, buf, size);
|
|
||||||
|
|
||||||
psp->writePos += sampleCount;
|
writePos += sampleCount;
|
||||||
psp->writePos &= AUDIO_BUFFER_SIZE_MASK;
|
writePos &= AUDIO_BUFFER_SIZE_MASK;
|
||||||
|
psp->writePos = writePos;
|
||||||
}
|
|
||||||
|
|
||||||
return sampleCount;
|
return sampleCount;
|
||||||
}
|
}
|
||||||
|
@ -137,9 +140,9 @@ static bool psp_audio_stop(void *data)
|
||||||
SceKernelThreadRunStatus runStatus;
|
SceKernelThreadRunStatus runStatus;
|
||||||
psp1_audio_t* psp = (psp1_audio_t*)data;
|
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||||
|
|
||||||
runStatus.size = sizeof(SceKernelThreadRunStatus);
|
runStatus.size = sizeof(SceKernelThreadRunStatus);
|
||||||
|
|
||||||
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
|
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
|
||||||
return false;
|
return false;
|
||||||
if (runStatus.status == PSP_THREAD_STOPPED)
|
if (runStatus.status == PSP_THREAD_STOPPED)
|
||||||
return false;
|
return false;
|
||||||
|
@ -158,7 +161,7 @@ static bool psp_audio_start(void *data)
|
||||||
|
|
||||||
runStatus.size = sizeof(SceKernelThreadRunStatus);
|
runStatus.size = sizeof(SceKernelThreadRunStatus);
|
||||||
|
|
||||||
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
|
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
|
||||||
return false;
|
return false;
|
||||||
if (runStatus.status != PSP_THREAD_STOPPED)
|
if (runStatus.status != PSP_THREAD_STOPPED)
|
||||||
return false;
|
return false;
|
||||||
|
@ -185,7 +188,8 @@ static bool psp_audio_use_float(void *data)
|
||||||
static size_t psp_write_avail(void *data)
|
static size_t psp_write_avail(void *data)
|
||||||
{
|
{
|
||||||
/* TODO */
|
/* TODO */
|
||||||
return AUDIO_OUT_COUNT;
|
psp1_audio_t* psp = (psp1_audio_t*)data;
|
||||||
|
return ((uint16_t)(psp->writePos - psp->readPos) & AUDIO_BUFFER_SIZE_MASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t psp_buffer_size(void *data)
|
static size_t psp_buffer_size(void *data)
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Frame buffer */
|
/* Frame buffer */
|
||||||
#define SCEGU_VRAM_TOP 0x04000000
|
#define SCEGU_VRAM_TOP 0x44000000
|
||||||
/* 16bit mode */
|
/* 16bit mode */
|
||||||
#define SCEGU_VRAM_BUFSIZE (SCEGU_VRAM_WIDTH*SCEGU_SCR_HEIGHT*2)
|
#define SCEGU_VRAM_BUFSIZE (SCEGU_VRAM_WIDTH*SCEGU_SCR_HEIGHT*2)
|
||||||
#define SCEGU_VRAM_BP_0 (void *)(SCEGU_VRAM_TOP)
|
#define SCEGU_VRAM_BP_0 (void *)(SCEGU_VRAM_TOP)
|
||||||
|
|
Loading…
Reference in New Issue