|
|
|
@ -41,103 +41,103 @@ MPC_decoder::RESET_Globals ( void )
|
|
|
|
|
unsigned int
|
|
|
|
|
MPC_decoder::decode_internal ( MPC_SAMPLE_FORMAT *buffer )
|
|
|
|
|
{
|
|
|
|
|
unsigned int output_frame_length = FrameLength;
|
|
|
|
|
|
|
|
|
|
unsigned int FrameBitCnt = 0;
|
|
|
|
|
|
|
|
|
|
if ( DecodedFrames >= OverallFrames )
|
|
|
|
|
return (unsigned int)(-1); // end of file -> abort decoding
|
|
|
|
|
|
|
|
|
|
// read jump-info for validity check of frame
|
|
|
|
|
FwdJumpInfo = Bitstream_read (20);
|
|
|
|
|
SeekTable [DecodedFrames] = 20 + FwdJumpInfo; // ...
|
|
|
|
|
|
|
|
|
|
ActDecodePos = (Zaehler << 5) + pos;
|
|
|
|
|
|
|
|
|
|
// decode data and check for validity of frame
|
|
|
|
|
FrameBitCnt = BitsRead ();
|
|
|
|
|
switch ( StreamVersion ) {
|
|
|
|
|
case 0x04:
|
|
|
|
|
case 0x05:
|
|
|
|
|
case 0x06:
|
|
|
|
|
Lese_Bitstrom_SV6 ();
|
|
|
|
|
break;
|
|
|
|
|
case 0x07:
|
|
|
|
|
case 0x17:
|
|
|
|
|
Lese_Bitstrom_SV7 ();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return (unsigned int)(-1);
|
|
|
|
|
}
|
|
|
|
|
FrameWasValid = BitsRead() - FrameBitCnt == FwdJumpInfo;
|
|
|
|
|
|
|
|
|
|
// synthesize signal
|
|
|
|
|
Requantisierung ( Max_Band );
|
|
|
|
|
|
|
|
|
|
//if ( EQ_activated && PluginSettings.EQbyMPC )
|
|
|
|
|
// perform_EQ ();
|
|
|
|
|
|
|
|
|
|
Synthese_Filter_float ( buffer );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DecodedFrames++;
|
|
|
|
|
|
|
|
|
|
// cut off first SynthDelay zero-samples
|
|
|
|
|
if ( DecodedFrames == OverallFrames && StreamVersion >= 6 )
|
|
|
|
|
{ // reconstruct exact filelength
|
|
|
|
|
int mod_block = Bitstream_read (11);
|
|
|
|
|
int FilterDecay;
|
|
|
|
|
|
|
|
|
|
if (mod_block == 0) mod_block = 1152; // Encoder bugfix
|
|
|
|
|
FilterDecay = (mod_block + SynthDelay) % FrameLength;
|
|
|
|
|
|
|
|
|
|
// additional FilterDecay samples are needed for decay of synthesis filter
|
|
|
|
|
if ( SynthDelay + mod_block >= FrameLength ) {
|
|
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
// Rhoades 4/16/2002
|
|
|
|
|
// Commented out are blocks of code which cause gapless playback to fail.
|
|
|
|
|
// Temporary fix...
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
if ( ! TrueGaplessPresent ) {
|
|
|
|
|
RESET_Y ();
|
|
|
|
|
} else {
|
|
|
|
|
//if ( FrameLength != LastValidSamples ) {
|
|
|
|
|
Bitstream_read (20);
|
|
|
|
|
Lese_Bitstrom_SV7 ();
|
|
|
|
|
Requantisierung ( Max_Band );
|
|
|
|
|
//FilterDecay = LastValidSamples;
|
|
|
|
|
//}
|
|
|
|
|
//else {
|
|
|
|
|
//FilterDecay = 0;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Synthese_Filter_float ( buffer + 2304 );
|
|
|
|
|
|
|
|
|
|
output_frame_length = FrameLength + FilterDecay;
|
|
|
|
|
}
|
|
|
|
|
else { // there are only FilterDecay samples needed for this frame
|
|
|
|
|
output_frame_length = FilterDecay;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( samples_to_skip ) {
|
|
|
|
|
if (output_frame_length < samples_to_skip)
|
|
|
|
|
{
|
|
|
|
|
samples_to_skip -= output_frame_length;
|
|
|
|
|
output_frame_length = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
output_frame_length -= samples_to_skip;
|
|
|
|
|
memmove ( buffer, buffer + samples_to_skip * 2, output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT) );
|
|
|
|
|
samples_to_skip = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output_frame_length;
|
|
|
|
|
unsigned int output_frame_length = FrameLength;
|
|
|
|
|
|
|
|
|
|
unsigned int FrameBitCnt = 0;
|
|
|
|
|
|
|
|
|
|
if ( DecodedFrames >= OverallFrames )
|
|
|
|
|
return (unsigned int)(-1); // end of file -> abort decoding
|
|
|
|
|
|
|
|
|
|
// read jump-info for validity check of frame
|
|
|
|
|
FwdJumpInfo = Bitstream_read (20);
|
|
|
|
|
SeekTable [DecodedFrames] = 20 + FwdJumpInfo; // ...
|
|
|
|
|
|
|
|
|
|
ActDecodePos = (Zaehler << 5) + pos;
|
|
|
|
|
|
|
|
|
|
// decode data and check for validity of frame
|
|
|
|
|
FrameBitCnt = BitsRead ();
|
|
|
|
|
switch ( StreamVersion ) {
|
|
|
|
|
case 0x04:
|
|
|
|
|
case 0x05:
|
|
|
|
|
case 0x06:
|
|
|
|
|
Lese_Bitstrom_SV6 ();
|
|
|
|
|
break;
|
|
|
|
|
case 0x07:
|
|
|
|
|
case 0x17:
|
|
|
|
|
Lese_Bitstrom_SV7 ();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return (unsigned int)(-1);
|
|
|
|
|
}
|
|
|
|
|
FrameWasValid = BitsRead() - FrameBitCnt == FwdJumpInfo;
|
|
|
|
|
|
|
|
|
|
// synthesize signal
|
|
|
|
|
Requantisierung ( Max_Band );
|
|
|
|
|
|
|
|
|
|
//if ( EQ_activated && PluginSettings.EQbyMPC )
|
|
|
|
|
// perform_EQ ();
|
|
|
|
|
|
|
|
|
|
Synthese_Filter_float ( buffer );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DecodedFrames++;
|
|
|
|
|
|
|
|
|
|
// cut off first SynthDelay zero-samples
|
|
|
|
|
if ( DecodedFrames == OverallFrames && StreamVersion >= 6 )
|
|
|
|
|
{ // reconstruct exact filelength
|
|
|
|
|
int mod_block = Bitstream_read (11);
|
|
|
|
|
int FilterDecay;
|
|
|
|
|
|
|
|
|
|
if (mod_block == 0) mod_block = 1152; // Encoder bugfix
|
|
|
|
|
FilterDecay = (mod_block + SynthDelay) % FrameLength;
|
|
|
|
|
|
|
|
|
|
// additional FilterDecay samples are needed for decay of synthesis filter
|
|
|
|
|
if ( SynthDelay + mod_block >= FrameLength ) {
|
|
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
// Rhoades 4/16/2002
|
|
|
|
|
// Commented out are blocks of code which cause gapless playback to fail.
|
|
|
|
|
// Temporary fix...
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
if ( ! TrueGaplessPresent ) {
|
|
|
|
|
RESET_Y ();
|
|
|
|
|
} else {
|
|
|
|
|
//if ( FrameLength != LastValidSamples ) {
|
|
|
|
|
Bitstream_read (20);
|
|
|
|
|
Lese_Bitstrom_SV7 ();
|
|
|
|
|
Requantisierung ( Max_Band );
|
|
|
|
|
//FilterDecay = LastValidSamples;
|
|
|
|
|
//}
|
|
|
|
|
//else {
|
|
|
|
|
//FilterDecay = 0;
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Synthese_Filter_float ( buffer + 2304 );
|
|
|
|
|
|
|
|
|
|
output_frame_length = FrameLength + FilterDecay;
|
|
|
|
|
}
|
|
|
|
|
else { // there are only FilterDecay samples needed for this frame
|
|
|
|
|
output_frame_length = FilterDecay;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( samples_to_skip ) {
|
|
|
|
|
if (output_frame_length < samples_to_skip)
|
|
|
|
|
{
|
|
|
|
|
samples_to_skip -= output_frame_length;
|
|
|
|
|
output_frame_length = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
output_frame_length -= samples_to_skip;
|
|
|
|
|
memmove ( buffer, buffer + samples_to_skip * 2, output_frame_length * 2 * sizeof (MPC_SAMPLE_FORMAT) );
|
|
|
|
|
samples_to_skip = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output_frame_length;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -158,20 +158,20 @@ unsigned int MPC_decoder::Decode ( MPC_SAMPLE_FORMAT *buffer, unsigned int * vbr
|
|
|
|
|
if ( FrameWasValid == 0 ) { // error occurred in bitstream
|
|
|
|
|
return (unsigned int)(-1);
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
if (vbr_update_acc && vbr_update_bits)
|
|
|
|
|
{
|
|
|
|
|
(*vbr_update_acc) ++;
|
|
|
|
|
vbr_ring = (Zaehler << 5) + pos - vbr_ring;
|
|
|
|
|
if (vbr_ring < 0) vbr_ring += 524288;
|
|
|
|
|
(*vbr_update_bits) += vbr_ring;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
UpdateBuffer ( RING );
|
|
|
|
|
|
|
|
|
|
if (valid_samples > 0) return valid_samples;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
if (vbr_update_acc && vbr_update_bits)
|
|
|
|
|
{
|
|
|
|
|
(*vbr_update_acc) ++;
|
|
|
|
|
vbr_ring = (Zaehler << 5) + pos - vbr_ring;
|
|
|
|
|
if (vbr_ring < 0) vbr_ring += 524288;
|
|
|
|
|
(*vbr_update_bits) += vbr_ring;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
UpdateBuffer ( RING );
|
|
|
|
|
|
|
|
|
|
if (valid_samples > 0) return valid_samples;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@ -191,7 +191,7 @@ MPC_decoder::Requantisierung ( const int Last_Band )
|
|
|
|
|
#ifdef MPC_FIXED_POINT
|
|
|
|
|
#if MPC_FIXED_POINT_FRACTPART == 14
|
|
|
|
|
#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \
|
|
|
|
|
MPC_MULTIPLY_EX(CcVal,SCF[SCF_idx],SCF_shift[SCF_idx])
|
|
|
|
|
MPC_MULTIPLY_EX(CcVal,SCF[SCF_idx],SCF_shift[SCF_idx])
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#error FIXME, Cc table is in 18.14 format
|
|
|
|
@ -199,7 +199,7 @@ MPC_decoder::Requantisierung ( const int Last_Band )
|
|
|
|
|
#endif
|
|
|
|
|
#else
|
|
|
|
|
#define MPC_MULTIPLY_SCF(CcVal, SCF_idx) \
|
|
|
|
|
MPC_MULTIPLY(CcVal,SCF[SCF_idx])
|
|
|
|
|
MPC_MULTIPLY(CcVal,SCF[SCF_idx])
|
|
|
|
|
#endif
|
|
|
|
|
// requantization and scaling of subband-samples
|
|
|
|
|
for ( Band = 0; Band <= Last_Band; Band++ ) { // setting pointers
|
|
|
|
@ -232,7 +232,7 @@ MPC_decoder::Requantisierung ( const int Last_Band )
|
|
|
|
|
} else { // M!=0, S==0
|
|
|
|
|
facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][0]);
|
|
|
|
|
for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) {
|
|
|
|
|
*YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
|
|
|
|
|
*YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++);
|
|
|
|
|
}
|
|
|
|
|
facL = MPC_MULTIPLY_SCF( Cc[Res_L[Band]] , (unsigned char)SCF_Index_L[Band][1]);
|
|
|
|
|
for ( ; n < 24; n++, YL += 32, YR += 32 ) {
|
|
|
|
@ -886,8 +886,8 @@ MPC_decoder::MPC_decoder ( MPC_reader *r, double scale_factor )
|
|
|
|
|
|
|
|
|
|
void MPC_decoder::SetStreamInfo ( const StreamInfo *si )
|
|
|
|
|
{
|
|
|
|
|
RESET_Synthesis ();
|
|
|
|
|
RESET_Globals ();
|
|
|
|
|
RESET_Synthesis ();
|
|
|
|
|
RESET_Globals ();
|
|
|
|
|
|
|
|
|
|
StreamVersion = si->simple.StreamVersion;
|
|
|
|
|
MS_used = si->simple.MS;
|
|
|
|
@ -899,14 +899,14 @@ void MPC_decoder::SetStreamInfo ( const StreamInfo *si )
|
|
|
|
|
SampleRate = (int)si->simple.SampleFreq;
|
|
|
|
|
|
|
|
|
|
if ( SeekTable != NULL ) free ( SeekTable );
|
|
|
|
|
SeekTable = (unsigned short *)calloc ( sizeof(unsigned short), OverallFrames+64 );
|
|
|
|
|
SeekTable = (unsigned short *)calloc ( OverallFrames+64, sizeof(unsigned short) );
|
|
|
|
|
|
|
|
|
|
samples_to_skip = SynthDelay;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MPC_decoder::Initialize(const StreamInfo * info)
|
|
|
|
|
{
|
|
|
|
|
SetStreamInfo(info);
|
|
|
|
|
SetStreamInfo(info);
|
|
|
|
|
|
|
|
|
|
// AB: setting position to the beginning of the data-bitstream
|
|
|
|
|
switch ( StreamVersion ) {
|
|
|
|
@ -971,7 +971,7 @@ static unsigned int get_initial_fpos(unsigned int StreamVersion)
|
|
|
|
|
case 0x07:
|
|
|
|
|
case 0x17: fpos = 200; break;
|
|
|
|
|
}
|
|
|
|
|
return fpos;
|
|
|
|
|
return fpos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MPC_decoder::SeekSeconds ( double seconds )
|
|
|
|
@ -985,8 +985,8 @@ bool MPC_decoder::SeekSample(MPC_INT64 destsample)
|
|
|
|
|
unsigned long fpos;
|
|
|
|
|
unsigned int fwd;
|
|
|
|
|
|
|
|
|
|
fwd = (unsigned) (destsample / FrameLength);
|
|
|
|
|
samples_to_skip = SynthDelay + (unsigned)(destsample % FrameLength);
|
|
|
|
|
fwd = (unsigned) (destsample / FrameLength);
|
|
|
|
|
samples_to_skip = SynthDelay + (unsigned)(destsample % FrameLength);
|
|
|
|
|
|
|
|
|
|
memset ( Y_L , 0, sizeof Y_L );
|
|
|
|
|
memset ( Y_R , 0, sizeof Y_R );
|
|
|
|
@ -1058,17 +1058,17 @@ void MPC_decoder::UpdateBuffer ( unsigned int RING )
|
|
|
|
|
|
|
|
|
|
static unsigned long swap32(unsigned long val)
|
|
|
|
|
{
|
|
|
|
|
const unsigned char * src = (const unsigned char*)&val;
|
|
|
|
|
return (unsigned long)src[0] | ((unsigned long)src[1] << 8) | ((unsigned long)src[2] << 16) | ((unsigned long)src[3] << 24);
|
|
|
|
|
const unsigned char * src = (const unsigned char*)&val;
|
|
|
|
|
return (unsigned long)src[0] | ((unsigned long)src[1] << 8) | ((unsigned long)src[2] << 16) | ((unsigned long)src[3] << 24);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MPC_decoder::f_read_dword( unsigned int * ptr, unsigned int count)
|
|
|
|
|
{
|
|
|
|
|
count = f_read(ptr,count << 2) >> 2;
|
|
|
|
|
count = f_read(ptr,count << 2) >> 2;
|
|
|
|
|
#ifndef MPC_LITTLE_ENDIAN
|
|
|
|
|
unsigned int n;
|
|
|
|
|
for(n=0;n<count;n++)
|
|
|
|
|
ptr[n] = swap32(ptr[n]);
|
|
|
|
|
unsigned int n;
|
|
|
|
|
for(n=0;n<count;n++)
|
|
|
|
|
ptr[n] = swap32(ptr[n]);
|
|
|
|
|
#endif
|
|
|
|
|
return count;
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|