static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
struct afh_info *afhi)
{
- long freq_avg = 0, br_avg = 0;
+ uint64_t freq_sum = 0, br_sum = 0;
int ret, len = 0, old_br = -1, vbr = 0;
struct timeval total_time = {0, 0};
unsigned chunk_table_size = 1000; /* gets increased on demand */
afhi->chunk_table = para_malloc(chunk_table_size * sizeof(uint32_t));
taginfo = mp3_get_id3(map, numbytes, fd);
while (1) {
- unsigned long freq, br, fl;
+ int freq, br, fl;
struct timeval tmp, cct; /* current chunk time */
fpos += len;
len = find_valid_start(map, numbytes, &fpos, &header);
tv_divide(br * 125, &tmp, &cct);
tv_add(&cct, &total_time, &tmp);
total_time = tmp;
- //PARA_DEBUG_LOG("%s: br: %d, freq: %d, fl: %d, cct: %lu\n", __func__, br, freq, fl, cct.tv_usec);
if (afhi->chunks_total >= chunk_table_size) {
chunk_table_size *= 2;
afhi->chunk_table = para_realloc(afhi->chunk_table,
chunk_table_size * sizeof(uint32_t));
}
afhi->chunk_table[afhi->chunks_total] = fpos;
-// if (afhi->chunks_total < 10 || !(afhi->chunks_total % 1000))
-// PARA_INFO_LOG("chunk #%lu: %zd\n", afhi->chunks_total,
-// afhi->chunk_table[afhi->chunks_total]);
afhi->chunks_total++;
- if (afhi->chunks_total == 1) {
- freq_avg = freq;
- br_avg = br;
- old_br = br;
- continue;
- }
- freq_avg += ((long)freq - freq_avg) / ((long)afhi->chunks_total + 1);
- br_avg += ((long)br - br_avg) / ((long)afhi->chunks_total + 1);
- if (old_br != br)
+ freq_sum += freq;
+ br_sum += br;
+ if (afhi->chunks_total != 1 && old_br != br)
vbr = 1;
old_br = br;
}
ret = -E_MP3_INFO;
- if (!afhi->chunks_total || !freq_avg || !br_avg)
+ if (!afhi->chunks_total || !freq_sum || !br_sum)
goto err_out;
afhi->chunk_table[afhi->chunks_total] = numbytes - 1;
- afhi->bitrate = br_avg;
- afhi->frequency = freq_avg;
+ afhi->bitrate = br_sum / afhi->chunks_total;
+ afhi->frequency = freq_sum / afhi->chunks_total;
afhi->channels = header_channels(&header);
afhi->seconds_total = (tv2ms(&total_time) + 500) / 1000;
tv_divide(afhi->chunks_total, &total_time, &afhi->chunk_tv);