MPEG fixes from kode54, get the right freq and srate even with MPG123_NEED_MORE, avoid locking up with too little data

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@911 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2011-01-19 13:54:59 +00:00
parent 54a6cc88eb
commit 7b78a5262d
8 changed files with 16 additions and 10 deletions

View File

@ -1 +1 @@
#define VERSION "r873" #define VERSION "r911"

View File

@ -80,7 +80,7 @@ void decode_ws(VGMSTREAM * vgmstream, int channel, sample * outbuf, int channels
void decode_fake_mpeg2_l2(VGMSTREAMCHANNEL * stream, void decode_fake_mpeg2_l2(VGMSTREAMCHANNEL * stream,
mpeg_codec_data * data, mpeg_codec_data * data,
sample * outbuf, int32_t samples_to_do); sample * outbuf, int32_t samples_to_do);
mpeg_codec_data *init_mpeg_codec_data(STREAMFILE *streamfile, off_t start_offset, long given_sample_rate, int given_channels, coding_t *coding_type); mpeg_codec_data *init_mpeg_codec_data(STREAMFILE *streamfile, off_t start_offset, long given_sample_rate, int given_channels, coding_t *coding_type, int * actual_sample_rate, int * actual_channels);
long mpeg_bytes_to_samples(long bytes, const struct mpg123_frameinfo *mi); long mpeg_bytes_to_samples(long bytes, const struct mpg123_frameinfo *mi);
void decode_mpeg(VGMSTREAMCHANNEL * stream, void decode_mpeg(VGMSTREAMCHANNEL * stream,
mpeg_codec_data * data, mpeg_codec_data * data,

View File

@ -85,7 +85,7 @@ void decode_fake_mpeg2_l2(VGMSTREAMCHANNEL *stream,
} }
} }
mpeg_codec_data *init_mpeg_codec_data(STREAMFILE *streamfile, off_t start_offset, long given_sample_rate, int given_channels, coding_t *coding_type) { mpeg_codec_data *init_mpeg_codec_data(STREAMFILE *streamfile, off_t start_offset, long given_sample_rate, int given_channels, coding_t *coding_type, int * actual_sample_rate, int * actual_channels) {
int rc; int rc;
off_t read_offset; off_t read_offset;
mpeg_codec_data *data = NULL; mpeg_codec_data *data = NULL;
@ -157,6 +157,9 @@ mpeg_codec_data *init_mpeg_codec_data(STREAMFILE *streamfile, off_t start_offset
else if (mi.version == MPG123_2_5 && mi.layer == 3) else if (mi.version == MPG123_2_5 && mi.layer == 3)
*coding_type = coding_MPEG25_L3; *coding_type = coding_MPEG25_L3;
else goto mpeg_fail; else goto mpeg_fail;
if ( actual_sample_rate ) *actual_sample_rate = rate;
if ( actual_channels ) *actual_channels = channels;
} }
/* reinit, to ignore the reading we've done so far */ /* reinit, to ignore the reading we've done so far */
@ -187,6 +190,11 @@ void decode_mpeg(VGMSTREAMCHANNEL *stream,
data->bytes_in_buffer = read_streamfile(data->buffer, data->bytes_in_buffer = read_streamfile(data->buffer,
stream->offset,MPEG_BUFFER_SIZE,stream->streamfile); stream->offset,MPEG_BUFFER_SIZE,stream->streamfile);
if (!data->bytes_in_buffer) {
memset(outbuf + samples_done * channels, 0, (samples_to_do - samples_done) * sizeof(sample));
break;
}
data->buffer_full = 1; data->buffer_full = 1;
data->buffer_used = 0; data->buffer_used = 0;

View File

@ -430,10 +430,9 @@ VGMSTREAM * init_vgmstream_fsb_mpeg(STREAMFILE *streamFile) {
num_samples = (read_32bitLE(0x5C,streamFile)); num_samples = (read_32bitLE(0x5C,streamFile));
#ifdef VGM_USE_MPEG #ifdef VGM_USE_MPEG
mpeg_data = init_mpeg_codec_data(streamFile, start_offset, -1, -1, &mpeg_coding_type); // -1 to not check sample rate or channels mpeg_data = init_mpeg_codec_data(streamFile, start_offset, -1, -1, &mpeg_coding_type, &rate, &channels); // -1 to not check sample rate or channels
if (!mpeg_data) goto fail; if (!mpeg_data) goto fail;
if (MPG123_OK != mpg123_getformat(mpeg_data->m,&rate,&channels,&encoding)) goto fail;
channel_count = channels; channel_count = channels;
sample_rate = rate; sample_rate = rate;

View File

@ -323,7 +323,7 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
#ifdef VGM_USE_MPEG #ifdef VGM_USE_MPEG
if (coding == coding_MPEG1_L3) { if (coding == coding_MPEG1_L3) {
vgmstream->codec_data = init_mpeg_codec_data(vgmstream->ch[0].streamfile, start_offset, vgmstream->sample_rate, vgmstream->channels, &(vgmstream->coding_type)); vgmstream->codec_data = init_mpeg_codec_data(vgmstream->ch[0].streamfile, start_offset, vgmstream->sample_rate, vgmstream->channels, &(vgmstream->coding_type), NULL, NULL);
if (!vgmstream->codec_data) goto fail; if (!vgmstream->codec_data) goto fail;
} }
#endif #endif

View File

@ -105,7 +105,7 @@ VGMSTREAM * init_vgmstream_ps3_msf(STREAMFILE *streamFile) {
struct mpg123_frameinfo mi; struct mpg123_frameinfo mi;
coding_t ct; coding_t ct;
mpeg_data = init_mpeg_codec_data(streamFile, start_offset, vgmstream->sample_rate, vgmstream->channels, &ct); mpeg_data = init_mpeg_codec_data(streamFile, start_offset, vgmstream->sample_rate, vgmstream->channels, &ct, NULL, NULL);
if (!mpeg_data) goto fail; if (!mpeg_data) goto fail;
vgmstream->codec_data = mpeg_data; vgmstream->codec_data = mpeg_data;

View File

@ -73,10 +73,9 @@ VGMSTREAM * init_vgmstream_ps3_xvag(STREAMFILE *streamFile) {
long rate; long rate;
int channels,encoding; int channels,encoding;
mpeg_data = init_mpeg_codec_data(streamFile, start_offset, -1, -1, &mpeg_coding_type); // -1 to not check sample rate or channels mpeg_data = init_mpeg_codec_data(streamFile, start_offset, -1, -1, &mpeg_coding_type, &rate, &channels); // -1 to not check sample rate or channels
if (!mpeg_data) goto fail; if (!mpeg_data) goto fail;
if (MPG123_OK != mpg123_getformat(mpeg_data->m,&rate,&channels,&encoding)) goto fail;
channel_count = channels; channel_count = channels;
sample_rate = rate; sample_rate = rate;

View File

@ -88,7 +88,7 @@ VGMSTREAM * init_vgmstream_se_scd(STREAMFILE *streamFile) {
struct mpg123_frameinfo mi; struct mpg123_frameinfo mi;
coding_t ct; coding_t ct;
mpeg_data = init_mpeg_codec_data(streamFile, start_offset, vgmstream->sample_rate, vgmstream->channels, &ct); mpeg_data = init_mpeg_codec_data(streamFile, start_offset, vgmstream->sample_rate, vgmstream->channels, &ct, NULL, NULL);
if (!mpeg_data) goto fail; if (!mpeg_data) goto fail;
vgmstream->codec_data = mpeg_data; vgmstream->codec_data = mpeg_data;