mpg123-1.32.0

This commit is contained in:
Ozkan Sezer
2023-09-24 08:51:02 +03:00
parent 89d671ef14
commit 2279cffc0f
241 changed files with 18940 additions and 16360 deletions

View File

@@ -1,19 +1,19 @@
/*
ntom.c: N->M down/up sampling; the setup code.
copyright 1995-2008 by the mpg123 project - free software under the terms of the LGPL 2.1
copyright 1995-2023 by the mpg123 project - free software under the terms of the LGPL 2.1
see COPYING and AUTHORS files in distribution or http://mpg123.org
initially written by Michael Hipp
*/
#define SAFE_NTOM /* Do not depend on off_t*off_t with big values still being in the range... */
#define SAFE_NTOM /* Do not depend on int64_t*int64_t with big values still being in the range... */
#include "mpg123lib_intern.h"
#include "debug.h"
int synth_ntom_set_step(mpg123_handle *fr)
int INT123_synth_ntom_set_step(mpg123_handle *fr)
{
long m,n;
m = frame_freq(fr);
m = INT123_frame_freq(fr);
n = fr->af.rate;
if(VERBOSE2)
fprintf(stderr,"Init rate converter: %ld->%ld\n",m,n);
@@ -33,21 +33,21 @@ int synth_ntom_set_step(mpg123_handle *fr)
return -1;
}
fr->ntom_val[0] = fr->ntom_val[1] = ntom_val(fr, fr->num);
fr->INT123_ntom_val[0] = fr->INT123_ntom_val[1] = INT123_ntom_val(fr, fr->num);
return 0;
}
/*
The SAFE_NTOM does iterative loops instead of straight multiplication.
The safety is not just about the algorithm closely mimicking the decoder instead of applying some formula,
it is more about avoiding multiplication of possibly big sample offsets (a 32bit off_t could overflow too easily).
it is more about avoiding multiplication of possibly big sample offsets (a 32bit int64_t could overflow too easily).
*/
unsigned long ntom_val(mpg123_handle *fr, off_t frame)
unsigned long INT123_ntom_val(mpg123_handle *fr, int64_t frame)
{
off_t ntm;
int64_t ntm;
#ifdef SAFE_NTOM /* Carry out the loop, without the threatening integer overflow. */
off_t f;
int64_t f;
ntm = NTOM_MUL>>1; /* for frame 0 */
for(f=0; f<frame; ++f) /* for frame > 0 */
{
@@ -63,29 +63,29 @@ unsigned long ntom_val(mpg123_handle *fr, off_t frame)
/* Set the ntom value for next expected frame to be decoded.
This is for keeping output consistent across seeks. */
void ntom_set_ntom(mpg123_handle *fr, off_t num)
void INT123_ntom_set_ntom(mpg123_handle *fr, int64_t num)
{
fr->ntom_val[1] = fr->ntom_val[0] = ntom_val(fr, num);
fr->INT123_ntom_val[1] = fr->INT123_ntom_val[0] = INT123_ntom_val(fr, num);
}
/* Carry out the ntom sample count operation for this one frame.
No fear of integer overflow here. */
off_t ntom_frame_outsamples(mpg123_handle *fr)
int64_t INT123_ntom_frame_outsamples(mpg123_handle *fr)
{
/* The do this before decoding the separate channels, so there is only one common ntom value. */
int ntm = fr->ntom_val[0];
int ntm = fr->INT123_ntom_val[0];
ntm += fr->spf*fr->ntom_step;
return ntm/NTOM_MUL;
}
/* Convert frame offset to unadjusted output sample offset. */
off_t ntom_frmouts(mpg123_handle *fr, off_t frame)
int64_t INT123_ntom_frmouts(mpg123_handle *fr, int64_t frame)
{
#ifdef SAFE_NTOM
off_t f;
int64_t f;
#endif
off_t soff = 0;
off_t ntm = ntom_val(fr,0);
int64_t soff = 0;
int64_t ntm = INT123_ntom_val(fr,0);
#ifdef SAFE_NTOM
if(frame <= 0) return 0;
for(f=0; f<frame; ++f)
@@ -95,23 +95,23 @@ off_t ntom_frmouts(mpg123_handle *fr, off_t frame)
ntm -= (ntm/NTOM_MUL)*NTOM_MUL;
}
#else
soff = (ntm + frame*(off_t)fr->spf*(off_t)fr->ntom_step)/(off_t)NTOM_MUL;
soff = (ntm + frame*(int64_t)fr->spf*(int64_t)fr->ntom_step)/(int64_t)NTOM_MUL;
#endif
return soff;
}
/* Convert input samples to unadjusted output samples. */
off_t ntom_ins2outs(mpg123_handle *fr, off_t ins)
int64_t INT123_ntom_ins2outs(mpg123_handle *fr, int64_t ins)
{
off_t soff = 0;
off_t ntm = ntom_val(fr,0);
int64_t soff = 0;
int64_t ntm = INT123_ntom_val(fr,0);
#ifdef SAFE_NTOM
{
off_t block = fr->spf;
int64_t block = fr->spf;
if(ins <= 0) return 0;
do
{
off_t nowblock = ins > block ? block : ins;
int64_t nowblock = ins > block ? block : ins;
ntm += nowblock*fr->ntom_step;
soff += ntm/NTOM_MUL;
ntm -= (ntm/NTOM_MUL)*NTOM_MUL;
@@ -119,18 +119,18 @@ off_t ntom_ins2outs(mpg123_handle *fr, off_t ins)
} while(ins > 0);
}
#else
/* Beware of overflows: when off_t is 32bits, the multiplication blows too easily.
/* Beware of overflows: when int64_t is 32bits, the multiplication blows too easily.
Of course, it blows for 64bits, too, in theory, but that's for _really_ large files. */
soff = ((off_t)ntm + (off_t)ins*(off_t)fr->ntom_step)/(off_t)NTOM_MUL;
soff = ((int64_t)ntm + (int64_t)ins*(int64_t)fr->ntom_step)/(int64_t)NTOM_MUL;
#endif
return soff;
}
/* Determine frame offset from unadjusted output sample offset. */
off_t ntom_frameoff(mpg123_handle *fr, off_t soff)
int64_t INT123_ntom_frameoff(mpg123_handle *fr, int64_t soff)
{
off_t ioff = 0; /* frames or samples */
off_t ntm = ntom_val(fr,0);
int64_t ioff = 0; /* frames or samples */
int64_t ntm = INT123_ntom_val(fr,0);
#ifdef SAFE_NTOM
if(soff <= 0) return 0;
for(ioff=0; 1; ++ioff)
@@ -142,7 +142,7 @@ off_t ntom_frameoff(mpg123_handle *fr, off_t soff)
}
return ioff;
#else
ioff = (soff*(off_t)NTOM_MUL-ntm)/(off_t)fr->ntom_step;
return ioff/(off_t)fr->spf;
ioff = (soff*(int64_t)NTOM_MUL-ntm)/(int64_t)fr->ntom_step;
return ioff/(int64_t)fr->spf;
#endif
}