unify helix mp3 code, some sound adjustments

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@726 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2009-08-02 19:42:12 +00:00
parent 3328d53bb7
commit 7c34867ab6
6 changed files with 119 additions and 191 deletions

View file

@ -405,24 +405,24 @@ int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)
}
/***********************************************************/
static int mp3_samples_ready = 0, mp3_buffer_offs = 0;
static int mp3_play_bufsel = 0, mp3_job_started = 0;
void mp3_update(int *buffer, int length, int stereo)
{
int length_mp3;
int cdda_on;
// playback was started, track not ended
cdda_on = loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len;
if (!cdda_on) return;
if (!(PicoOpt&0x200)) {
if (!(PicoOpt & POPT_EXT_FM)) {
mp3_update_local(buffer, length, stereo);
return;
}
// check if playback was started, track not ended
if (loaded_mp3 == NULL || shared_ctl->mp3_offs >= shared_ctl->mp3_len)
return;
length_mp3 = length;
if (PsndRate == 22050) length_mp3 <<= 1; // mp3s are locked to 44100Hz stereo
else if (PsndRate == 11025) length_mp3 <<= 2; // so make length 44100ish
@ -475,13 +475,15 @@ void mp3_update(int *buffer, int length, int stereo)
}
/***********************************************************/
void mp3_start_play(FILE *f, int pos) // pos is 0-1023
{
int byte_offs = 0;
if (!(PicoOpt&0x800)) { // cdda disabled?
if (!(PicoOpt & POPT_EN_MCD_CDDA) || f == NULL)
return;
if (!(PicoOpt & POPT_EXT_FM)) {
mp3_start_play_local(f, pos);
return;
}
@ -522,31 +524,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
mp3_job_started = 0;
shared_ctl->mp3_buffsel = 1; // will change to 0 on first decode
if (PicoOpt & POPT_EXT_FM)
{
add_job_940(JOB940_MP3RESET);
if (CHECK_BUSY(JOB940_MP3RESET)) wait_busy_940(JOB940_MP3RESET);
}
else
mp3_start_local();
add_job_940(JOB940_MP3RESET);
if (CHECK_BUSY(JOB940_MP3RESET)) wait_busy_940(JOB940_MP3RESET);
}
int mp3_get_offset(void)
{
unsigned int offs1024 = 0;
int cdda_on;
cdda_on = (PicoAHW & PAHW_MCD) && (PicoOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) &&
(Pico_mcd->scd.Status_CDC & 1) && loaded_mp3;
if (cdda_on) {
offs1024 = shared_ctl->mp3_offs << 7;
offs1024 /= shared_ctl->mp3_len >> 3;
}
printf("offs1024=%u (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len);
return offs1024;
}

View file

@ -61,32 +61,43 @@ static void mp3_decode(void)
if (bytesLeft <= 0) return; // EOF, nothing to do
retry:
offset = find_sync_word(readPtr, bytesLeft);
if (offset < 0) {
set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
return; // EOF
}
readPtr += offset;
bytesLeft -= offset;
for (retries = 0; retries < 2; retries++)
{
offset = find_sync_word(readPtr, bytesLeft);
if (offset < 0)
goto set_eof;
err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,
shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);
if (err) {
if (err == ERR_MP3_INDATA_UNDERFLOW) {
set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
return;
} else if (err <= -6 && err >= -12) {
// ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*
// just try to skip the offending frame..
readPtr++;
bytesLeft--;
if (retries++ < 2) goto retry;
readPtr += offset;
bytesLeft -= offset;
err = MP3Decode(shared_data->mp3dec, &readPtr, &bytesLeft,
shared_data->mp3_buffer[shared_ctl->mp3_buffsel], 0);
if (err) {
if (err == ERR_MP3_MAINDATA_UNDERFLOW)
// just need another frame
continue;
if (err == ERR_MP3_INDATA_UNDERFLOW)
goto set_eof;
if (err <= -6 && err >= -12) {
// ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*
// just try to skip the offending frame..
readPtr++;
bytesLeft--;
continue;
}
shared_ctl->mp3_errors++;
shared_ctl->mp3_lasterr = err;
}
shared_ctl->mp3_errors++;
shared_ctl->mp3_lasterr = err;
break;
}
set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, readPtr - mp3_data);
return;
set_eof:
set_if_not_changed(&shared_ctl->mp3_offs, mp3_offs, shared_ctl->mp3_len);
}
static void ym_flush_writes(void)

View file

@ -9,9 +9,10 @@ export CROSS = arm-linux-
# settings
#up = 1
DEFINC = -I../.. -I. -D__GP2X__ -DARM # -DBENCHMARK
COPT_COMMON = -static -s -O2 -ftracer -fstrength-reduce -Wall -fomit-frame-pointer -fstrict-aliasing -ffast-math
COPT = $(COPT_COMMON) -mtune=arm940t
DEFINC = -I../.. -I. -D__GP2X__ -DARM
# -ftracer
COPT_COMMON = -static -s -O2 -Wall -fomit-frame-pointer -fstrict-aliasing -ffast-math
CFLAGS = $(COPT_COMMON) $(DEFINC) -mcpu=arm940t -mtune=arm940t
GCC = $(CROSS)gcc
STRIP = $(CROSS)strip
AS = $(CROSS)as
@ -25,16 +26,16 @@ all: $(BIN)
.c.o:
@echo ">>>" $<
$(GCC) $(COPT) $(DEFINC) -c $< -o $@
$(GCC) $(CFLAGS) -c $< -o $@
.s.o:
@echo ">>>" $<
$(GCC) $(COPT) $(DEFINC) -c $< -o $@
$(GCC) $(CFLAGS) -c $< -o $@
# stuff for 940 core
# init, emu_control, emu
OBJS940 += 940init.o 940.o 940ym2612.o memcpy.o mix.o misc.o
OBJS940 += 940init.o 940.o 940ym2612.o memcpy.o misc_arm.o
# the asm code seems to be faster when run on 920, but not on 940 for some reason
# OBJS940 += ../../Pico/sound/ym2612_asm.o
@ -43,24 +44,24 @@ OBJS940 += uClibc/memset.o uClibc/s_floor.o uClibc/e_pow.o uClibc/e_sqrt.o uClib
OBJS940 += uClibc/s_scalbn.o uClibc/s_copysign.o uClibc/k_sin.o uClibc/k_cos.o uClibc/s_sin.o
OBJS940 += uClibc/e_rem_pio2.o uClibc/k_rem_pio2.o uClibc/e_log.o uClibc/wrappers.o
$(BIN) : code940.gpe
$(BIN) : code940.elf
@echo ">>>" $@
$(OBJCOPY) -O binary $< $@
code940.gpe : $(OBJS940) ../../common/helix/helix_mp3.a
code940.elf : $(OBJS940) ../../common/helix/$(CROSS)helix-mp3.a
@echo ">>>" $@
$(LD) -static -e code940 -Ttext 0x0 $^ -L$(lgcc_path) -lgcc -o $@ -Map code940.map
940ym2612.o : ../../../Pico/sound/ym2612.c
940ym2612.o : ../../../pico/sound/ym2612.c
@echo ">>>" $@
$(GCC) $(COPT) -Os $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@
$(GCC) $(CFLAGS) -Os -DEXTERNAL_YM2612 -c $< -o $@
mix.o : ../../../Pico/sound/mix.s
mix.o : ../../../pico/sound/mix.s
@echo ">>>" $@
$(GCC) $(COPT) $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@
misc.o : ../../../Pico/Misc.s
$(GCC) $(CFLAGS) -DEXTERNAL_YM2612 -c $< -o $@
misc_arm.o : ../../../pico/misc_arm.s
@echo ">>>" $@
$(GCC) $(COPT) $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@
$(GCC) $(CFLAGS) -DEXTERNAL_YM2612 -c $< -o $@
../../common/helix/helix_mp3.a:
@make -C ../../common/helix/
@ -72,9 +73,9 @@ up: $(BIN)
# cleanup
clean: tidy
@$(RM) code940.bin
$(RM) $(BIN)
tidy:
@$(RM) code940.gpe $(OBJS940) code940.map
$(RM) code940.elf $(OBJS940) code940.map
OBJSMP3T = mp3test.o ../gp2x.o ../asmutils.o ../usbjoy.o
@ -89,8 +90,8 @@ cleanmp3test:
# uClibc/e_pow.o : uClibc/e_pow.c
# @echo $<
# @$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@
# @$(GCC) $(CFLAGS) -fno-profile-generate -c $< -o $@
# uClibc/e_sqrt.o : uClibc/e_sqrt.c
# @echo $<
# @$(GCC) $(COPT) $(DEFINC) -fno-profile-generate -c $< -o $@
# @$(GCC) $(CFLAGS) -fno-profile-generate -c $< -o $@

View file

@ -409,6 +409,7 @@ void plat_status_msg_busy_next(const char *msg)
{
plat_status_msg_clear();
pemu_update_display("", msg);
emu_status_msg("");
/* assumption: msg_busy_next gets called only when
* something slow is about to happen */
@ -600,22 +601,26 @@ static void updateSound(int len)
void pemu_sound_start(void)
{
static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
int target_fps = Pico.m.pal ? 50 : 60;
PsndOut = NULL;
// prepare sound stuff
if (currentConfig.EmuOpt & 4)
if (currentConfig.EmuOpt & EOPT_EN_SOUND)
{
int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;
int target_fps = Pico.m.pal ? 50 : 60;
int snd_excess_add;
if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old ||
((PicoOpt&0x200) && crashed_940)) {
gp2x_soc_t soc;
#define SOUND_RERATE_FLAGS (POPT_EN_FM|POPT_EN_PSG|POPT_EN_STEREO|POPT_EXT_FM|POPT_EN_MCD_CDDA)
if (PsndRate != PsndRate_old || Pico.m.pal != pal_old || ((PicoOpt & POPT_EXT_FM) && crashed_940) ||
((PicoOpt ^ PicoOpt_old) & SOUND_RERATE_FLAGS)) {
PsndRerate(Pico.m.frame_count ? 1 : 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);
sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);
PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);
sndout_oss_start(PsndRate, 16, is_stereo);
sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
PicoWriteSound = updateSound;
plat_update_volume(0, 0);
@ -624,6 +629,11 @@ void pemu_sound_start(void)
PsndRate_old = PsndRate;
PicoOpt_old = PicoOpt;
pal_old = Pico.m.pal;
/* Wiz's sound hardware needs more prebuffer */
soc = soc_detect();
if (soc == SOCID_POLLUX)
updateSound(PsndLen);
}
}