psp snd output improved

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@288 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-11-01 09:39:56 +00:00
parent d0ae0cb4bb
commit 88b3d7c16a
3 changed files with 29 additions and 16 deletions

View file

@ -220,8 +220,14 @@ PICO_INTERNAL void PsndClear(void)
{ {
int len = PsndLen; int len = PsndLen;
if (PsndLen_exc_add) len++; if (PsndLen_exc_add) len++;
if (PicoOpt & 8) memset32((int *) PsndOut, 0, len); // clear both channels at once if (PicoOpt & 8)
else memset(PsndOut, 0, len<<1); memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned
else {
short *out = PsndOut;
if ((int)out & 2) { *out++ = 0; len--; }
memset32((int *) out, 0, len/2);
if (len & 1) out[len-1] = 0;
}
} }
@ -248,9 +254,9 @@ PICO_INTERNAL int PsndRender(int offset, int length)
SN76496Update(PsndOut+offset, length, stereo); SN76496Update(PsndOut+offset, length, stereo);
// Add in the stereo FM buffer // Add in the stereo FM buffer
if (PicoOpt & 1) { if (PicoOpt & 1)
buf32_updated = YM2612UpdateOne(buf32, length, stereo, 1); buf32_updated = YM2612UpdateOne(buf32, length, stereo, 1);
} else else
memset32(buf32, 0, length<<stereo); memset32(buf32, 0, length<<stereo);
//printf("active_chs: %02x\n", buf32_updated); //printf("active_chs: %02x\n", buf32_updated);

View file

@ -20,7 +20,7 @@
#define FAMEC_CHECK_BRANCHES #define FAMEC_CHECK_BRANCHES
#define FAMEC_EXTRA_INLINE #define FAMEC_EXTRA_INLINE
// #define FAMEC_DEBUG // #define FAMEC_DEBUG
//#define FAMEC_NO_GOTOS #define FAMEC_NO_GOTOS
#define FAMEC_ADR_BITS 24 #define FAMEC_ADR_BITS 24
// #define FAMEC_FETCHBITS 8 // #define FAMEC_FETCHBITS 8
#define FAMEC_DATABITS 8 #define FAMEC_DATABITS 8
@ -506,6 +506,7 @@ static u32 Opcode;
static s32 cycles_needed; static s32 cycles_needed;
static u16 *PC; static u16 *PC;
static u32 BasePC; static u32 BasePC;
static u32 flag_C;
static u32 flag_V; static u32 flag_V;
static u32 flag_NotZ; static u32 flag_NotZ;
static u32 flag_N; static u32 flag_N;

View file

@ -469,8 +469,8 @@ static void vidResetMode(void)
/* sound stuff */ /* sound stuff */
#define SOUND_BLOCK_SIZE_NTSC (2940*2) // 1024 // 1152 #define SOUND_BLOCK_SIZE_NTSC (1470*2) // 1024 // 1152
#define SOUND_BLOCK_SIZE_PAL (3528*2) #define SOUND_BLOCK_SIZE_PAL (1764*2)
#define SOUND_BLOCK_COUNT 4 #define SOUND_BLOCK_COUNT 4
static short __attribute__((aligned(4))) sndBuffer[SOUND_BLOCK_SIZE_PAL*SOUND_BLOCK_COUNT + 44100/50*2]; static short __attribute__((aligned(4))) sndBuffer[SOUND_BLOCK_SIZE_PAL*SOUND_BLOCK_COUNT + 44100/50*2];
@ -490,8 +490,9 @@ static int sound_thread(SceSize args, void *argp)
while (!sound_thread_exit) while (!sound_thread_exit)
{ {
if (samples_made - samples_done < samples_block) { if (samples_made - samples_done < samples_block) {
// wait for data... // wait for data (use at least 2 blocks)
//lprintf("sthr: wait... (%i/%i)\n", samples_done, samples_made); //lprintf("sthr: wait... (%i)\n", samples_made - samples_done);
while (samples_made - samples_done <= samples_block*2 && !sound_thread_exit)
ret = sceKernelWaitSema(sound_sem, 1, 0); ret = sceKernelWaitSema(sound_sem, 1, 0);
//lprintf("sthr: sceKernelWaitSema: %i\n", ret); //lprintf("sthr: sceKernelWaitSema: %i\n", ret);
continue; continue;
@ -507,6 +508,14 @@ static int sound_thread(SceSize args, void *argp)
snd_playptr = sndBuffer; snd_playptr = sndBuffer;
if (ret) if (ret)
lprintf("sthr: outf: %i; pos %i/%i\n", ret, samples_done, samples_made); lprintf("sthr: outf: %i; pos %i/%i\n", ret, samples_done, samples_made);
// shouln't happen, but just in case
if (samples_made - samples_done >= samples_block*3) {
//lprintf("block skip (%i)\n", samples_made - samples_done);
samples_done += samples_block; // skip
snd_playptr += samples_block;
}
} }
lprintf("sthr: exit\n"); lprintf("sthr: exit\n");
@ -546,8 +555,7 @@ static void sound_prepare(void)
stereo=(PicoOpt&8)>>3; stereo=(PicoOpt&8)>>3;
samples_block = Pico.m.pal ? SOUND_BLOCK_SIZE_PAL : SOUND_BLOCK_SIZE_NTSC; samples_block = Pico.m.pal ? SOUND_BLOCK_SIZE_PAL : SOUND_BLOCK_SIZE_NTSC;
if (PsndRate == 22050) samples_block /= 2; if (PsndRate <= 22050) samples_block /= 2;
else if (PsndRate == 11025) samples_block /= 4;
sndBuffer_endptr = &sndBuffer[samples_block*SOUND_BLOCK_COUNT]; sndBuffer_endptr = &sndBuffer[samples_block*SOUND_BLOCK_COUNT];
lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n", lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n",
@ -606,7 +614,7 @@ static void writeSound(int len)
// signal the snd thread // signal the snd thread
samples_made += len; samples_made += len;
if (samples_made - samples_done >= samples_block) { if (samples_made - samples_done > samples_block*2) {
// lprintf("signal, %i/%i\n", samples_done, samples_made); // lprintf("signal, %i/%i\n", samples_done, samples_made);
ret = sceKernelSignalSema(sound_sem, 1); ret = sceKernelSignalSema(sound_sem, 1);
// lprintf("signal ret %i\n", ret); // lprintf("signal ret %i\n", ret);
@ -938,12 +946,10 @@ void emu_Loop(void)
int tval_diff; int tval_diff;
tval = sceKernelGetSystemTimeLow(); tval = sceKernelGetSystemTimeLow();
tval_diff = (int)(tval - tval_thissec) << 8; tval_diff = (int)(tval - tval_thissec) << 8;
if (tval_diff > lim_time) if (tval_diff > lim_time && (frames_done/16 < frames_shown))
{ {
// no time left for this frame - skip // no time left for this frame - skip
if (tval_diff - lim_time >= (300000<<8)) { if (tval_diff - lim_time >= (300000<<8)) {
/* something caused a slowdown for us (disk access? cache flush?)
* try to recover by resetting timing... */
reset_timing = 1; reset_timing = 1;
continue; continue;
} }