Add P3D MPEG decoder [Prototype 1/2 (PS3)], fix debug crap

This commit is contained in:
bnnm 2017-07-29 23:53:45 +02:00
parent 3e947b5e9d
commit cb05313b13
4 changed files with 24 additions and 37 deletions

View File

@ -22,8 +22,6 @@ int mpeg_custom_setup_init_default(STREAMFILE *streamFile, off_t start_offset, m
/* extra checks per type */
switch(data->type) {
//case MPEG_P3D:
//case MPEG_LYN:
case MPEG_XVAG:
if (data->config.chunk_size <= 0 || data->config.interleave <= 0)
goto fail; /* needs external fixed size */
@ -51,6 +49,10 @@ int mpeg_custom_setup_init_default(STREAMFILE *streamFile, off_t start_offset, m
break;
case MPEG_P3D:
if (data->config.interleave <= 0)
goto fail; /* needs external fixed size */
break;
case MPEG_LYN:
case MPEG_AWC:
goto fail; /* not fully implemented */
@ -75,11 +77,9 @@ int mpeg_custom_setup_init_default(STREAMFILE *streamFile, off_t start_offset, m
/* set encoder delay (samples to skip at the beginning of a stream) if needed, which varies with encoder used */
switch(data->type) {
case MPEG_AHX:
data->skip_samples = 480; /* observed default */
break;
default:
break;
case MPEG_AHX: data->skip_samples = 480; break; /* observed default */
case MPEG_P3D: data->skip_samples = info.frame_samples; break; /* matches Radical ADPCM (PC) output */
default: break;
}
data->samples_to_discard = data->skip_samples;
@ -101,29 +101,6 @@ int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL *stream, mpeg_codec_data *d
/* Get data size to give to the decoder, per stream. Usually 1 frame at a time,
* but doesn't really need to be a full frame (decoder would request more data). */
switch(data->type) {
#if 0
case MPEG_P3D: { /* frames chopped up after the first frames? chunk_size * 3 = frame size? (0x60=0x120, 0x40=0xC0) */
//try: after N frames always read 0x60/0x40 (value given in the P3D header), as chunks seems muxed (mpg123 will request more data)
uint32_t current_header = read_32bitBE(offset,streamfile);
/* unknown how frames are chunked, frame header separation can be one of these */
if (read_32bitBE(offset+0x120,streamfile) == current_header) {
data->current_data_size = 0x120;
} else if (read_32bitBE(offset+0xA0,streamfile) == current_header) {
data->current_data_size = 0xA0;
} else if (read_32bitBE(offset+0x1C0,streamfile) == current_header) {
data->current_data_size = 0x1C0;
} else if (read_32bitBE(offset+0x180,streamfile) == current_header) {
data->current_data_size = 0x180;
//} else if (read_32bitBE(offset+0x120,streamfile) == -1) { /* at EOF */
// data->current_data_size = 0x120;
} else {
VGM_LOG("MPEG P3D: unknown frame size @ %lx, %x\n", offset, read_32bitBE(offset+0x120,streamfile));
goto fail;
}
break;
}
#endif
case MPEG_XVAG: /* frames of fixed size (though we could read frame info too) */
current_data_size = data->config.chunk_size;
@ -150,6 +127,12 @@ int mpeg_custom_parse_frame_default(VGMSTREAMCHANNEL *stream, mpeg_codec_data *d
"MPEG FSB: non-constant interleave found @ 0x%08lx\n", stream->offset);
break;
case MPEG_P3D: /* fixed interleave, not frame-aligned (ie. blocks may end/start in part of a frame) */
current_data_size = data->config.interleave / 4; /* to ensure we don't feed mpg123 too much */
current_interleave = data->config.interleave; /* fixed interleave (0x400) */
//todo: last block is smaller that interleave, not sure how it's divided
break;
default: /* standard frames (CBR or VBR) */
if ( !mpeg_get_frame_info(stream->streamfile, stream->offset, &info) )
goto fail;

View File

@ -328,6 +328,7 @@ static void decode_mpeg_custom(VGMSTREAM * vgmstream, mpeg_codec_data * data, sa
//case MPEG_LYN:
case MPEG_FSB:
case MPEG_XVAG:
case MPEG_P3D:
/* multiple offsets, decodes 1 frame per stream until reaching interleave/block_size and skips it */
decode_mpeg_custom_stream(&vgmstream->ch[i], data, data->ms[i], channels, i);
break;
@ -370,8 +371,7 @@ static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data
/* decode samples from one full-frame (as N data-frames = 1 full-frame) before exiting (to orderly copy to sample buffer) */
do {
VGM_LOG("MPEG: new step of stream %i @ 0x%08lx\n", num_stream, stream->offset);
getchar();
//VGM_LOG("MPEG: new step of stream %i @ 0x%08lx\n", num_stream, stream->offset);
/* extra EOF check for edge cases when the caller tries to read more samples than possible */
if (stream->offset >= stream_size) {
@ -397,7 +397,7 @@ static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data
bytes_done = data->stream_buffer_size;
break; /* continue with other streams */
}
VGM_LOG("MPEG: read results: bytes_in_buffer=0x%x, new offset off=%lx\n", data->bytes_in_buffer, stream->offset);
//VGM_LOG("MPEG: read results: bytes_in_buffer=0x%x, new offset off=%lx\n", data->bytes_in_buffer, stream->offset);
data->buffer_full = 1;
data->buffer_used = 0;

View File

@ -143,11 +143,15 @@ VGMSTREAM * init_vgmstream_p3d(STREAMFILE *streamFile) {
mpeg_custom_config cfg;
memset(&cfg, 0, sizeof(mpeg_custom_config));
cfg.chunk_size = block_size; /* usually 0x60 or 0x40, portion of a full MPEG frame */
cfg.interleave = 0x400;
/* block_size * 3 = frame size (0x60*3=0x120 or 0x40*3=0xC0) but doesn't seem to have any significance) */
vgmstream->layout_type = layout_none;
vgmstream->codec_data = init_mpeg_custom_codec_data(streamFile, start_offset, &vgmstream->coding_type, vgmstream->channels, MPEG_P3D, &cfg);
if (!vgmstream->codec_data) goto fail;
/* both to setup initial interleave in vgmstream_open_stream */
vgmstream->interleave_block_size = cfg.interleave;
vgmstream->layout_type = layout_mpeg_custom;
break;
}
#endif

View File

@ -854,9 +854,9 @@ typedef struct {
typedef enum {
MPEG_STANDARD, /* 1 stream */
MPEG_AHX, /* 1 stream with false frame headers */
MPEG_XVAG, /* N streams of fixed interleave (with several data-frames of fixed size) */
MPEG_XVAG, /* N streams of fixed interleave (frame-aligned, several data-frames of fixed size) */
MPEG_FSB, /* N streams of 1 data-frame+padding (=interleave) */
MPEG_P3D, /* N streams of chunked frames */
MPEG_P3D, /* N streams of fixed interleave (not frame-aligned) */
MPEG_EA, /* 1 stream (maybe N streams in absolute offsets?) */
MPEG_EAL31, /* EALayer3 v1, custom frames */
MPEG_EAL32P, /* EALayer3 v2 "P" (PCM?), altered custom frames */