Changed gl_shm name to nes_shm. Added audio circular buffer to shared memory.
This commit is contained in:
parent
7eca2978ed
commit
72141845f0
|
@ -308,7 +308,7 @@ SOURCES += src/drivers/Qt/GameSoundConf.cpp
|
|||
SOURCES += src/drivers/Qt/fceuWrapper.cpp
|
||||
SOURCES += src/drivers/Qt/config.cpp
|
||||
SOURCES += src/drivers/Qt/input.cpp
|
||||
SOURCES += src/drivers/Qt/gl_win.cpp
|
||||
SOURCES += src/drivers/Qt/nes_shm.cpp
|
||||
SOURCES += src/drivers/Qt/keyscan.cpp
|
||||
SOURCES += src/drivers/Qt/sdl-sound.cpp
|
||||
SOURCES += src/drivers/Qt/sdl-video.cpp
|
||||
|
|
|
@ -24,7 +24,7 @@ gameWin_t::gameWin_t(QWidget *parent)
|
|||
connect( gameTimer, &QTimer::timeout, this, &gameWin_t::runGameFrame );
|
||||
|
||||
gameTimer->setTimerType( Qt::PreciseTimer );
|
||||
gameTimer->start( 10 );
|
||||
gameTimer->start( 16 );
|
||||
|
||||
gamePadConfWin = NULL;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
|
||||
#include "Qt/gl_win.h"
|
||||
#include "Qt/nes_shm.h"
|
||||
#include "Qt/GameViewerGL.h"
|
||||
|
||||
extern unsigned int gui_draw_area_width;
|
||||
|
@ -111,8 +111,8 @@ void gameViewGL_t::resizeGL(int w, int h)
|
|||
|
||||
void gameViewGL_t::paintGL(void)
|
||||
{
|
||||
int texture_width = gl_shm->ncol;
|
||||
int texture_height = gl_shm->nrow;
|
||||
int texture_width = nes_shm->ncol;
|
||||
int texture_height = nes_shm->nrow;
|
||||
int l=0, r=texture_width;
|
||||
int t=0, b=texture_height;
|
||||
|
||||
|
@ -149,7 +149,7 @@ void gameViewGL_t::paintGL(void)
|
|||
|
||||
glTexSubImage2D(GL_TEXTURE_RECTANGLE, 0,
|
||||
0, 0, GL_NES_WIDTH, GL_NES_HEIGHT,
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, gl_shm->pixbuf );
|
||||
GL_BGRA, GL_UNSIGNED_BYTE, nes_shm->pixbuf );
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f( l, b); // Bottom left of picture.
|
||||
|
@ -169,4 +169,4 @@ void gameViewGL_t::paintGL(void)
|
|||
glDisable(GL_TEXTURE_RECTANGLE);
|
||||
|
||||
//printf("Paint GL!\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "Qt/gl_win.h"
|
||||
#include "Qt/nes_shm.h"
|
||||
#include "Qt/GameViewerSDL.h"
|
||||
|
||||
extern unsigned int gui_draw_area_width;
|
||||
|
@ -147,10 +147,10 @@ void gameViewSDL_t::paintEvent( QPaintEvent *event )
|
|||
int nesWidth = GL_NES_WIDTH;
|
||||
int nesHeight = GL_NES_HEIGHT;
|
||||
|
||||
if ( gl_shm != NULL )
|
||||
if ( nes_shm != NULL )
|
||||
{
|
||||
nesWidth = gl_shm->ncol;
|
||||
nesHeight = gl_shm->nrow;
|
||||
nesWidth = nes_shm->ncol;
|
||||
nesHeight = nes_shm->nrow;
|
||||
}
|
||||
//printf(" %i x %i \n", nesWidth, nesHeight );
|
||||
float xscale = (float)view_width / (float)nesWidth;
|
||||
|
@ -183,7 +183,7 @@ void gameViewSDL_t::paintEvent( QPaintEvent *event )
|
|||
int rowPitch;
|
||||
SDL_LockTexture( sdlTexture, nullptr, (void**)&textureBuffer, &rowPitch);
|
||||
{
|
||||
memcpy( textureBuffer, gl_shm->pixbuf, GL_NES_HEIGHT*GL_NES_WIDTH*sizeof(uint32_t) );
|
||||
memcpy( textureBuffer, nes_shm->pixbuf, GL_NES_HEIGHT*GL_NES_WIDTH*sizeof(uint32_t) );
|
||||
}
|
||||
SDL_UnlockTexture(sdlTexture);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "Qt/input.h"
|
||||
#include "Qt/sdl.h"
|
||||
#include "Qt/sdl-video.h"
|
||||
#include "Qt/gl_win.h"
|
||||
#include "Qt/nes_shm.h"
|
||||
#include "Qt/unix-netplay.h"
|
||||
|
||||
#include "common/cheat.h"
|
||||
|
@ -471,11 +471,11 @@ int fceuWrapperInit( int argc, char *argv[] )
|
|||
return 0;
|
||||
}
|
||||
|
||||
gl_shm = open_video_shm();
|
||||
nes_shm = open_nes_shm();
|
||||
|
||||
if ( gl_shm == NULL )
|
||||
if ( nes_shm == NULL )
|
||||
{
|
||||
printf("Error: Failed to open video Shared memory\n");
|
||||
printf("Error: Failed to open NES Shared memory\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,18 +9,18 @@
|
|||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "Qt/gl_win.h"
|
||||
#include "Qt/nes_shm.h"
|
||||
|
||||
gl_win_shm_t *gl_shm = NULL;
|
||||
nes_shm_t *nes_shm = NULL;
|
||||
|
||||
//************************************************************************
|
||||
gl_win_shm_t *open_video_shm(void)
|
||||
nes_shm_t *open_nes_shm(void)
|
||||
{
|
||||
int shmId;
|
||||
gl_win_shm_t *vaddr;
|
||||
nes_shm_t *vaddr;
|
||||
struct shmid_ds ds;
|
||||
|
||||
shmId = shmget( IPC_PRIVATE, sizeof(struct gl_win_shm_t), IPC_CREAT | S_IRWXU | S_IRWXG );
|
||||
shmId = shmget( IPC_PRIVATE, sizeof(struct nes_shm_t), IPC_CREAT | S_IRWXU | S_IRWXG );
|
||||
|
||||
if ( shmId == -1 )
|
||||
{
|
||||
|
@ -29,14 +29,14 @@ gl_win_shm_t *open_video_shm(void)
|
|||
}
|
||||
printf("Created ShmID: %i \n", shmId );
|
||||
|
||||
vaddr = (gl_win_shm_t*)shmat( shmId, NULL, 0);
|
||||
vaddr = (nes_shm_t*)shmat( shmId, NULL, 0);
|
||||
|
||||
if ( vaddr == (gl_win_shm_t*)-1 )
|
||||
if ( vaddr == (nes_shm_t*)-1 )
|
||||
{
|
||||
perror("Error: GLX shmat Failed:");
|
||||
perror("Error: NES shmat Failed:");
|
||||
return NULL;
|
||||
}
|
||||
memset( vaddr, 0, sizeof(struct gl_win_shm_t));
|
||||
memset( vaddr, 0, sizeof(struct nes_shm_t));
|
||||
|
||||
if ( shmctl( shmId, IPC_RMID, &ds ) != 0 )
|
||||
{
|
|
@ -1,8 +1,8 @@
|
|||
// gl_win.cpp
|
||||
// nes_shm.h
|
||||
//
|
||||
|
||||
#ifndef __GL_WIN_H__
|
||||
#define __GL_WIN_H__
|
||||
#ifndef __NES_SHM_H__
|
||||
#define __NES_SHM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -11,8 +11,9 @@
|
|||
|
||||
#define GL_NES_WIDTH 256
|
||||
#define GL_NES_HEIGHT 256
|
||||
#define NES_AUDIO_BUFLEN 480000
|
||||
|
||||
struct gl_win_shm_t
|
||||
struct nes_shm_t
|
||||
{
|
||||
int pid;
|
||||
int run;
|
||||
|
@ -59,10 +60,24 @@ struct gl_win_shm_t
|
|||
{
|
||||
memset( pixbuf, 0, sizeof(pixbuf) );
|
||||
}
|
||||
|
||||
struct sndBuf_t
|
||||
{
|
||||
int head;
|
||||
int tail;
|
||||
int16_t data[NES_AUDIO_BUFLEN];
|
||||
unsigned int starveCounter;
|
||||
} sndBuf;
|
||||
|
||||
void push_sound_sample( int16_t sample )
|
||||
{
|
||||
sndBuf.data[ sndBuf.head ] = sample;
|
||||
sndBuf.head = (sndBuf.head + 1) % NES_AUDIO_BUFLEN;
|
||||
}
|
||||
};
|
||||
|
||||
extern gl_win_shm_t *gl_shm;
|
||||
extern nes_shm_t *nes_shm;
|
||||
|
||||
gl_win_shm_t *open_video_shm(void);
|
||||
nes_shm_t *open_nes_shm(void);
|
||||
|
||||
#endif
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "common/configSys.h"
|
||||
#include "utils/memory.h"
|
||||
#include "nes_shm.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
@ -49,18 +50,27 @@ fillaudio(void *udata,
|
|||
uint8 *stream,
|
||||
int len)
|
||||
{
|
||||
static int16_t sample = 0;
|
||||
int16 *tmps = (int16*)stream;
|
||||
len >>= 1;
|
||||
while(len) {
|
||||
int16 sample = 0;
|
||||
if(s_BufferIn) {
|
||||
while (len)
|
||||
{
|
||||
//int16 sample = 0;
|
||||
if (s_BufferIn)
|
||||
{
|
||||
sample = s_Buffer[s_BufferRead];
|
||||
s_BufferRead = (s_BufferRead + 1) % s_BufferSize;
|
||||
s_BufferIn--;
|
||||
} else {
|
||||
sample = 0;
|
||||
// Retain last known sample value, helps avoid clicking
|
||||
// noise when sound system is starved of audio data.
|
||||
//sample = 0;
|
||||
nes_shm->sndBuf.starveCounter++;
|
||||
//printf("Starve:%u\n", nes_shm->sndBuf.starveCounter );
|
||||
}
|
||||
|
||||
nes_shm->push_sound_sample( sample );
|
||||
|
||||
*tmps = sample;
|
||||
tmps++;
|
||||
len--;
|
||||
|
@ -179,6 +189,7 @@ WriteSound(int32 *buf,
|
|||
{
|
||||
extern int EmulationPaused;
|
||||
if (EmulationPaused == 0)
|
||||
{
|
||||
while(Count)
|
||||
{
|
||||
while(s_BufferIn == s_BufferSize)
|
||||
|
@ -196,6 +207,7 @@ WriteSound(int32 *buf,
|
|||
|
||||
buf++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ static const double Fastest = 32; // 32x speed (around 1920 fps on NTSC)
|
|||
static const double Normal = 1.0; // 1x speed (around 60 fps on NTSC)
|
||||
|
||||
static uint64 Lasttime, Nexttime;
|
||||
static long double desired_frametime;
|
||||
static double desired_frametime = (1.0 / 60.099823);
|
||||
static int InFrame;
|
||||
double g_fpsScale = Normal; // used by sdl.cpp
|
||||
bool MaxSpeed = false;
|
||||
|
@ -30,8 +30,14 @@ bool MaxSpeed = false;
|
|||
void
|
||||
RefreshThrottleFPS()
|
||||
{
|
||||
uint64 fps = FCEUI_GetDesiredFPS(); // Do >> 24 to get in Hz
|
||||
desired_frametime = 16777216.0l / (fps * g_fpsScale);
|
||||
double hz;
|
||||
int32_t fps = FCEUI_GetDesiredFPS(); // Do >> 24 to get in Hz
|
||||
|
||||
hz = ( ((double)fps) / 16777216.0 );
|
||||
|
||||
desired_frametime = 1.0 / ( hz * g_fpsScale );
|
||||
|
||||
printf("FrameTime: %llu %llu %f %lf \n", fps, fps >> 24, hz, desired_frametime );
|
||||
|
||||
Lasttime=0;
|
||||
Nexttime=0;
|
||||
|
@ -44,6 +50,8 @@ RefreshThrottleFPS()
|
|||
int
|
||||
SpeedThrottle()
|
||||
{
|
||||
return 0;
|
||||
|
||||
if(g_fpsScale >= 32)
|
||||
{
|
||||
return 0; /* Done waiting */
|
||||
|
@ -66,7 +74,7 @@ SpeedThrottle()
|
|||
else
|
||||
time_left = Nexttime - cur_time;
|
||||
|
||||
if(time_left > 50)
|
||||
if (time_left > 50)
|
||||
{
|
||||
time_left = 50;
|
||||
/* In order to keep input responsive, don't wait too long at once */
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
/// \brief Handles the graphical game display for the SDL implementation.
|
||||
|
||||
#include "Qt/sdl.h"
|
||||
#include "Qt/gl_win.h"
|
||||
#include "Qt/nes_shm.h"
|
||||
#include "common/vidblit.h"
|
||||
#include "../../fceu.h"
|
||||
#include "../../version.h"
|
||||
|
@ -91,9 +91,9 @@ KillVideo()
|
|||
{
|
||||
//printf("Killing Video\n");
|
||||
|
||||
if ( gl_shm != NULL )
|
||||
if ( nes_shm != NULL )
|
||||
{
|
||||
gl_shm->clear_pixbuf();
|
||||
nes_shm->clear_pixbuf();
|
||||
}
|
||||
|
||||
//destroy_gui_video();
|
||||
|
@ -337,7 +337,7 @@ static void WriteTestPattern(void)
|
|||
{
|
||||
for (j=0; j<GL_NES_HEIGHT; j++)
|
||||
{
|
||||
gl_shm->pixbuf[k] = 0xffffffff; k++;
|
||||
nes_shm->pixbuf[k] = 0xffffffff; k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -360,14 +360,14 @@ BlitScreen(uint8 *XBuf)
|
|||
// XXX soules - not entirely sure why this is being done yet
|
||||
XBuf += s_srendline * 256;
|
||||
|
||||
dest = (uint8*)gl_shm->pixbuf;
|
||||
dest = (uint8*)nes_shm->pixbuf;
|
||||
w = GL_NES_WIDTH;
|
||||
h = GL_NES_HEIGHT;
|
||||
pitch = w*4;
|
||||
|
||||
gl_shm->ncol = NWIDTH;
|
||||
gl_shm->nrow = s_tlines;
|
||||
gl_shm->pitch = pitch;
|
||||
nes_shm->ncol = NWIDTH;
|
||||
nes_shm->nrow = s_tlines;
|
||||
nes_shm->pitch = pitch;
|
||||
|
||||
if ( dest == NULL ) return;
|
||||
|
||||
|
|
Loading…
Reference in New Issue