//------------------------------------------------------------------------- // This is a parser for a comma-separated value String. It returns one // value per call. It handles quoted String and depends on the caller to // tell it where the end of the String is. // Returns value in value and return pointing to character after separator // string //------------------------------------------------------------------------- static Uint32 nextcsv(const String &csv, int sep, const Uint32 start, const Uint32 end, String &value) { enum parsestate {INDQUOTE, INSQUOTE, NOTINQUOTE}; value = ""; Uint32 maxend = local_min(csv.size(), end); Uint32 idx = start; parsestate state = NOTINQUOTE; // Change KS 4 March 2002. Change from < to <=. Was dropping last char in string. // ATTN-RK-P3-071702: Added hack to check for null character because Strings // were sometimes getting created that included an extra null character. while (idx <= maxend && csv[idx]) { char idxchar = csv[idx]; switch (state) { case NOTINQUOTE: switch (idxchar) { case '\\': state = INSQUOTE; break; case '"': state = INDQUOTE; break; default: if (idxchar == sep) return idx + 1; else value.append(idxchar); break; } break; case INSQUOTE: value.append(idxchar); state = NOTINQUOTE; break; case INDQUOTE: switch (idxchar) { case '"': state = NOTINQUOTE; break; default: value.append(idxchar); break; } } idx++; } // end while return idx; }
static FLAC__bool parse_double_(const FLAC__StreamMetadata_VorbisComment_Entry *entry, double *val) { char s[32], *end; const char *p, *q; double v; FLAC__ASSERT(0 != entry); FLAC__ASSERT(0 != val); p = (const char *)entry->entry; q = strchr(p, '='); if(0 == q) return false; q++; memset(s, 0, sizeof(s)-1); strncpy(s, q, local_min(sizeof(s)-1, entry->length - (q-p))); v = strtod(s, &end); if(end == s) return false; *val = v; return true; }
static void optimize_leaf_nodes(const ml_instance_definition &mlid, boosted_loss_func loss_func, decision_tree &tree) { ml_vector<dt_node_ptr> leaf_nodes; gather_leaf_nodes(leaf_nodes, tree); double eps = sqrt(r8_epsilon()); for(auto &leaf_ptr : leaf_nodes) { // // use custom loss function if given, otherwise defaults to squared error loss // if(loss_func) { leaf_opt_helper help; help.instances = &leaf_ptr->leaf_instances; help.mlid = &mlid; help.loss_func = loss_func; double optimal = 0.0; double upper = leaf_ptr->feature_value.continuous_value * 100.0; double lower = upper * -1.0; if(lower > upper) { std::swap(lower, upper); } //puml::log("optimize: leaf before %.3f, ", leaf_ptr->feature_value.continuous_value); local_min(lower, upper, eps, eps, leaf_optimization, &help, &optimal); leaf_ptr->feature_value.continuous_value = optimal; //puml::log(" after %.3f\n", leaf_ptr->feature_value.continuous_value); } // empty the leaf instances vector. we only kept them around for this optimization step leaf_ptr->leaf_instances.clear(); leaf_ptr->leaf_instances.shrink_to_fit(); } }
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; }
double local_min ( double a, double b, double t, double f ( double x ), double &x ){ func_wrapper foo(f); return local_min(a, b, t, foo, x); }