#ifndef PICO_H\r
#define PICO_H\r
\r
-#include <stdio.h>\r
+//#include <stdio.h>\r
\r
// port-specific compile-time settings\r
#include <port_config.h>\r
#endif\r
\r
// external funcs for Sega/Mega CD\r
-extern int mp3_get_bitrate(FILE *f, int size);\r
-extern void mp3_start_play(FILE *f, int pos);\r
+extern int mp3_get_bitrate(void *f, int size);\r
+extern void mp3_start_play(void *f, int pos);\r
extern void mp3_update(int *buffer, int length, int stereo);\r
\r
// this function should write-back d-cache and invalidate i-cache\r
--- /dev/null
+#include "mp3.h"
+
+int mp3_find_sync_word(const unsigned char *buf, int size)
+{
+ const unsigned char *p, *pe;
+
+ /* find byte-aligned syncword - need 12 (MPEG 1,2) or 11 (MPEG 2.5) matching bits */
+ for (p = buf, pe = buf + size - 3; p <= pe; p++)
+ {
+ int pn;
+ if (p[0] != 0xff)
+ continue;
+ pn = p[1];
+ if ((pn & 0xf8) != 0xf8 || // currently must be MPEG1
+ (pn & 6) == 0) { // invalid layer
+ p++; continue;
+ }
+ pn = p[2];
+ if ((pn & 0xf0) < 0x20 || (pn & 0xf0) == 0xf0 || // bitrates
+ (pn & 0x0c) != 0) { // not 44kHz
+ continue;
+ }
+
+ return p - buf;
+ }
+
+ return -1;
+}
+
+int mp3_find_sync_word(const unsigned char *buf, int size);
+
#ifdef __GP2X__
void mp3_update_local(int *buffer, int length, int stereo);
-void mp3_start_play_local(FILE *f, int pos);
+void mp3_start_play_local(void *f, int pos);
#endif
#define mp3_start_play mp3_start_play_local
#endif
-static int find_sync_word(unsigned char *buf, int nBytes)
-{
- unsigned char *p, *pe;
-
- /* find byte-aligned syncword - need 12 (MPEG 1,2) or 11 (MPEG 2.5) matching bits */
- for (p = buf, pe = buf + nBytes - 4; p < pe; p++)
- {
- int pn;
- if (p[0] != 0xff) continue;
- pn = p[1];
- if ((pn & 0xf8) != 0xf8 || // currently must be MPEG1
- (pn & 6) == 0) { // invalid layer
- p++; continue;
- }
- pn = p[2];
- if ((pn & 0xf0) < 0x20 || (pn & 0xf0) == 0xf0 || // bitrates
- (pn & 0x0c) != 0) { // not 44kHz
- continue;
- }
-
- return p - buf;
- }
-
- return -1;
-}
-
static int try_get_header(unsigned char *buff, MP3FrameInfo *fi)
{
int ret, offs1, offs = 0;
while (1)
{
- offs1 = find_sync_word(buff + offs, 2048 - offs);
+ offs1 = mp3_find_sync_word(buff + offs, 2048 - offs);
if (offs1 < 0) return -2;
offs += offs1;
if (2048 - offs < 4) return -3;
return ret;
}
-int mp3_get_bitrate(FILE *f, int len)
+int mp3_get_bitrate(void *f_, int len)
{
unsigned char buff[2048];
MP3FrameInfo fi;
+ FILE *f = f_;
int ret;
- memset(buff, 0, 2048);
+ memset(buff, 0, sizeof(buff));
- if (mp3dec) MP3FreeDecoder(mp3dec);
+ if (mp3dec)
+ MP3FreeDecoder(mp3dec);
mp3dec = MP3InitDecoder();
fseek(f, 0, SEEK_SET);
- ret = fread(buff, 1, 2048, f);
+ ret = fread(buff, 1, sizeof(buff), f);
fseek(f, 0, SEEK_SET);
- if (ret <= 0) return -1;
+ if (ret <= 0)
+ return -1;
ret = try_get_header(buff, &fi);
if (ret != 0 || fi.bitrate == 0) {
fseek(f, 0, SEEK_SET);
ret = try_get_header(buff, &fi);
}
- if (ret != 0) return ret;
+ if (ret != 0)
+ return ret;
// printf("bitrate: %i\n", fi.bitrate / 1000);
fseek(mp3_current_file, mp3_file_pos, SEEK_SET);
bytesLeft = fread(mp3_input_buffer, 1, sizeof(mp3_input_buffer), mp3_current_file);
- offset = find_sync_word(mp3_input_buffer, bytesLeft);
+ offset = mp3_find_sync_word(mp3_input_buffer, bytesLeft);
if (offset < 0) {
lprintf("find_sync_word (%i/%i) err %i\n", mp3_file_pos, mp3_file_len, offset);
mp3_file_pos = mp3_file_len;
return 0;
}
-void mp3_start_play(FILE *f, int pos)
+void mp3_start_play(void *f_, int pos)
{
+ FILE *f = f_;
+
mp3_file_len = mp3_file_pos = 0;
mp3_current_file = NULL;
mp3_buffer_offs = 0;
fseek(f, 0, SEEK_END);
mp3_file_len = ftell(f);
+ // search for first sync word, skipping stuff like ID3 tags
+ while (mp3_file_pos < 128*1024) {
+ int offs, bytes;
+
+ fseek(f, mp3_file_pos, SEEK_SET);
+ bytes = fread(mp3_input_buffer, 1, sizeof(mp3_input_buffer), f);
+ if (bytes < 4)
+ break;
+ offs = mp3_find_sync_word(mp3_input_buffer, bytes);
+ if (offs >= 0) {
+ mp3_file_pos += offs;
+ break;
+ }
+ mp3_file_pos += bytes - 2;
+ }
+
// seek..
if (pos) {
- unsigned long long pos64 = mp3_file_len;
+ unsigned long long pos64 = mp3_file_len - mp3_file_pos;
pos64 *= pos;
- mp3_file_pos = pos64 >> 10;
+ mp3_file_pos += pos64 >> 10;
}
mp3_decode();
}\r
\r
\r
-void mp3_start_play(FILE *f, int pos) // pos is 0-1023\r
+void mp3_start_play(void *f_, int pos) // pos is 0-1023\r
{\r
int byte_offs = 0;\r
+ FILE *f = f_;\r
\r
if (!(PicoOpt & POPT_EN_MCD_CDDA) || f == NULL)\r
return;\r
# common\r
OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o platform/common/config.o \\r
platform/common/arm_utils.o platform/common/arm_linux.o platform/common/readpng.o \\r
- platform/common/mp3_helix.o platform/common/input.o platform/common/main.o \\r
+ platform/common/mp3_helix.o platform/common/input.o platform/common/main.o platform/common/mp3.o \\r
platform/linux/sndout_oss.o platform/linux/plat.o platform/linux/in_evdev.o\r
\r
# unzip\r
// (c) Copyright 2006-2007, Grazvydas "notaz" Ignotas\r
\r
#include "940shared.h"\r
+#include "../../common/mp3.h"\r
\r
static _940_data_t *shared_data = (_940_data_t *) 0x00100000;\r
static _940_ctl_t *shared_ctl = (_940_ctl_t *) 0x00200000;\r
// asm volatile ("mcr p15, 0, r0, c7, c10, 4" ::: "r0"); /* drain write buffer */\r
\r
\r
-static int find_sync_word(unsigned char *buf, int nBytes)\r
-{\r
- unsigned char *p, *pe;\r
-\r
- /* find byte-aligned syncword - need 12 (MPEG 1,2) or 11 (MPEG 2.5) matching bits */\r
- for (p = buf, pe = buf + nBytes - 4; p < pe; p++)\r
- {\r
- int pn;\r
- if (p[0] != 0xff) continue;\r
- pn = p[1];\r
- if ((pn & 0xf8) != 0xf8 || // currently must be MPEG1\r
- (pn & 6) == 0) { // invalid layer\r
- p++; continue;\r
- }\r
- pn = p[2];\r
- if ((pn & 0xf0) < 0x20 || (pn & 0xf0) == 0xf0 || // bitrates\r
- (pn & 0x0c) != 0) { // not 44kHz\r
- continue;\r
- }\r
-\r
- return p - buf;\r
- }\r
-\r
- return -1;\r
-}\r
-\r
static void mp3_decode(void)\r
{\r
int mp3_offs = shared_ctl->mp3_offs;\r
\r
for (retries = 0; retries < 2; retries++)\r
{\r
- offset = find_sync_word(readPtr, bytesLeft);\r
+ offset = mp3_find_sync_word(readPtr, bytesLeft);\r
if (offset < 0)\r
goto set_eof;\r
\r
LD = $(CROSS)ld\r
OBJCOPY = $(CROSS)objcopy\r
\r
+vpath %.c = ../../common\r
+\r
BIN = pico940_v3.bin\r
\r
all: $(BIN)\r
\r
-\r
.c.o:\r
@echo ">>>" $<\r
$(GCC) $(CFLAGS) -c $< -o $@\r
# stuff for 940 core\r
\r
# init, emu_control, emu\r
-OBJS940 += 940init.o 940.o 940ym2612.o memcpy.o misc_arm.o\r
+OBJS940 += 940init.o 940.o 940ym2612.o memcpy.o misc_arm.o mp3.o\r
# the asm code seems to be faster when run on 920, but not on 940 for some reason\r
# OBJS940 += ../../Pico/sound/ym2612_asm.o\r
\r
}
/* misc */
-int mp3_get_bitrate(FILE *f, int size)
+int mp3_get_bitrate(void *f, int size)
{
return 128;
}
-void mp3_start_play(FILE *f, int pos)
+void mp3_start_play(void *f, int pos)
{
}
# common\r
OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o platform/common/config.o \\r
platform/common/arm_utils.o platform/common/mp3_helix.o platform/common/arm_linux.o \\r
- platform/common/readpng.o platform/common/input.o platform/common/main.o \\r
+ platform/common/readpng.o platform/common/input.o platform/common/main.o platform/common/mp3.o \\r
platform/linux/fbdev.o platform/linux/in_evdev.o platform/linux/sndout_oss.o \\r
platform/linux/plat.o platform/linux/oshide.o\r
\r
\r
void plat_status_msg_clear(void)\r
{\r
- vout_fbdev_clear_lines(layer_fb, g_screen_height - 8, 8);\r
+ vout_fbdev_clear_lines(layer_fb, g_osd_y, 8);\r
}\r
\r
void plat_status_msg_busy_next(const char *msg)\r
// might be called before initialization
-int mp3_get_bitrate(FILE *f, int size)
+int mp3_get_bitrate(void *f, int size)
{
int ret, retval = -1, sample_rate, bitrate;
// filenames are stored instead handles in PSP, due to stupid max open file limit
- char *fname = (char *)f;
+ char *fname = f;
/* make sure thread is not busy.. */
if (thread_busy_sem >= 0)
static int mp3_job_started = 0, mp3_samples_ready = 0, mp3_buffer_offs = 0, mp3_play_bufsel = 0;
-void mp3_start_play(FILE *f, int pos)
+void mp3_start_play(void *f, int pos)
{
- char *fname = (char *)f;
+ char *fname = f;
if (!initialized) return;
}
// required by pico
-int mp3_get_bitrate(FILE *f, int size)
+int mp3_get_bitrate(void *f, int size)
{
return 128;
}
-void mp3_start_play(FILE *f, int pos)
+void mp3_start_play(void *f, int pos)
{
}