Merge pull request #567 from aliaspider/master

audio + OSD text fixes.
This commit is contained in:
Twinaphex 2014-02-22 03:06:09 +01:00
commit 8295a173b8
2 changed files with 153 additions and 149 deletions

View File

@ -1,6 +1,6 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
*
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
@ -28,37 +28,39 @@ typedef struct psp1_audio
uint32_t* buffer;
uint32_t* zeroBuffer;
SceUID thread;
int rate;
uint16_t readPos;
uint16_t writePos;
int rate;
volatile uint16_t readPos;
volatile uint16_t writePos;
} psp1_audio_t;
#define AUDIO_OUT_COUNT 128
#define AUDIO_BUFFER_SIZE (1u<<12u)
#define AUDIO_OUT_COUNT 128u
#define AUDIO_BUFFER_SIZE (1u<<11u)
#define AUDIO_BUFFER_SIZE_MASK (AUDIO_BUFFER_SIZE-1)
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);
else
{
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->buffer + psp->readPos);
psp->readPos += AUDIO_OUT_COUNT;
psp->readPos &= AUDIO_BUFFER_SIZE_MASK;
sceAudioSRCOutputBlocking(PSP_AUDIO_VOLUME_MAX, psp->buffer + readPos);
readPos += AUDIO_OUT_COUNT;
readPos &= AUDIO_BUFFER_SIZE_MASK;
psp->readPos = readPos;
}
}
sceAudioSRCChRelease();
sceKernelExitThread(0);
return 0;
sceAudioSRCChRelease();
sceKernelExitThread(0);
return 0;
}
static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
@ -71,17 +73,21 @@ static void *psp_audio_init(const char *device, unsigned rate, unsigned latency)
if (!psp)
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->writePos = 0;
psp->zeroBuffer = (uint32_t*)calloc(AUDIO_OUT_COUNT, sizeof(uint32_t));
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->running = true;
psp->running = true;
sceKernelStartThread(psp->thread, sizeof(psp1_audio_t*), &psp);
return psp;
}
@ -95,7 +101,7 @@ static void psp_audio_free(void *data)
SceUInt timeout = 100000;
sceKernelWaitThreadEnd(psp->thread, &timeout);
sceKernelDeleteThread(psp->thread);
free(psp->buffer);
free(psp->zeroBuffer);
free(psp);
@ -105,30 +111,27 @@ static ssize_t psp_audio_write(void *data, const void *buf, size_t size)
{
uint16_t sampleCount;
psp1_audio_t* psp = (psp1_audio_t*)data;
uint16_t writePos = psp->writePos;
sampleCount= size / sizeof(uint32_t);
printf("size: %i sampleCount %i\n",(int)size , (int) sampleCount);
if (psp->nonblocking)
// if (psp->nonblocking)
// {
// /* TODO */
// }
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
{
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;
psp->writePos &= AUDIO_BUFFER_SIZE_MASK;
}
memcpy(psp->buffer + writePos, buf, size);
writePos += sampleCount;
writePos &= AUDIO_BUFFER_SIZE_MASK;
psp->writePos = writePos;
return sampleCount;
}
@ -136,18 +139,18 @@ static bool psp_audio_stop(void *data)
{
SceKernelThreadRunStatus runStatus;
psp1_audio_t* psp = (psp1_audio_t*)data;
runStatus.size = sizeof(SceKernelThreadRunStatus);
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
return false;
runStatus.size = sizeof(SceKernelThreadRunStatus);
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
return false;
if (runStatus.status == PSP_THREAD_STOPPED)
return false;
psp->running = false;
SceUInt timeout = 100000;
sceKernelWaitThreadEnd(psp->thread, &timeout);
return true;
}
@ -155,16 +158,16 @@ static bool psp_audio_start(void *data)
{
SceKernelThreadRunStatus runStatus;
psp1_audio_t* psp = (psp1_audio_t*)data;
runStatus.size = sizeof(SceKernelThreadRunStatus);
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
return false;
if (sceKernelReferThreadRunStatus(psp->thread, &runStatus) < 0) // error
return false;
if (runStatus.status != PSP_THREAD_STOPPED)
return false;
psp->running = true;
psp->running = true;
sceKernelStartThread(psp->thread, sizeof(psp1_audio_t*), &psp);
return true;
@ -185,7 +188,8 @@ static bool psp_audio_use_float(void *data)
static size_t psp_write_avail(void *data)
{
/* 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)

View File

@ -37,7 +37,7 @@
#endif
/* Frame buffer */
#define SCEGU_VRAM_TOP 0x04000000
#define SCEGU_VRAM_TOP 0x44000000
/* 16bit mode */
#define SCEGU_VRAM_BUFSIZE (SCEGU_VRAM_WIDTH*SCEGU_SCR_HEIGHT*2)
#define SCEGU_VRAM_BP_0 (void *)(SCEGU_VRAM_TOP)
@ -64,48 +64,48 @@ typedef struct psp1_rgui_frame
int pixel_size;
unsigned width;
unsigned height;
unsigned height;
unsigned buffer_width;
unsigned buffer_Height;
void* buffer;
float alpha;
uint32_t alpha_source;
uint32_t alpha_dest;
bool active;
psp1_copy_frame_func copy_frame;
psp1_copy_frame_func copy_frame;
} psp1_rgui_frame_t;
typedef struct psp1_video
{
void* displayList;
void* displayList;
void* frameBuffers[2];
unsigned int drawBuffer_ID;
bool vsync;
bool rgb32;
int pixel_format;
int pixel_size;
unsigned buffer_width;
unsigned buffer_Height;
void* buffer;
psp1_copy_frame_func copy_frame;
psp1_copy_frame_func copy_frame;
psp1_rgui_frame_t rgui;
// not implemented
unsigned width;
unsigned height;
bool force_aspect;
bool smooth;
unsigned input_scale; // Maximum input size: RARCH_SCALE_BASE * input_scale
int rotation;
int rotation;
} psp1_video_t;
@ -120,11 +120,11 @@ typedef struct psp1_vertex
static void copy_frame_ARGB8888_to_ABGR8888(const void *in_frame, unsigned in_buffer_width,
void *out_frame, unsigned out_buffer_width,
unsigned width, unsigned height)
{
{
int x,y;
const uint32_t *in_p = (const uint32_t*)in_frame;
uint32_t *out_p = (uint32_t*)out_frame;
const uint32_t *in_p = (const uint32_t*)in_frame;
uint32_t *out_p = (uint32_t*)out_frame;
for(y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
@ -142,11 +142,11 @@ static void copy_frame_ARGB8888_to_ABGR8888(const void *in_frame, unsigned in_bu
static void copy_frame_RGB5650_to_BGR5650(const void *in_frame, unsigned in_buffer_width,
void *out_frame, unsigned out_buffer_width,
unsigned width, unsigned height)
{
{
int x,y;
const uint16_t *in_p = (const uint16_t*)in_frame;
uint16_t *out_p = (uint16_t*)out_frame;
const uint16_t *in_p = (const uint16_t*)in_frame;
uint16_t *out_p = (uint16_t*)out_frame;
for(y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
@ -162,11 +162,11 @@ static void copy_frame_RGB5650_to_BGR5650(const void *in_frame, unsigned in_buff
static void copy_frame_XBGR16(const void *in_frame, unsigned in_buffer_width,
void *out_frame, unsigned out_buffer_width,
unsigned width, unsigned height)
{
{
int x,y;
const uint16_t *in_p = (const uint16_t*)in_frame;
uint16_t *out_p = (uint16_t*)out_frame;
const uint16_t *in_p = (const uint16_t*)in_frame;
uint16_t *out_p = (uint16_t*)out_frame;
for(y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
@ -188,12 +188,12 @@ static void *psp_init(const video_info_t *video,
{
// first time init
psp = (psp1_video_t*)calloc(1, sizeof(psp1_video_t));
if (!psp)
goto error;
}
if(!psp->displayList) // either first time init or psp_free was called
{
sceGuInit();
@ -202,50 +202,50 @@ static void *psp_init(const video_info_t *video,
psp->buffer_width = 512;
psp->buffer_Height = 512;
psp->rgui.buffer_width = 512;
psp->rgui.buffer_Height = 256;
psp->rgui.buffer_Height = 256;
}
psp->width = video->width;
psp->height = video->height;
psp->vsync = video->vsync;
psp->force_aspect = video->force_aspect;
psp->smooth = video->smooth;
psp->input_scale = video->input_scale;
psp->rgb32 = video->rgb32;
psp->pixel_format = psp->rgb32 ? GU_PSM_8888 : GU_PSM_5650;
psp->pixel_size = psp->rgb32 ? 4 : 2;
psp->pixel_size = psp->rgb32 ? 4 : 2;
psp->copy_frame = psp->rgb32 ? copy_frame_ARGB8888_to_ABGR8888 : copy_frame_RGB5650_to_BGR5650;
if (psp->buffer)
free(TO_CACHED_PTR(psp->buffer));
psp->buffer = memalign(16, psp->buffer_width * psp->buffer_Height * psp->pixel_size);
psp->buffer = memalign(16, psp->buffer_width * psp->buffer_Height * psp->pixel_size);
psp->buffer = TO_UNCACHED_PTR(psp->buffer);
//init rgui to 16-bit pixel format since it can't be empty when psp_set_texture_frame is called
psp->rgui.rgb32 = video->rgb32;
psp->rgui.pixel_format = psp->rgui.rgb32 ? GU_PSM_8888 : GU_PSM_4444;
psp->rgui.pixel_size = psp->rgui.rgb32 ? 4 : 2;
psp->rgui.pixel_size = psp->rgui.rgb32 ? 4 : 2;
psp->rgui.copy_frame = psp->rgui.rgb32 ? copy_frame_ARGB8888_to_ABGR8888 : copy_frame_XBGR16;
psp->frameBuffers[0]=psp->rgui.rgb32 ? SCEGU_VRAM_BP32_0 : SCEGU_VRAM_BP_0;
psp->frameBuffers[1]=psp->rgui.rgb32 ? SCEGU_VRAM_BP32_1 : SCEGU_VRAM_BP_1;
psp->drawBuffer_ID=0;
if (psp->rgui.buffer)
free(TO_CACHED_PTR(psp->rgui.buffer));
psp->rgui.buffer = memalign(16, psp->rgui.buffer_width * psp->rgui.buffer_Height * psp->rgui.pixel_size);
psp->rgui.buffer = memalign(16, psp->rgui.buffer_width * psp->rgui.buffer_Height * psp->rgui.pixel_size);
psp->rgui.buffer = TO_UNCACHED_PTR(psp->rgui.buffer);
psp->rgui.active = false;
psp->rgui.alpha = 0.0;
psp->rgui.alpha_source = 0x00000000;
psp->rgui.alpha_dest = 0xFFFFFFFF;
// need to invalidate cache before using uncached pointers, to avoid unwanted cache writebacks. TODO: check up/downsides of using sceKernelDcacheInvalidateRange here instead
sceKernelDcacheWritebackInvalidateAll();
sceDisplayWaitVblankStart(); // TODO : check if necessary
sceDisplayWaitVblankStart(); // TODO : check if necessary
sceGuDisplay(GU_FALSE);
sceGuStart(GU_DIRECT, psp->displayList);
@ -257,21 +257,21 @@ static void *psp_init(const video_info_t *video,
sceGuEnable(GU_SCISSOR_TEST);
sceGuTexMode(psp->pixel_format, 0, 0, GU_FALSE);
sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
sceGuTexFilter(GU_LINEAR, GU_LINEAR); // TODO , move this to display list
sceGuTexFilter(GU_LINEAR, GU_LINEAR); // TODO , move this to display list
sceGuTexWrap (GU_CLAMP, GU_CLAMP);
sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_TEXTURE_2D);
sceGuDisable(GU_BLEND);
sceGuDisable(GU_DEPTH_TEST);
sceGuDisable(GU_DEPTH_TEST);
sceGuFinish();
sceGuSync(0, 0);
sceDisplayWaitVblankStart(); // TODO : check if necessary
sceDisplayWaitVblankStart(); // TODO : check if necessary
sceGuDisplay(GU_TRUE);
pspDebugScreenSetColorMode(psp->pixel_format);
pspDebugScreenSetBase(psp->frameBuffers[psp->drawBuffer_ID]);
if (input && input_data)
{
pspinput = input_psp.init();
@ -279,7 +279,7 @@ static void *psp_init(const video_info_t *video,
*input_data = pspinput;
}
return psp;
error:
RARCH_ERR("PSP1 video could not be initialized.\n");
@ -292,74 +292,74 @@ static bool psp_frame(void *data, const void *frame,
unsigned width, unsigned height, unsigned pitch, const char *msg)
{
psp1_vertex_t *v;
psp1_video_t *psp = (psp1_video_t*)data;
sceGuSync(0, 0);
if (msg) // TODO: fix flickering text
{
pspDebugScreenSetBase(psp->frameBuffers[psp->drawBuffer_ID]);
pspDebugScreenSetXY(0,0);
pspDebugScreenPuts(msg);
}
if (psp->vsync)
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
psp->drawBuffer_ID^=1;
/* frame dupes. */
/* frame dupes. */
if (frame == NULL)
return true;
psp->copy_frame(frame, pitch / psp->pixel_size, psp->buffer, psp->buffer_width, width, height);
sceGuStart(GU_DIRECT, psp->displayList);
sceGuClear(GU_COLOR_BUFFER_BIT);
v = (psp1_vertex_t*)sceGuGetMemory(4 * sizeof(psp1_vertex_t));
v[0].x = (SCEGU_SCR_WIDTH - width * SCEGU_SCR_HEIGHT / height) / 2;
v[0].y = 0;
v[0].y = 0;
v[0].u = 0;
v[0].v = 0;
v[0].v = 0;
v[1].x = (SCEGU_SCR_WIDTH + width * SCEGU_SCR_HEIGHT / height) / 2;
v[1].y = SCEGU_SCR_HEIGHT;
v[1].u = width;
v[1].v = height;
sceGuTexMode(psp->pixel_format, 0, 0, GU_FALSE);
sceGuTexImage(0, psp->buffer_width, psp->buffer_Height, psp->buffer_width, psp->buffer);
sceGuTexImage(0, psp->buffer_width, psp->buffer_Height, psp->buffer_width, psp->buffer);
// sceGuTexFilter(GU_LINEAR, GU_LINEAR);
sceGuDisable(GU_BLEND);
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_5650 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, v);
if (psp->rgui.active)
{
v[2].x = 0;
v[2].y = 0;
v[2].y = 0;
v[2].u = 0;
v[2].v = 0;
v[2].v = 0;
v[3].x = SCEGU_SCR_WIDTH;
v[3].y = SCEGU_SCR_HEIGHT;
v[3].u = psp->rgui.width;
v[3].u = psp->rgui.width;
v[3].v = psp->rgui.height;
sceGuTexMode(psp->rgui.pixel_format, 0, 0, GU_FALSE);
sceGuTexImage(0, psp->rgui.buffer_width, psp->rgui.buffer_Height, psp->rgui.buffer_width, psp->rgui.buffer);
sceGuTexImage(0, psp->rgui.buffer_width, psp->rgui.buffer_Height, psp->rgui.buffer_width, psp->rgui.buffer);
// sceGuTexFilter(GU_LINEAR, GU_LINEAR);
sceGuEnable(GU_BLEND);
sceGuBlendFunc(GU_ADD, GU_FIX, GU_FIX, psp->rgui.alpha_source, psp->rgui.alpha_dest);
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_COLOR_5650 | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, NULL, v + 2);
}
sceGuFinish();
sceGuFinish();
return true;
}
@ -384,16 +384,16 @@ static bool psp_focus(void *data)
static void psp_free(void *data)
{
psp1_video_t *psp = (psp1_video_t*)data;
if (psp->displayList)
free(psp->displayList);
if (psp->buffer)
free(TO_CACHED_PTR(psp->buffer));
if (psp->rgui.buffer)
free(TO_CACHED_PTR(psp->rgui.buffer));
memset(psp, 0, sizeof(psp1_video_t));
sceGuTerm();
}
@ -411,26 +411,26 @@ static void psp_set_texture_frame(void *data, const void *frame, bool rgb32,
unsigned width, unsigned height, float alpha)
{
psp1_video_t *psp = (psp1_video_t*)data;
if (psp->rgui.rgb32 != rgb32)
{
psp->rgui.rgb32 = rgb32;
psp->rgui.pixel_format = psp->rgui.rgb32 ? GU_PSM_8888 : GU_PSM_4444;
psp->rgui.pixel_size = psp->rgui.rgb32 ? 4 : 2;
psp->rgui.pixel_size = psp->rgui.rgb32 ? 4 : 2;
psp->rgui.copy_frame = psp->rgui.rgb32 ? copy_frame_ARGB8888_to_ABGR8888 : copy_frame_XBGR16;
if (psp->rgui.buffer)
free(TO_CACHED_PTR(psp->rgui.buffer));
psp->rgui.buffer = memalign(16, psp->rgui.buffer_width * psp->rgui.buffer_Height * psp->rgui.pixel_size);
psp->rgui.buffer = memalign(16, psp->rgui.buffer_width * psp->rgui.buffer_Height * psp->rgui.pixel_size);
psp->rgui.buffer = TO_UNCACHED_PTR(psp->rgui.buffer);
sceKernelDcacheWritebackInvalidateAll();
}
psp->rgui.width = width;
psp->rgui.height = height;
psp->rgui.copy_frame(frame, width, psp->rgui.buffer, psp->rgui.buffer_width, width, height);
psp->rgui.alpha = alpha;
psp->rgui.copy_frame(frame, width, psp->rgui.buffer, psp->rgui.buffer_width, width, height);
psp->rgui.alpha = alpha;
uint32_t mask;
mask = alpha*255.0;
mask &= 0xFF;
@ -443,7 +443,7 @@ static void psp_set_texture_frame(void *data, const void *frame, bool rgb32,
static void psp_set_texture_enable(void *data, bool state, bool full_screen)
{
(void) full_screen;
psp1_video_t *psp = (psp1_video_t*)data;
psp->rgui.active = state;