mpg123-1.30.0

This commit is contained in:
Ozkan Sezer
2022-06-28 07:10:00 +03:00
parent 01b6013145
commit c46daebce1
56 changed files with 3497 additions and 1035 deletions

View File

@@ -984,6 +984,12 @@ int attribute_align_arg mpg123_volume_change(mpg123_handle *mh, double change)
return mpg123_volume(mh, change + (double) mh->p.outscale);
}
int attribute_align_arg mpg123_volume_change_db(mpg123_handle *mh, double change)
{
if(mh == NULL) return MPG123_ERR;
return mpg123_volume(mh, dbchange(mh->p.outscale, change));
}
int attribute_align_arg mpg123_volume(mpg123_handle *mh, double vol)
{
if(mh == NULL) return MPG123_ERR;

View File

@@ -454,8 +454,8 @@ int attribute_align_arg mpg123_getstate2(mpg123_handle *mh, int key, long *val,
int attribute_align_arg mpg123_eq(mpg123_handle *mh, enum mpg123_channels channel, int band, double val)
{
#ifndef NO_EQUALIZER
if(mh == NULL) return MPG123_BAD_HANDLE;
#ifndef NO_EQUALIZER
if(band < 0 || band > 31){ mh->err = MPG123_BAD_BAND; return MPG123_ERR; }
switch(channel)
{
@@ -478,9 +478,42 @@ int attribute_align_arg mpg123_eq2(mpg123_handle *mh, int channel, int band, dou
return mpg123_eq(mh, channel, band, val);
}
int attribute_align_arg mpg123_eq_bands(mpg123_handle *mh, int channel, int a, int b, double factor)
{
if(mh == NULL) return MPG123_BAD_HANDLE;
#ifndef NO_EQUALIZER
int ret;
// Always count up.
if(a>b){ int s=a; a=b; b=s; }
for(int n=a; n<=b; ++n)
if( (ret=mpg123_eq(mh, channel, n, factor)) != MPG123_OK )
return ret;
#endif
return MPG123_OK;
}
int attribute_align_arg mpg123_eq_change(mpg123_handle *mh, int channel, int a, int b, double db)
{
if(mh == NULL) return MPG123_BAD_HANDLE;
#ifndef NO_EQUALIZER
// Always count up.
if(a>b){ int s=a; a=b; b=s; }
for(int band=a; band<=b; ++band)
{
if(band < 0 || band > 31){ mh->err = MPG123_BAD_BAND; return MPG123_ERR; }
if(channel & MPG123_LEFT)
mh->equalizer[0][band] = DOUBLE_TO_REAL(dbchange(REAL_TO_DOUBLE(mh->equalizer[0][band]), db));
if(channel & MPG123_RIGHT)
mh->equalizer[1][band] = DOUBLE_TO_REAL(dbchange(REAL_TO_DOUBLE(mh->equalizer[1][band]), db));;
mh->have_eq_settings = TRUE;
}
#endif
return MPG123_OK;
}
double attribute_align_arg mpg123_geteq(mpg123_handle *mh, enum mpg123_channels channel, int band)
{
double ret = 0.;
double ret = 1.;
#ifndef NO_EQUALIZER
/* Handle this gracefully. When there is no band, it has no volume. */

View File

@@ -1093,6 +1093,28 @@ MPG123_EXPORT int mpg123_eq( mpg123_handle *mh
MPG123_EXPORT int mpg123_eq2( mpg123_handle *mh
, int channel, int band, double val );
/** Set a range of equalizer bands
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
* #MPG123_LEFT|#MPG123_RIGHT for both.
* \param a The first equalizer band to set (from 0 to 31)
* \param b The last equalizer band to set (from 0 to 31)
* \param factor The (linear) adjustment factor, 1 being neutral.
* \return MPG123_OK on success
*/
MPG123_EXPORT int mpg123_eq_bands( mpg123_handle *mh
, int channel, int a, int b, double factor );
/** Change a range of equalizer bands
* \param channel Can be #MPG123_LEFT, #MPG123_RIGHT or
* #MPG123_LEFT|#MPG123_RIGHT for both.
* \param a The first equalizer band to change (from 0 to 31)
* \param b The last equalizer band to change (from 0 to 31)
* \param db The adjustment in dB (limited to +/- 60 dB).
* \return MPG123_OK on success
*/
MPG123_EXPORT int mpg123_eq_change( mpg123_handle *mh
, int channel, int a, int b, double db );
#ifdef MPG123_ENUM_API
/** Get the 32 Band Audio Equalizer settings.
*
@@ -1141,6 +1163,13 @@ MPG123_EXPORT int mpg123_volume(mpg123_handle *mh, double vol);
*/
MPG123_EXPORT int mpg123_volume_change(mpg123_handle *mh, double change);
/** Adjust output volume including the RVA setting by chosen amount
* \param mh handle
* \param change volume adjustment in decibels (limited to +/- 60 dB)
* \return MPG123_OK on success
*/
MPG123_EXPORT int mpg123_volume_change_db(mpg123_handle *mh, double db);
/** Return current volume setting, the actual value due to RVA, and the RVA
* adjustment itself. It's all as double float value to abstract the sample
* format. The volume values are linear factors / amplitudes (not percent)
@@ -1741,7 +1770,7 @@ MPG123_EXPORT int mpg123_id3( mpg123_handle *mh
, mpg123_id3v1 **v1, mpg123_id3v2 **v2 );
/** Return pointers to and size of stored raw ID3 data if storage has
* been configured with MPG123_RAW_ID3 and stream parsing passed the
* been configured with MPG123_STORE_RAW_ID3 and stream parsing passed the
* metadata already. Null value with zero size is a possibility!
* The storage can change at any next API call.
*

View File

@@ -339,4 +339,16 @@ int open_fixed_post(mpg123_handle *mh, int channels, int encoding);
#define TIMEOUT_READ
#endif
// Change a given linear factor by the given dB value, bounded
// to +/- 60 dB.
static inline double dbchange(double base_factor, double db)
{
double nscale = base_factor * pow(10, db/20);
if(nscale < 0.001) // -60 dB
nscale = 0.001;
if(nscale > 1000)
nscale = 1000; // +60 dB
return nscale;
}
#endif

View File

@@ -129,7 +129,8 @@ static ssize_t icy_fullread(mpg123_handle *fr, unsigned char *buf, ssize_t count
return READER_ERROR;
}
if(!(fr->rdat.flags & READER_BUFFERED)) fr->rdat.filepos += ret;
if(!(fr->rdat.flags & READER_BUFFERED))
SATURATE_ADD(fr->rdat.filepos, ret, OFF_MAX);
cnt += ret;
fr->icy.next -= ret;
if(fr->icy.next > 0)
@@ -147,7 +148,8 @@ static ssize_t icy_fullread(mpg123_handle *fr, unsigned char *buf, ssize_t count
if(ret == 0) break;
debug2("got meta-size byte: %u, at filepos %li", temp_buff, (long)fr->rdat.filepos );
if(!(fr->rdat.flags & READER_BUFFERED)) fr->rdat.filepos += ret; /* 1... */
if(!(fr->rdat.flags & READER_BUFFERED))
SATURATE_ADD(fr->rdat.filepos, ret, OFF_MAX); /* 1... */
if((meta_size = ((size_t) temp_buff) * 16))
{
@@ -166,7 +168,8 @@ static ssize_t icy_fullread(mpg123_handle *fr, unsigned char *buf, ssize_t count
left -= ret;
}
meta_buff[meta_size] = 0; /* string paranoia */
if(!(fr->rdat.flags & READER_BUFFERED)) fr->rdat.filepos += ret;
if(!(fr->rdat.flags & READER_BUFFERED))
SATURATE_ADD(fr->rdat.filepos, ret, OFF_MAX);
if(fr->icy.data) free(fr->icy.data);
fr->icy.data = meta_buff;
@@ -218,7 +221,8 @@ static ssize_t plain_fullread(mpg123_handle *fr,unsigned char *buf, ssize_t coun
ret = fr->rdat.fdread(fr,buf+cnt,count-cnt);
if(ret < 0) return READER_ERROR;
if(ret == 0) break;
if(!(fr->rdat.flags & READER_BUFFERED)) fr->rdat.filepos += ret;
if(!(fr->rdat.flags & READER_BUFFERED))
SATURATE_ADD(fr->rdat.filepos, ret, OFF_MAX);
cnt += ret;
}
return cnt;
@@ -396,7 +400,10 @@ static off_t generic_tell(mpg123_handle *fr)
{
#ifndef NO_FEEDER
if(fr->rdat.flags & READER_BUFFERED)
fr->rdat.filepos = fr->rdat.buffer.fileoff+fr->rdat.buffer.pos;
{
fr->rdat.filepos = fr->rdat.buffer.fileoff;
SATURATE_ADD(fr->rdat.filepos, fr->rdat.buffer.pos, OFF_MAX);
}
#endif
return fr->rdat.filepos;
@@ -458,6 +465,7 @@ static off_t get_fileinfo(mpg123_handle *fr)
debug("cannot seek back");
return -1;
}
fr->rdat.filepos = 0; // un-do our seeking here
debug1("returning length: %"OFF_P, (off_p)len);
return len;
@@ -816,7 +824,8 @@ static int feed_seek_frame(mpg123_handle *fr, off_t num){ return READER_ERROR; }
static void buffered_forget(mpg123_handle *fr)
{
bc_forget(&fr->rdat.buffer);
fr->rdat.filepos = fr->rdat.buffer.fileoff + fr->rdat.buffer.pos;
fr->rdat.filepos = fr->rdat.buffer.fileoff;
SATURATE_ADD(fr->rdat.filepos, fr->rdat.buffer.pos, OFF_MAX);
}
off_t feed_set_pos(mpg123_handle *fr, off_t pos)
@@ -1064,8 +1073,8 @@ static int default_init(mpg123_handle *fr)
if(fr->p.icy_interval > 0) fr->rdat.lseek = nix_lseek;
#endif
fr->rdat.filelen = fr->p.flags & MPG123_NO_PEEK_END ? -1 : get_fileinfo(fr);
fr->rdat.filepos = 0;
fr->rdat.filelen = fr->p.flags & MPG123_NO_PEEK_END ? -1 : get_fileinfo(fr);
if(fr->p.flags & MPG123_FORCE_SEEKABLE)
fr->rdat.flags |= READER_SEEKABLE;
/*