Merge pull request #858 from bnnm/mpeg

mpeg
This commit is contained in:
bnnm 2021-05-08 15:39:02 +02:00 committed by GitHub
commit 5757eee603
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 609 additions and 594 deletions

View File

@ -16,7 +16,7 @@ static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data
/* Inits regular MPEG */
mpeg_codec_data *init_mpeg(STREAMFILE *streamfile, off_t start_offset, coding_t *coding_type, int channels) {
mpeg_codec_data* init_mpeg(STREAMFILE* sf, off_t start_offset, coding_t* coding_type, int channels) {
mpeg_codec_data* data = NULL;
/* init codec */
@ -41,14 +41,16 @@ mpeg_codec_data *init_mpeg(STREAMFILE *streamfile, off_t start_offset, coding_t
size_t samples_per_frame;
struct mpg123_frameinfo mi;
//todo read single big buffer then add +1 up to a few max bytes, or just read once only
/* read first frame(s) */
do {
size_t bytes_done;
if (read_streamfile(data->buffer, start_offset+read_offset, data->buffer_size, streamfile) != data->buffer_size)
goto fail;
size_t bytes_read, bytes_done;
/* don't check max as sfx can be smaller than buffer */
bytes_read = read_streamfile(data->buffer, start_offset + read_offset, data->buffer_size, sf);
read_offset += 1;
rc = mpg123_decode(main_m, data->buffer,data->buffer_size, NULL,0, &bytes_done);
rc = mpg123_decode(main_m, data->buffer, bytes_read, NULL,0, &bytes_done);
if (rc != MPG123_OK && rc != MPG123_NEW_FORMAT && rc != MPG123_NEED_MORE) {
VGM_LOG("MPEG: unable to set up mpg123 at start offset\n");
goto fail; //handle MPG123_DONE?
@ -111,7 +113,7 @@ fail:
/* Init custom MPEG, with given type and config */
mpeg_codec_data *init_mpeg_custom(STREAMFILE *streamFile, off_t start_offset, coding_t *coding_type, int channels, mpeg_custom_t type, mpeg_custom_config *config) {
mpeg_codec_data* init_mpeg_custom(STREAMFILE* sf, off_t start_offset, coding_t* coding_type, int channels, mpeg_custom_t type, mpeg_custom_config* config) {
mpeg_codec_data* data = NULL;
int i, ok;
@ -132,10 +134,10 @@ mpeg_codec_data *init_mpeg_custom(STREAMFILE *streamFile, off_t start_offset, co
case MPEG_EAL31:
case MPEG_EAL31b:
case MPEG_EAL32P:
case MPEG_EAL32S: ok = mpeg_custom_setup_init_ealayer3(streamFile, start_offset, data, coding_type); break;
case MPEG_AWC: ok = mpeg_custom_setup_init_awc(streamFile, start_offset, data, coding_type); break;
case MPEG_EAMP3: ok = mpeg_custom_setup_init_eamp3(streamFile, start_offset, data, coding_type); break;
default: ok = mpeg_custom_setup_init_default(streamFile, start_offset, data, coding_type); break;
case MPEG_EAL32S: ok = mpeg_custom_setup_init_ealayer3(sf, start_offset, data, coding_type); break;
case MPEG_AWC: ok = mpeg_custom_setup_init_awc(sf, start_offset, data, coding_type); break;
case MPEG_EAMP3: ok = mpeg_custom_setup_init_eamp3(sf, start_offset, data, coding_type); break;
default: ok = mpeg_custom_setup_init_default(sf, start_offset, data, coding_type); break;
}
if (!ok)
goto fail;
@ -219,7 +221,7 @@ fail:
/************/
void decode_mpeg(VGMSTREAM* vgmstream, sample_t* outbuf, int32_t samples_to_do, int channels) {
mpeg_codec_data * data = (mpeg_codec_data *) vgmstream->codec_data;
mpeg_codec_data* data = vgmstream->codec_data;
if (!data->custom) {
decode_mpeg_standard(&vgmstream->ch[0], data, outbuf, samples_to_do, channels);

View File

@ -231,15 +231,26 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
case 0xB9: sample_rate = 30000; break; //?
case 0xB8: sample_rate = 28000; break; //?
case 0xB6: sample_rate = 22050; break;
case 0xB4: sample_rate = 18000; break; //?
case 0xB2: sample_rate = 16000; break; //?
case 0xB0: sample_rate = 15000; break; //?
case 0xAF: sample_rate = 14000; break; //?
case 0xAE: sample_rate = 13000; break; //?
case 0xAD: sample_rate = 12500; break; //?
case 0xAC: sample_rate = 12000; break; //?
case 0xAB: sample_rate = 11050; break; //?
case 0xAA: sample_rate = 11025; break;
case 0xA9: sample_rate = 10000; break; //?
case 0xA8: sample_rate = 9000; break; //?
case 0xA7: sample_rate = 8000; break; //?
case 0xA6: sample_rate = 7000; break; //?
case 0xA5: sample_rate = 6500; break; //?
case 0xA4: sample_rate = 6000; break; //?
case 0xA3: sample_rate = 5800; break; //?
case 0xA2: sample_rate = 5400; break; //?
case 0xA1: sample_rate = 5000; break; //?
case 0x9d: sample_rate = 4000; break; //?
case 0x9c: sample_rate = 3500; break; //?
default:
VGM_LOG("BNK: unknown pitch %x\n", pitch);
goto fail;

View File

@ -3366,12 +3366,14 @@ static int config_sb_version(ubi_sb_header* sb, STREAMFILE* sf) {
/* Splinter Cell: Pandora Tomorrow-online (2004)(PS2)-bank 0x000A0008 */
/* Prince of Persia: Warrior Within (Demo)(2004)(PS2)-bank 0x00100000 */
/* Prince of Persia: Warrior Within (2004)(PS2)-bank 0x00120009 */
/* Horsez / Champion Dreams: First to Ride / Pipa Funnell: Take the Reins (2006)(PS2)-bank 0x0012000c */
if ((sb->version == 0x000A0002 && sb->platform == UBI_PS2) ||
(sb->version == 0x000A0004 && sb->platform == UBI_PS2) ||
(sb->version == 0x000A0007 && sb->platform == UBI_PS2 && !is_bia_ps2) ||
(sb->version == 0x000A0008 && sb->platform == UBI_PS2) ||
(sb->version == 0x00100000 && sb->platform == UBI_PS2) ||
(sb->version == 0x00120009 && sb->platform == UBI_PS2)) {
(sb->version == 0x00120009 && sb->platform == UBI_PS2) ||
(sb->version == 0x0012000c && sb->platform == UBI_PS2)) {
config_sb_entry(sb, 0x48, 0x6c);
config_sb_audio_fb(sb, 0x18, (1 << 2), (1 << 3), (1 << 4));