sound code rewrite for lower sample rates (except mp3s)

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@30 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-02-06 22:25:53 +00:00
parent 1cd356a33d
commit 7a93adeb29
9 changed files with 98 additions and 108 deletions

View file

@ -537,6 +537,12 @@ int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)
}
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 */
shared_ctl->writebuffsel ^= 1;
shared_ctl->length = length;

View file

@ -4,7 +4,6 @@ static _940_data_t *shared_data = (_940_data_t *) 0x00100000;
static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x00200000;
static unsigned char *mp3_data = (unsigned char *) 0x01000000;
YM2612 *ym2612_940;
int *mix_buffer;
// from init.s
void wait_irq(void);
@ -59,8 +58,8 @@ static void mp3_decode(void)
void Main940(int startvector, int pc_at_irq)
{
int mix_buffer = shared_data->mix_buffer;
ym2612_940 = &shared_data->ym2612;
mix_buffer = shared_data->mix_buffer;
// debug
shared_ctl->vstarts[startvector]++;

View file

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