extern int get_max( MOTYPE mtype, /* the model type */ DATASET *dataset, /* the dataset */ int w, /* width of sites */ P_PROB maxima, /* array of encoded site starts of local maxima */ BOOLEAN ic, /* use reverse complement, too */ BOOLEAN sort /* sort the maxima */ ) { int n_maxima; /* find the maxima */ if (mtype == Oops || mtype == Zoops) { n_maxima = global_max(dataset, w, maxima, ic); } else { n_maxima = local_max(dataset, w, maxima, ic); } /* sort the local maxima of pY[1] */ if (sort) qsort((char *) maxima, n_maxima, sizeof(p_prob), pY_compare); return n_maxima; } /* get_max */
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 const unsigned nbuffer = sizeof(lbuffer) / sizeof(lbuffer[0]); FLAC__int32 block_peak = 0, s; unsigned i, j; FLAC__ASSERT(bps >= 4 && bps <= FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE); FLAC__ASSERT(FLAC__MIN_BITS_PER_SAMPLE == 4); /* * We use abs() on a FLAC__int32 which is undefined for the most negative value. * If the reference codec ever handles 32bps we will have to write a special * case here. */ FLAC__ASSERT(FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE < 32); if(bps == 16) { if(is_stereo) { j = 0; while(samples > 0) { const unsigned n = local_min(samples, nbuffer); for(i = 0; i < n; i++, j++) { s = input[0][j]; lbuffer[i] = (Float_t)s; s = abs(s); block_peak = local_max(block_peak, s); s = input[1][j]; rbuffer[i] = (Float_t)s; s = abs(s); block_peak = local_max(block_peak, s); } samples -= n; if(AnalyzeSamples(lbuffer, rbuffer, n, 2) != GAIN_ANALYSIS_OK) return false; } } else { j = 0; while(samples > 0) { const unsigned n = local_min(samples, nbuffer); for(i = 0; i < n; i++, j++) { s = input[0][j]; lbuffer[i] = (Float_t)s; s = abs(s); block_peak = local_max(block_peak, s); } samples -= n; if(AnalyzeSamples(lbuffer, 0, n, 1) != GAIN_ANALYSIS_OK) return false; } } } else { /* bps must be < 32 according to above assertion */ const double scale = ( (bps > 16)? (double)1. / (double)(1u << (bps - 16)) : (double)(1u << (16 - bps)) ); if(is_stereo) { j = 0; while(samples > 0) { 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); s = abs(s); block_peak = local_max(block_peak, s); s = input[1][j]; rbuffer[i] = (Float_t)(scale * (double)s); s = abs(s); block_peak = local_max(block_peak, s); } samples -= n; if(AnalyzeSamples(lbuffer, rbuffer, n, 2) != GAIN_ANALYSIS_OK) return false; } } else { j = 0; while(samples > 0) { 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); s = abs(s); block_peak = local_max(block_peak, s); } samples -= n; if(AnalyzeSamples(lbuffer, 0, n, 1) != GAIN_ANALYSIS_OK) return false; } } } { const double peak_scale = (double)(1u << (bps - 1)); double peak = (double)block_peak / peak_scale; if(peak > title_peak_) title_peak_ = peak; if(peak > album_peak_) album_peak_ = peak; } return true; }