From b4f7528e9a267cf7a8f03827429008cb994e1bb7 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Mon, 16 Jun 2014 07:24:43 +1000 Subject: [PATCH] replaygain_analysis : Switch to standard C sized integer types. --- include/share/replaygain_analysis.h | 10 +- src/share/grabbag/replaygain.c | 14 +-- .../replaygain_analysis/replaygain_analysis.c | 115 +++++++++--------- 3 files changed, 69 insertions(+), 70 deletions(-) diff --git a/include/share/replaygain_analysis.h b/include/share/replaygain_analysis.h index 36c14e04..c61737e2 100644 --- a/include/share/replaygain_analysis.h +++ b/include/share/replaygain_analysis.h @@ -42,15 +42,15 @@ extern "C" { #endif -typedef float Float_t; /* Type used for filtering */ +typedef float float_t; /* Type used for filtering */ -extern Float_t ReplayGainReferenceLoudness; /* in dB SPL, currently == 89.0 */ +extern float_t ReplayGainReferenceLoudness; /* in dB SPL, currently == 89.0 */ int InitGainAnalysis ( long samplefreq ); int ValidGainFrequency ( long samplefreq ); -int AnalyzeSamples ( const Float_t* left_samples, const Float_t* right_samples, size_t num_samples, int num_channels ); -Float_t GetTitleGain ( void ); -Float_t GetAlbumGain ( void ); +int AnalyzeSamples ( const float_t* left_samples, const float_t* right_samples, size_t num_samples, int num_channels ); +float_t GetTitleGain ( void ); +float_t GetAlbumGain ( void ); #ifdef __cplusplus } diff --git a/src/share/grabbag/replaygain.c b/src/share/grabbag/replaygain.c index 46baea81..3b933d7c 100644 --- a/src/share/grabbag/replaygain.c +++ b/src/share/grabbag/replaygain.c @@ -129,7 +129,7 @@ FLAC__bool grabbag__replaygain_init(unsigned sample_frequency) FLAC__bool grabbag__replaygain_analyze(const FLAC__int32 * const input[], FLAC__bool is_stereo, unsigned bps, unsigned samples) { /* using a small buffer improves data locality; we'd like it to fit easily in the dcache */ - static Float_t lbuffer[2048], rbuffer[2048]; + static float_t lbuffer[2048], rbuffer[2048]; static const unsigned nbuffer = sizeof(lbuffer) / sizeof(lbuffer[0]); FLAC__int32 block_peak = 0, s; unsigned i, j; @@ -150,12 +150,12 @@ FLAC__bool grabbag__replaygain_analyze(const FLAC__int32 * const input[], FLAC__ const unsigned n = local_min(samples, nbuffer); for(i = 0; i < n; i++, j++) { s = input[0][j]; - lbuffer[i] = (Float_t)s; + lbuffer[i] = (float_t)s; s = abs(s); block_peak = local_max(block_peak, s); s = input[1][j]; - rbuffer[i] = (Float_t)s; + rbuffer[i] = (float_t)s; s = abs(s); block_peak = local_max(block_peak, s); } @@ -170,7 +170,7 @@ FLAC__bool grabbag__replaygain_analyze(const FLAC__int32 * const input[], FLAC__ const unsigned n = local_min(samples, nbuffer); for(i = 0; i < n; i++, j++) { s = input[0][j]; - lbuffer[i] = (Float_t)s; + lbuffer[i] = (float_t)s; s = abs(s); block_peak = local_max(block_peak, s); } @@ -193,12 +193,12 @@ FLAC__bool grabbag__replaygain_analyze(const FLAC__int32 * const input[], FLAC__ const unsigned n = local_min(samples, nbuffer); for(i = 0; i < n; i++, j++) { s = input[0][j]; - lbuffer[i] = (Float_t)(scale * (double)s); + lbuffer[i] = (float_t)(scale * (double)s); s = abs(s); block_peak = local_max(block_peak, s); s = input[1][j]; - rbuffer[i] = (Float_t)(scale * (double)s); + rbuffer[i] = (float_t)(scale * (double)s); s = abs(s); block_peak = local_max(block_peak, s); } @@ -213,7 +213,7 @@ FLAC__bool grabbag__replaygain_analyze(const FLAC__int32 * const input[], FLAC__ const unsigned n = local_min(samples, nbuffer); for(i = 0; i < n; i++, j++) { s = input[0][j]; - lbuffer[i] = (Float_t)(scale * (double)s); + lbuffer[i] = (float_t)(scale * (double)s); s = abs(s); block_peak = local_max(block_peak, s); } diff --git a/src/share/replaygain_analysis/replaygain_analysis.c b/src/share/replaygain_analysis/replaygain_analysis.c index 7d87091c..9b74b905 100644 --- a/src/share/replaygain_analysis/replaygain_analysis.c +++ b/src/share/replaygain_analysis/replaygain_analysis.c @@ -38,8 +38,8 @@ * * to initialize everything. Call * - * AnalyzeSamples ( const Float_t* left_samples, - * const Float_t* right_samples, + * AnalyzeSamples ( const float_t* left_samples, + * const float_t* right_samples, * size_t num_samples, * int num_channels ); * @@ -59,8 +59,8 @@ * * Pseudo-code to process an album: * - * Float_t l_samples [4096]; - * Float_t r_samples [4096]; + * float_t l_samples [4096]; + * float_t r_samples [4096]; * size_t num_samples; * unsigned int num_songs; * unsigned int i; @@ -98,14 +98,13 @@ #include #include +#ifdef HAVE_STDINT_H +#include +#endif + #include "replaygain_analysis.h" -Float_t ReplayGainReferenceLoudness = 89.0; /* in dB SPL */ - -typedef unsigned short Uint16_t; -typedef signed short Int16_t; -typedef unsigned int Uint32_t; -typedef signed int Int32_t; +float_t ReplayGainReferenceLoudness = 89.0; /* in dB SPL */ #define YULE_ORDER 10 #define BUTTER_ORDER 2 @@ -117,29 +116,29 @@ typedef signed int Int32_t; #define MAX_ORDER (BUTTER_ORDER > YULE_ORDER ? BUTTER_ORDER : YULE_ORDER) #define PINK_REF 64.82 /* 298640883795 */ /* calibration value */ -static Float_t linprebuf [MAX_ORDER * 2]; -static Float_t* linpre; /* left input samples, with pre-buffer */ -static Float_t* lstepbuf; -static Float_t* lstep; /* left "first step" (i.e. post first filter) samples */ -static Float_t* loutbuf; -static Float_t* lout; /* left "out" (i.e. post second filter) samples */ -static Float_t rinprebuf [MAX_ORDER * 2]; -static Float_t* rinpre; /* right input samples ... */ -static Float_t* rstepbuf; -static Float_t* rstep; -static Float_t* routbuf; -static Float_t* rout; +static float_t linprebuf [MAX_ORDER * 2]; +static float_t* linpre; /* left input samples, with pre-buffer */ +static float_t* lstepbuf; +static float_t* lstep; /* left "first step" (i.e. post first filter) samples */ +static float_t* loutbuf; +static float_t* lout; /* left "out" (i.e. post second filter) samples */ +static float_t rinprebuf [MAX_ORDER * 2]; +static float_t* rinpre; /* right input samples ... */ +static float_t* rstepbuf; +static float_t* rstep; +static float_t* routbuf; +static float_t* rout; static unsigned int sampleWindow; /* number of samples required to reach number of milliseconds required for RMS window */ static unsigned long totsamp; static double lsum; static double rsum; #if 0 -static Uint32_t A [(size_t)(STEPS_per_dB * MAX_dB)]; -static Uint32_t B [(size_t)(STEPS_per_dB * MAX_dB)]; +static uint32_t A [(size_t)(STEPS_per_dB * MAX_dB)]; +static uint32_t B [(size_t)(STEPS_per_dB * MAX_dB)]; #else /* [JEC] Solaris Forte compiler doesn't like float calc in array indices */ -static Uint32_t A [120 * 100]; -static Uint32_t B [120 * 100]; +static uint32_t A [120 * 100]; +static uint32_t B [120 * 100]; #endif #ifdef _MSC_VER @@ -149,10 +148,10 @@ static Uint32_t B [120 * 100]; struct ReplayGainFilter { long rate; unsigned downsample; - Float_t BYule[YULE_ORDER+1]; - Float_t AYule[YULE_ORDER+1]; - Float_t BButter[BUTTER_ORDER+1]; - Float_t AButter[BUTTER_ORDER+1]; + float_t BYule[YULE_ORDER+1]; + float_t AYule[YULE_ORDER+1]; + float_t BButter[BUTTER_ORDER+1]; + float_t AButter[BUTTER_ORDER+1]; }; static struct ReplayGainFilter *replaygainfilter; @@ -273,17 +272,17 @@ static const struct ReplayGainFilter ReplayGainFilters[] = { /* When calling this procedure, make sure that ip[-order] and op[-order] point to real data! */ static void -filter ( const Float_t* input, Float_t* output, size_t nSamples, const Float_t* a, const Float_t* b, size_t order, unsigned downsample ) +filter ( const float_t* input, float_t* output, size_t nSamples, const float_t* a, const float_t* b, size_t order, unsigned downsample ) { double y; size_t i; size_t k; - const Float_t* input_head = input; - const Float_t* input_tail; + const float_t* input_head = input; + const float_t* input_tail; - Float_t* output_head = output; - Float_t* output_tail; + float_t* output_head = output; + float_t* output_tail; for ( i = 0; i < nSamples; i++, input_head += downsample, ++output_head ) { @@ -298,7 +297,7 @@ filter ( const Float_t* input, Float_t* output, size_t nSamples, const Float_t* y += *input_tail * b[k] - *output_tail * a[k]; } - output[i] = (Float_t)y; + output[i] = (float_t)y; } } @@ -342,7 +341,7 @@ CreateGainFilter ( long samplefreq ) } static void* -ReallocateWindowBuffer(unsigned window_size, Float_t **window_buffer) +ReallocateWindowBuffer(unsigned window_size, float_t **window_buffer) { void *p = realloc( *window_buffer, sizeof(**window_buffer) * (window_size + MAX_ORDER)); @@ -421,11 +420,11 @@ InitGainAnalysis ( long samplefreq ) /* returns GAIN_ANALYSIS_OK if successful, GAIN_ANALYSIS_ERROR if not */ int -AnalyzeSamples ( const Float_t* left_samples, const Float_t* right_samples, size_t num_samples, int num_channels ) +AnalyzeSamples ( const float_t* left_samples, const float_t* right_samples, size_t num_samples, int num_channels ) { unsigned downsample = replaygainfilter->downsample; - const Float_t* curleft; - const Float_t* curright; + const float_t* curleft; + const float_t* curright; long prebufsamples; long batchsamples; long cursamples; @@ -491,10 +490,10 @@ AnalyzeSamples ( const Float_t* left_samples, const Float_t* right_samples, size if ( ival >= (int)(sizeof(A)/sizeof(*A)) ) ival = (int)(sizeof(A)/sizeof(*A)) - 1; A [ival]++; lsum = rsum = 0.; - memmove ( loutbuf , loutbuf + totsamp, MAX_ORDER * sizeof(Float_t) ); - memmove ( routbuf , routbuf + totsamp, MAX_ORDER * sizeof(Float_t) ); - memmove ( lstepbuf, lstepbuf + totsamp, MAX_ORDER * sizeof(Float_t) ); - memmove ( rstepbuf, rstepbuf + totsamp, MAX_ORDER * sizeof(Float_t) ); + memmove ( loutbuf , loutbuf + totsamp, MAX_ORDER * sizeof(float_t) ); + memmove ( routbuf , routbuf + totsamp, MAX_ORDER * sizeof(float_t) ); + memmove ( lstepbuf, lstepbuf + totsamp, MAX_ORDER * sizeof(float_t) ); + memmove ( rstepbuf, rstepbuf + totsamp, MAX_ORDER * sizeof(float_t) ); totsamp = 0; } if ( totsamp > sampleWindow ) /* somehow I really screwed up: Error in programming! Contact author about totsamp > sampleWindow */ @@ -502,10 +501,10 @@ AnalyzeSamples ( const Float_t* left_samples, const Float_t* right_samples, size } if ( num_samples < MAX_ORDER ) { - memmove ( linprebuf, linprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(Float_t) ); - memmove ( rinprebuf, rinprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(Float_t) ); - memcpy ( linprebuf + MAX_ORDER - num_samples, left_samples, num_samples * sizeof(Float_t) ); - memcpy ( rinprebuf + MAX_ORDER - num_samples, right_samples, num_samples * sizeof(Float_t) ); + memmove ( linprebuf, linprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(float_t) ); + memmove ( rinprebuf, rinprebuf + num_samples, (MAX_ORDER-num_samples) * sizeof(float_t) ); + memcpy ( linprebuf + MAX_ORDER - num_samples, left_samples, num_samples * sizeof(float_t) ); + memcpy ( rinprebuf + MAX_ORDER - num_samples, right_samples, num_samples * sizeof(float_t) ); } else { downsample = replaygainfilter->downsample; @@ -523,11 +522,11 @@ AnalyzeSamples ( const Float_t* left_samples, const Float_t* right_samples, size } -static Float_t -analyzeResult ( Uint32_t* Array, size_t len ) +static float_t +analyzeResult ( uint32_t* Array, size_t len ) { - Uint32_t elems; - Int32_t upper; + uint32_t elems; + int32_t upper; size_t i; elems = 0; @@ -537,23 +536,23 @@ analyzeResult ( Uint32_t* Array, size_t len ) return GAIN_NOT_ENOUGH_SAMPLES; #if 0 /* GCC bug workaround: it incorrectly calculates 'elems * (1. - RMS_PERCENTILE)' with -O3 -msse2 ... options */ - upper = (Int32_t) ceil (elems * (1. - RMS_PERCENTILE)); + upper = (int32_t) ceil (elems * (1. - RMS_PERCENTILE)); #else - upper = (Int32_t) (elems / 20 + ((elems % 20) ? 1 : 0)); + upper = (int32_t) (elems / 20 + ((elems % 20) ? 1 : 0)); #endif for ( i = len; i-- > 0; ) { if ( (upper -= Array[i]) <= 0 ) break; } - return (Float_t) ((Float_t)PINK_REF - (Float_t)i / (Float_t)STEPS_per_dB); + return (float_t) ((float_t)PINK_REF - (float_t)i / (float_t)STEPS_per_dB); } -Float_t +float_t GetTitleGain ( void ) { - Float_t retval; + float_t retval; unsigned int i; retval = analyzeResult ( A, sizeof(A)/sizeof(*A) ); @@ -572,7 +571,7 @@ GetTitleGain ( void ) } -Float_t +float_t GetAlbumGain ( void ) { return analyzeResult ( B, sizeof(B)/sizeof(*B) );