some spiffy new audio/video code!

This commit is contained in:
dborth 2010-04-13 23:34:01 +00:00
parent 5169aa4d90
commit 13cd4e1653
8 changed files with 133 additions and 34 deletions

View File

@ -52,7 +52,6 @@ AudioThread (void *arg)
while (1)
{
whichab ^= 1;
if (ConfigRequested)
memset (soundbuffer[whichab], 0, AUDIOBUFFER);
else
@ -61,6 +60,7 @@ AudioThread (void *arg)
S9xMixSamples (soundbuffer[whichab], AUDIOBUFFER >> 1);
LWP_MutexUnlock(audiomutex);
}
DCFlushRange (soundbuffer[whichab], AUDIOBUFFER);
LWP_ThreadSleep (audioqueue);
}
@ -76,11 +76,8 @@ GCMixSamples ()
{
if (!ConfigRequested)
{
AUDIO_StopDMA ();
DCFlushRange (soundbuffer[whichab], AUDIOBUFFER);
whichab ^= 1;
AUDIO_InitDMA ((u32) soundbuffer[whichab], AUDIOBUFFER);
AUDIO_StartDMA ();
LWP_ThreadSignal (audioqueue);
}
}
@ -124,6 +121,13 @@ SwitchAudioMode(int mode)
AUDIO_StopDMA();
AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
AUDIO_RegisterDMACallback(GCMixSamples);
memset(soundbuffer[0],0,AUDIOBUFFER);
memset(soundbuffer[1],0,AUDIOBUFFER);
DCFlushRange(soundbuffer[0],AUDIOBUFFER);
DCFlushRange(soundbuffer[1],AUDIOBUFFER);
AUDIO_InitDMA((u32)soundbuffer[whichab],AUDIOBUFFER);
AUDIO_StartDMA();
#endif
S9xSetSamplesAvailableCallback(FinalizeSamplesCallback, NULL);
}
@ -134,7 +138,7 @@ SwitchAudioMode(int mode)
ASND_Init();
ASND_Pause(0);
#else
AUDIO_StopDMA();
//AUDIO_StopDMA();
#endif
}
}

View File

@ -58,7 +58,7 @@ SaveSnapshot (char * filepath, bool silent)
if (pngContext != NULL)
{
imgSize = PNGU_EncodeFromGXTexture(pngContext, screenwidth, screenheight, gameScreenTex2, 0);
imgSize = PNGU_EncodeFromGXTexture(pngContext, vmode->fbWidth, vmode->efbHeight, gameScreenTex2, 0);
PNGU_ReleaseImageContext(pngContext);
}

View File

@ -323,12 +323,28 @@ class GuiElement
//!Considers alpha, alphaDyn, and the parent element's GetAlpha() value
//!\return alpha
int GetAlpha();
//!Sets the element's scale
//!Sets the element's x and y scale
//!\param s scale (1 is 100%)
void SetScale(float s);
//!Sets the element's x scale
//!\param s scale (1 is 100%)
void SetScaleX(float s);
//!Sets the element's y scale
//!\param s scale (1 is 100%)
void SetScaleY(float s);
//!Sets the element's x and y scale, using the provided max width/height
//!\param w Maximum width
//!\param h Maximum height
void SetScale(int w, int h);
//!Gets the element's current scale
//!Considers scale, scaleDyn, and the parent element's GetScale() value
float GetScale();
//!Gets the element's current x scale
//!Considers scale, scaleDyn, and the parent element's GetScale() value
float GetScaleX();
//!Gets the element's current y scale
//!Considers scale, scaleDyn, and the parent element's GetScale() value
float GetScaleY();
//!Set a new GuiTrigger for the element
//!\param t Pointer to GuiTrigger
void SetTrigger(GuiTrigger * t);
@ -420,7 +436,8 @@ class GuiElement
int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects)
int alpha; //!< Element alpha value (0-255)
int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
f32 scale; //!< Element scale (1 = 100%)
f32 xscale; //!< Element X scale (1 = 100%)
f32 yscale; //!< Element Y scale (1 = 100%)
f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects)
int effects; //!< Currently enabled effect(s). 0 when no effects are enabled
int effectAmount; //!< Effect amount. Used by different effects for different purposes

View File

@ -24,7 +24,8 @@ GuiElement::GuiElement()
width = 0;
height = 0;
alpha = 255;
scale = 1;
xscale = 1;
yscale = 1;
state = STATE_DEFAULT;
stateChan = -1;
trigger[0] = NULL;
@ -92,12 +93,13 @@ int GuiElement::GetLeft()
x = pLeft;
break;
case ALIGN_CENTRE:
x = pLeft + (pWidth>>1) - (width>>1);
x = pLeft + pWidth/2.0 - (width*xscale)/2.0;
break;
case ALIGN_RIGHT:
x = pLeft + pWidth - width;
x = pLeft + pWidth - width*xscale;
break;
}
x += (width*(xscale - 1))/2.0; // correct offset for scaled images
return x + xoffset;
}
@ -122,12 +124,13 @@ int GuiElement::GetTop()
y = pTop;
break;
case ALIGN_MIDDLE:
y = pTop + (pHeight>>1) - (height>>1);
y = pTop + pHeight/2.0 - (height*yscale)/2.0;
break;
case ALIGN_BOTTOM:
y = pTop + pHeight - height;
y = pTop + pHeight - height*yscale;
break;
}
y += (height*(yscale - 1))/2.0; // correct offset for scaled images
return y + yoffset;
}
@ -218,12 +221,36 @@ int GuiElement::GetAlpha()
void GuiElement::SetScale(float s)
{
scale = s;
xscale = s;
yscale = s;
}
void GuiElement::SetScaleX(float s)
{
xscale = s;
}
void GuiElement::SetScaleY(float s)
{
yscale = s;
}
void GuiElement::SetScale(int mw, int mh)
{
xscale = 1.0f;
if(width > mw || height > mh)
{
if(width/(height*1.0) > mw/(mh*1.0))
xscale = mw/(width*1.0);
else
xscale = mh/(height*1.0);
}
yscale = xscale;
}
float GuiElement::GetScale()
{
float s = scale * scaleDyn;
float s = xscale * scaleDyn;
if(parentElement)
s *= parentElement->GetScale();
@ -231,6 +258,26 @@ float GuiElement::GetScale()
return s;
}
float GuiElement::GetScaleX()
{
float s = xscale * scaleDyn;
if(parentElement)
s *= parentElement->GetScale();
return s;
}
float GuiElement::GetScaleY()
{
float s = yscale * scaleDyn;
if(parentElement)
s *= parentElement->GetScaleY();
return s;
}
int GuiElement::GetState()
{
return state;

View File

@ -226,7 +226,8 @@ void GuiImage::Draw()
if(!image || !this->IsVisible() || tile == 0)
return;
float currScale = this->GetScale();
float currScaleX = this->GetScaleX();
float currScaleY = this->GetScaleY();
int currLeft = this->GetLeft();
int thisTop = this->GetTop();
@ -235,16 +236,12 @@ void GuiImage::Draw()
int alpha = this->GetAlpha();
for(int i=0; i<tile; ++i)
{
Menu_DrawImg(currLeft+width*i, thisTop, width, height, image, imageangle, currScale, currScale, alpha);
Menu_DrawImg(currLeft+width*i, thisTop, width, height, image, imageangle, currScaleX, currScaleY, alpha);
}
}
else
{
// temporary (maybe), used to correct offset for scaled images
if(scale != 1)
currLeft += (width*(scale - 1))/2;
Menu_DrawImg(currLeft, thisTop, width, height, image, imageangle, currScale, currScale, this->GetAlpha());
Menu_DrawImg(currLeft, thisTop, width, height, image, imageangle, currScaleX, currScaleY, this->GetAlpha());
}
if(stripe > 0)

View File

@ -3769,9 +3769,11 @@ MainMenu (int menu)
if(gameScreenTex)
{
gameScreenImg = new GuiImage(gameScreenTex, screenwidth, screenheight);
gameScreenImg = new GuiImage(gameScreenTex, vmode->fbWidth, vmode->efbHeight);
gameScreenImg->SetAlpha(192);
gameScreenImg->ColorStripe(30);
gameScreenImg->SetScaleX(screenwidth/(float)vmode->fbWidth);
gameScreenImg->SetScaleY(screenheight/(float)vmode->efbHeight);
mainWindow->Append(gameScreenImg);
bgImg->SetVisible(false);
}

View File

@ -40,7 +40,7 @@ unsigned char * filtermem = NULL; // only want ((512*2) X (239*2))
/*** 2D Video ***/
static unsigned int *xfb[2] = { NULL, NULL }; // Double buffered
static int whichfb = 0; // Switch
static GXRModeObj *vmode = NULL; // Current video mode
GXRModeObj *vmode = NULL; // Current video mode
int screenheight = 480;
int screenwidth = 640;
static int oldRenderMode = -1; // set to GCSettings.render when changing (temporarily) to another mode
@ -399,7 +399,7 @@ static GXRModeObj * FindVideoMode()
mode = &TVNtsc480Prog;
break;
case 3: // PAL (50Hz)
mode = &TVPal574IntDfScale;
mode = &TVPal528IntDf;
break;
case 4: // PAL (60Hz)
mode = &TVEurgb60Hz480IntDf;
@ -415,9 +415,6 @@ static GXRModeObj * FindVideoMode()
mode = &TVNtsc480Prog;
#endif
// use hardware vertical scaling to fill screen
if(mode->viTVMode >> 2 == VI_PAL)
mode = &TVPal574IntDfScale;
break;
}
@ -479,11 +476,45 @@ static GXRModeObj * FindVideoMode()
progressive = false;
#ifdef HW_RVL
// widescreen fix
if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
bool pal = false;
if (mode == &TVPal528IntDf)
pal = true;
if (CONF_GetAspectRatio() == CONF_ASPECT_16_9)
{
mode->viWidth = 678;
mode->viXOrigin = (VI_MAX_WIDTH_NTSC - 678) / 2;
mode->fbWidth = 640;
mode->efbHeight = 456;
mode->viWidth = 686;
if (pal)
{
mode->xfbHeight = 542;
mode->viHeight = 542;
}
else
{
mode->xfbHeight = 456;
mode->viHeight = 456;
}
}
else
{
if (pal)
mode = &TVPal574IntDfScale;
mode->viWidth = 672;
}
if (pal)
{
mode->viXOrigin = (VI_MAX_WIDTH_PAL - mode->viWidth) / 2;
mode->viYOrigin = (VI_MAX_HEIGHT_PAL - mode->viHeight) / 2;
}
else
{
mode->viXOrigin = (VI_MAX_WIDTH_NTSC - mode->viWidth) / 2;
mode->viYOrigin = (VI_MAX_HEIGHT_NTSC - mode->viHeight) / 2;
}
#endif
return mode;

View File

@ -30,6 +30,7 @@ void Menu_Render();
void Menu_DrawImg(f32 xpos, f32 ypos, u16 width, u16 height, u8 data[], f32 degrees, f32 scaleX, f32 scaleY, u8 alphaF );
void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 filled);
extern GXRModeObj *vmode;
extern int screenheight;
extern int screenwidth;
extern bool progressive;