sound code rewrite for lower sample rates (except mp3s)

git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@30 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-02-06 22:25:53 +00:00
parent 7bc9cd7fe1
commit 3ef975c9e4
2 changed files with 13 additions and 24 deletions

View file

@ -537,6 +537,12 @@ int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)
} }
writebuff_ptr = 0; writebuff_ptr = 0;
/* predict sample counter for next frame */
if (PsndLen_exc_add) {
if (PsndLen_exc_cnt + PsndLen_exc_add >= 0x10000) length = PsndLen + 1;
else length = PsndLen;
}
/* give 940 ym job */ /* give 940 ym job */
shared_ctl->writebuffsel ^= 1; shared_ctl->writebuffsel ^= 1;
shared_ctl->length = length; shared_ctl->length = length;

View file

@ -48,6 +48,7 @@ unsigned char *rom_data = NULL;
extern int crashed_940; extern int crashed_940;
static short sndBuffer[2*44100/50];
static char noticeMsg[64]; // notice msg to draw static char noticeMsg[64]; // notice msg to draw
static struct timeval noticeMsgTime = { 0, 0 }; // when started showing static struct timeval noticeMsgTime = { 0, 0 }; // when started showing
static int reset_timing, osd_fps_x; static int reset_timing, osd_fps_x;
@ -927,24 +928,10 @@ static void updateKeys(void)
prevEvents = (allActions[0] | allActions[1]) >> 16; prevEvents = (allActions[0] | allActions[1]) >> 16;
} }
static int snd_excess_add = 0, snd_excess_cnt = 0; // hack
static void updateSound(void) static void updateSound(int len)
{ {
int len = (PicoOpt&8)?PsndLen*2:PsndLen; if (PicoOpt&8) len<<=1;
snd_excess_cnt += snd_excess_add;
if (snd_excess_cnt >= 0x10000) {
snd_excess_cnt -= 0x10000;
if (PicoOpt&8) {
PsndOut[len] = PsndOut[len-2];
PsndOut[len+1] = PsndOut[len-1];
len+=2;
} else {
PsndOut[len] = PsndOut[len-1];
len++;
}
}
gp2x_sound_write(PsndOut, len<<1); gp2x_sound_write(PsndOut, len<<1);
} }
@ -1024,22 +1011,23 @@ void emu_Loop(void)
// prepare sound stuff // prepare sound stuff
if(currentConfig.EmuOpt & 4) { if(currentConfig.EmuOpt & 4) {
int snd_excess_add;
if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) { if(PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old || crashed_940) {
/* if 940 is turned off, we need it to be put back to sleep */ /* if 940 is turned off, we need it to be put back to sleep */
if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) { if (!(PicoOpt&0x200) && ((PicoOpt^PicoOpt_old)&0x200)) {
Reset940(1, 2); Reset940(1, 2);
Pause940(1); Pause940(1);
} }
sound_rerate(); sound_rerate(1);
} }
//excess_samples = PsndRate - PsndLen*target_fps; //excess_samples = PsndRate - PsndLen*target_fps;
snd_excess_cnt = 0;
snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps; snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal); printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);
gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3); gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3);
gp2x_sound_volume(currentConfig.volume, currentConfig.volume); gp2x_sound_volume(currentConfig.volume, currentConfig.volume);
PicoWriteSound = updateSound; PicoWriteSound = updateSound;
PsndOut = calloc((PicoOpt&8) ? (PsndLen*4+4) : (PsndLen*2+2), 1); memset(sndBuffer, 0, sizeof(sndBuffer));
PsndOut = sndBuffer;
PsndRate_old = PsndRate; PsndRate_old = PsndRate;
PsndLen_real = PsndLen; PsndLen_real = PsndLen;
PicoOpt_old = PicoOpt; PicoOpt_old = PicoOpt;
@ -1239,11 +1227,6 @@ if (Pico.m.frame_count == 31563) {
emu_SaveLoadGame(0, 1); emu_SaveLoadGame(0, 1);
SRam.changed = 0; SRam.changed = 0;
} }
if (PsndOut != 0) {
free(PsndOut);
PsndOut = 0;
}
} }