mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-05 14:57:46 -04:00
giz rc1 release
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@268 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
50cdcf97de
commit
11f4e72292
6 changed files with 270 additions and 155 deletions
|
@ -14,7 +14,7 @@
|
|||
#include "gp2x.h"
|
||||
#include "emu.h"
|
||||
#include "menu.h"
|
||||
#include "mp3.h"
|
||||
#include "../common/mp3.h"
|
||||
#include "../common/arm_utils.h"
|
||||
#include "../common/menu.h"
|
||||
#include "../common/emu.h"
|
||||
|
@ -533,9 +533,8 @@ void mp3_update(int *buffer, int length, int stereo)
|
|||
int length_mp3;
|
||||
int cdda_on;
|
||||
|
||||
// not data track, CDC is reading, playback was started, track not ended
|
||||
cdda_on = !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1) &&
|
||||
loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len;
|
||||
// playback was started, track not ended
|
||||
cdda_on = loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len;
|
||||
|
||||
if (!cdda_on) return;
|
||||
|
||||
|
@ -649,7 +648,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023
|
|||
|
||||
int mp3_get_offset(void)
|
||||
{
|
||||
int offs1024 = 0;
|
||||
unsigned int offs1024 = 0;
|
||||
int cdda_on;
|
||||
|
||||
cdda_on = (PicoMCD & 1) && (PicoOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) &&
|
||||
|
@ -657,10 +656,9 @@ int mp3_get_offset(void)
|
|||
|
||||
if (cdda_on) {
|
||||
offs1024 = shared_ctl->mp3_offs << 7;
|
||||
offs1024 /= shared_ctl->mp3_len;
|
||||
offs1024 <<= 3;
|
||||
offs1024 /= shared_ctl->mp3_len >> 3;
|
||||
}
|
||||
printf("offs1024=%i (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len);
|
||||
printf("offs1024=%u (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len);
|
||||
|
||||
return offs1024;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
# you may or may not need to change this
|
||||
#devkit_path = x:/stuff/dev/devkitgp2x/
|
||||
CROSS = arm-linux-
|
||||
export CROSS = arm-linux-
|
||||
#CROSS = $(devkit_path)bin/arm-linux-
|
||||
|
||||
# settings
|
||||
|
@ -58,7 +58,8 @@ OBJS += main.o menu.o gp2x.o usbjoy.o emu.o squidgehack.o cpuctrl.o
|
|||
OBJS += 940ctl.o
|
||||
|
||||
# common
|
||||
OBJS += ../common/emu.o ../common/menu.o ../common/fonts.o ../common/arm_utils.o ../common/readpng.o
|
||||
OBJS += ../common/emu.o ../common/menu.o ../common/fonts.o ../common/arm_utils.o \
|
||||
../common/readpng.o ../common/mp3_helix.o
|
||||
|
||||
# Pico
|
||||
ifeq "$(amalgamate)" "1"
|
||||
|
@ -111,8 +112,6 @@ OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/i
|
|||
../../zlib/deflate.o ../../zlib/crc32.o ../../zlib/adler32.o ../../zlib/zutil.o ../../zlib/compress.o
|
||||
# unzip
|
||||
OBJS += ../../unzip/unzip.o ../../unzip/unzip_stream.o
|
||||
# mp3
|
||||
OBJS += mp3.o
|
||||
# debug
|
||||
ifeq "$(debug_cyclone)" "1"
|
||||
OBJS += ../../Pico/_cyclone_debug.o ../../cpu/musashi/m68kdasm.o
|
||||
|
@ -138,7 +137,7 @@ endif
|
|||
|
||||
all: PicoDrive.gpe
|
||||
|
||||
PicoDrive.gpe : $(OBJS) helix/helix_mp3.a
|
||||
PicoDrive.gpe : $(OBJS) ../common/helix/helix_mp3.a
|
||||
@echo $@
|
||||
@$(GCC) -o $@ $(COPT) $^ -lm -lpng -Wl,-Map=PicoDrive.map
|
||||
ifeq ($(DEBUG),)
|
||||
|
@ -206,8 +205,8 @@ testrefr.gpe : test.o gp2x.o
|
|||
|
||||
|
||||
# build helix libs
|
||||
helix/helix_mp3.a:
|
||||
make -C helix
|
||||
../common/helix/helix_mp3.a:
|
||||
make -C ../common/helix
|
||||
|
||||
|
||||
# cleanup
|
||||
|
|
137
gp2x/mp3.c
137
gp2x/mp3.c
|
@ -1,137 +0,0 @@
|
|||
// Some mp3 related code for Sega/Mega CD
|
||||
// (c) Copyright 2007, Grazvydas "notaz" Ignotas
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../Pico/sound/mix.h"
|
||||
#include "code940/940shared.h"
|
||||
#include "helix/pub/mp3dec.h"
|
||||
|
||||
static short mp3_out_buffer[2*1152];
|
||||
static HMP3Decoder mp3dec = 0;
|
||||
static int mp3_buffer_offs = 0;
|
||||
|
||||
extern _940_ctl_t *shared_ctl;
|
||||
extern unsigned char *mp3_mem;
|
||||
extern int PsndRate;
|
||||
|
||||
|
||||
static int try_get_header(unsigned char *buff, MP3FrameInfo *fi)
|
||||
{
|
||||
int ret, offs1, offs = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
offs1 = MP3FindSyncWord(buff + offs, 2048 - offs);
|
||||
if (offs1 < 0) return -2;
|
||||
offs += offs1;
|
||||
if (2048 - offs < 4) return -3;
|
||||
|
||||
// printf("trying header %08x\n", *(int *)(buff + offs));
|
||||
|
||||
ret = MP3GetNextFrameInfo(mp3dec, fi, buff + offs);
|
||||
if (ret == 0 && fi->bitrate != 0) break;
|
||||
offs++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mp3_get_bitrate(FILE *f, int len)
|
||||
{
|
||||
unsigned char buff[2048];
|
||||
MP3FrameInfo fi;
|
||||
int ret;
|
||||
|
||||
memset(buff, 0, 2048);
|
||||
|
||||
if (!mp3dec) mp3dec = MP3InitDecoder();
|
||||
|
||||
fseek(f, 0, SEEK_SET);
|
||||
ret = fread(buff, 1, 2048, f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
if (ret <= 0) return -1;
|
||||
|
||||
ret = try_get_header(buff, &fi);
|
||||
if (ret != 0 || fi.bitrate == 0) {
|
||||
// try to read somewhere around the middle
|
||||
fseek(f, len>>1, SEEK_SET);
|
||||
fread(buff, 1, 2048, f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
ret = try_get_header(buff, &fi);
|
||||
}
|
||||
if (ret != 0) return ret;
|
||||
|
||||
// printf("bitrate: %i\n", fi.bitrate / 1000);
|
||||
|
||||
return fi.bitrate / 1000;
|
||||
}
|
||||
|
||||
|
||||
static void mp3_decode(void)
|
||||
{
|
||||
// tried copying this to cached mem, no improvement noticed
|
||||
int mp3_offs = shared_ctl->mp3_offs;
|
||||
unsigned char *readPtr = mp3_mem + mp3_offs;
|
||||
int bytesLeft = shared_ctl->mp3_len - mp3_offs;
|
||||
int offset; // frame offset from readPtr
|
||||
int err;
|
||||
|
||||
if (bytesLeft <= 0) return; // EOF, nothing to do
|
||||
|
||||
offset = MP3FindSyncWord(readPtr, bytesLeft);
|
||||
if (offset < 0) {
|
||||
shared_ctl->mp3_offs = shared_ctl->mp3_len;
|
||||
return; // EOF
|
||||
}
|
||||
readPtr += offset;
|
||||
bytesLeft -= offset;
|
||||
|
||||
err = MP3Decode(mp3dec, &readPtr, &bytesLeft, mp3_out_buffer, 0);
|
||||
if (err) {
|
||||
if (err == ERR_MP3_INDATA_UNDERFLOW) {
|
||||
shared_ctl->mp3_offs = shared_ctl->mp3_len; // EOF
|
||||
return;
|
||||
} else if (err <= -6 && err >= -12) {
|
||||
// ERR_MP3_INVALID_FRAMEHEADER, ERR_MP3_INVALID_*
|
||||
// just try to skip the offending frame..
|
||||
readPtr++;
|
||||
}
|
||||
shared_ctl->mp3_errors++;
|
||||
shared_ctl->mp3_lasterr = err;
|
||||
}
|
||||
shared_ctl->mp3_offs = readPtr - mp3_mem;
|
||||
}
|
||||
|
||||
|
||||
void mp3_update_local(int *buffer, int length, int stereo)
|
||||
{
|
||||
int length_mp3, shr = 0;
|
||||
void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
|
||||
|
||||
length_mp3 = length;
|
||||
if (PsndRate == 22050) { mix_samples = mix_16h_to_32_s1; length_mp3 <<= 1; shr = 1; }
|
||||
else if (PsndRate == 11025) { mix_samples = mix_16h_to_32_s2; length_mp3 <<= 2; shr = 2; }
|
||||
|
||||
if (1152 - mp3_buffer_offs >= length_mp3) {
|
||||
mix_samples(buffer, mp3_out_buffer + mp3_buffer_offs*2, length<<1);
|
||||
|
||||
mp3_buffer_offs += length_mp3;
|
||||
} else {
|
||||
int left = 1152 - mp3_buffer_offs;
|
||||
|
||||
mix_samples(buffer, mp3_out_buffer + mp3_buffer_offs*2, (left>>shr)<<1);
|
||||
mp3_decode();
|
||||
mp3_buffer_offs = length_mp3 - left;
|
||||
mix_samples(buffer + ((left>>shr)<<1), mp3_out_buffer, (mp3_buffer_offs>>shr)<<1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mp3_start_local(void)
|
||||
{
|
||||
mp3_buffer_offs = 0;
|
||||
mp3_decode();
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
void mp3_update_local(int *buffer, int length, int stereo);
|
||||
void mp3_start_local(void);
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue