static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
struct afh_info *afhi)
{
static int mp3_read_info(unsigned char *map, size_t numbytes, int fd,
struct afh_info *afhi)
{
int ret, len = 0, old_br = -1, vbr = 0;
struct timeval total_time = {0, 0};
unsigned chunk_table_size = 1000; /* gets increased on demand */
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) {
afhi->chunk_table = para_malloc(chunk_table_size * sizeof(uint32_t));
taginfo = mp3_get_id3(map, numbytes, fd);
while (1) {
struct timeval tmp, cct; /* current chunk time */
fpos += len;
len = find_valid_start(map, numbytes, &fpos, &header);
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;
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 >= 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 == 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)
afhi->channels = header_channels(&header);
afhi->seconds_total = (tv2ms(&total_time) + 500) / 1000;
tv_divide(afhi->chunks_total, &total_time, &afhi->chunk_tv);
afhi->channels = header_channels(&header);
afhi->seconds_total = (tv2ms(&total_time) + 500) / 1000;
tv_divide(afhi->chunks_total, &total_time, &afhi->chunk_tv);