X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=mood.c;h=d47c54efa360b856c63b660fd4cdb5b81d442b68;hb=81bc7110ff6a4c2d002618b94fcf5aa60cd4cad2;hp=a228b2432f9b56d3bc51535c13d74094314e7da9;hpb=c20e3e67fc2be1d5f8778b9c482271e023bbdcb8;p=paraslash.git diff --git a/mood.c b/mood.c index a228b243..d47c54ef 100644 --- a/mood.c +++ b/mood.c @@ -138,7 +138,7 @@ static void destroy_mood(struct mood *m) static struct mood *alloc_new_mood(const char *name) { - struct mood *m = para_calloc(sizeof(struct mood)); + struct mood *m = zalloc(sizeof(struct mood)); if (name) m->name = para_strdup(name); return m; @@ -249,20 +249,22 @@ int mood_check_callback(struct afs_callback_arg *aca) * overflows and rounding errors we store the common divisor of the * correction factors separately. */ -static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd) -{ - if (!n || !qd) - return 0; - return 100 * (n * x - sum) / (int64_t)int_sqrt(n) / (int64_t)int_sqrt(qd); -} - static long compute_score(struct afs_info *afsi) { - long score = -normalized_value(afsi->num_played, statistics.num, - statistics.num_played_sum, statistics.num_played_qd); - score -= normalized_value(afsi->last_played, statistics.num, - statistics.last_played_sum, statistics.last_played_qd); - return score / 2; + int64_t mean_n, mean_l,score_n, score_l; + + assert(statistics.normalization_divisor > 0); + assert(statistics.num > 0); + mean_n = statistics.num_played_sum / statistics.num; + mean_l = statistics.last_played_sum / statistics.num; + + score_n = -((int64_t)afsi->num_played - mean_n) + * statistics.num_played_correction + / statistics.normalization_divisor; + score_l = -((int64_t)afsi->last_played - mean_l) + * statistics.last_played_correction + / statistics.normalization_divisor; + return (score_n + score_l) / 2; } static int add_afs_statistics(const struct osl_row *row) @@ -363,8 +365,8 @@ static int add_if_admissible(struct osl_row *aft_row, void *data) if (statistics.num >= aa->size) { aa->size *= 2; aa->size += 100; - aa->array = para_realloc(aa->array, - aa->size * sizeof(struct osl_row *)); + aa->array = arr_realloc(aa->array, aa->size, + sizeof(struct osl_row *)); } aa->array[statistics.num] = aft_row; return add_afs_statistics(aft_row); @@ -715,9 +717,17 @@ static int reload_current_mood(void) * \param pb Unused. * \param data Its type depends on the event. * - * This function performs actions required due to the occurrence of the given - * event. Possible actions include reload of the current mood and update of the - * score of an audio file. + * This function updates the score table according to the event that has + * occurred. Two actions are possible: (a) reload the current mood, or (b) + * add/remove/update the row of the score table which corresponds to the audio + * file that has been modified or whose afs info has been changed. It depends + * on the type of the event which action (if any) is performed. + * + * The callbacks of command handlers such as com_add() or com_touch() which + * modify the audio file table call this function. The virtual streaming system + * also calls this after it has updated the afs info of the file it is about to + * stream (the one with the highest score). If the file stays admissible, its + * score is recomputed so that a different file is picked next time. * * \return Standard. */