Fix EOF frame in early ADX [Baroque (SAT)]

This commit is contained in:
bnnm 2020-08-03 23:17:20 +02:00
parent c6bd158700
commit 96d9502742

View File

@ -1,7 +1,7 @@
#include "coding.h"
#include "../util.h"
void decode_adx(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int32_t frame_size, coding_t coding_type) {
void decode_adx(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int32_t frame_size, coding_t coding_type) {
uint8_t frame[0x12] = {0};
off_t frame_offset;
int i, frames_in, sample_count = 0;
@ -21,12 +21,22 @@ void decode_adx(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing
frame_offset = stream->offset + bytes_per_frame * frames_in;
read_streamfile(frame, frame_offset, bytes_per_frame, stream->streamfile); /* ignore EOF errors */
scale = get_16bitBE(frame+0x00);
scale = get_s16be(frame+0x00);
switch(coding_type) {
case coding_CRI_ADX:
scale = scale + 1;
coef1 = stream->adpcm_coef[0];
coef2 = stream->adpcm_coef[1];
/* Detect EOF scale (0x8001) found in some ADX of any type, signals "stop decoding" (without this frame?).
* Normally num_samples stops right before it, but ADXPLAY will honor it even in the middle on a file
* (may repeat last sample buffer). Some Baroque (SAT) videos set it on file end, but num_samples goes beyond.
* Just the upper bit triggers it even in encrypted ADX (max is 0x7FFF), but the check only here just in case. */
if (frame[0] == 0x80 && frame[1] == 0x01) {
scale = 0; /* fix scaled click, maybe should just exit */
VGM_LOG("ADX: reached EOF scale\n");
}
break;
case coding_CRI_ADX_exp:
scale = 1 << (12 - scale);
@ -79,6 +89,6 @@ void decode_adx(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelspacing
}
}
void adx_next_key(VGMSTREAMCHANNEL * stream) {
void adx_next_key(VGMSTREAMCHANNEL* stream) {
stream->adx_xor = (stream->adx_xor * stream->adx_mult + stream->adx_add) & 0x7fff;
}