Commit c1a999c4 authored by Max Kellermann's avatar Max Kellermann

decoder/flac: don't use float to calculate song duration

Simple (up-rounding) integer division is good enough. We're casting the result back to an integer anyway.
parent e51d9fc6
...@@ -159,6 +159,13 @@ struct flac_data { ...@@ -159,6 +159,13 @@ struct flac_data {
struct tag *tag; struct tag *tag;
}; };
static inline unsigned
flac_duration(const FLAC__StreamMetadata_StreamInfo *stream_info)
{
return (stream_info->total_samples + stream_info->sample_rate - 1) /
stream_info->sample_rate;
}
/* initializes a given FlacData struct */ /* initializes a given FlacData struct */
void void
flac_data_init(struct flac_data *data, struct decoder * decoder, flac_data_init(struct flac_data *data, struct decoder * decoder,
......
...@@ -272,8 +272,7 @@ flac_tag_load(const char *file, const char *char_tnum) ...@@ -272,8 +272,7 @@ flac_tag_load(const char *file, const char *char_tnum)
flac_vorbis_comments_to_tag(tag, char_tnum, flac_vorbis_comments_to_tag(tag, char_tnum,
&block->data.vorbis_comment); &block->data.vorbis_comment);
} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) { } else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) {
tag->time = ((float)block->data.stream_info.total_samples) / tag->time = flac_duration(&block->data.stream_info);
block->data.stream_info.sample_rate + 0.5;
} }
FLAC__metadata_object_delete(block); FLAC__metadata_object_delete(block);
} while (FLAC__metadata_simple_iterator_next(it)); } while (FLAC__metadata_simple_iterator_next(it));
...@@ -853,9 +852,7 @@ oggflac_tag_dup(const char *file) ...@@ -853,9 +852,7 @@ oggflac_tag_dup(const char *file)
flac_vorbis_comments_to_tag(ret, NULL, flac_vorbis_comments_to_tag(ret, NULL,
&block->data.vorbis_comment); &block->data.vorbis_comment);
} else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) { } else if (block->type == FLAC__METADATA_TYPE_STREAMINFO) {
ret->time = ((float)block->data.stream_info. ret->time = flac_duration(&block->data.stream_info);
total_samples) /
block->data.stream_info.sample_rate + 0.5;
} }
} while (FLAC__metadata_iterator_next(it)); } while (FLAC__metadata_iterator_next(it));
FLAC__metadata_iterator_delete(it); FLAC__metadata_iterator_delete(it);
......
...@@ -172,9 +172,7 @@ static void of_metadata_dup_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecode ...@@ -172,9 +172,7 @@ static void of_metadata_dup_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecode
switch (block->type) { switch (block->type) {
case FLAC__METADATA_TYPE_STREAMINFO: case FLAC__METADATA_TYPE_STREAMINFO:
data->tag->time = ((float)block->data.stream_info. data->tag->time = flac_duration(&block->data.stream_info);
total_samples) /
block->data.stream_info.sample_rate + 0.5;
return; return;
case FLAC__METADATA_TYPE_VORBIS_COMMENT: case FLAC__METADATA_TYPE_VORBIS_COMMENT:
flac_vorbis_comments_to_tag(data->tag, NULL, flac_vorbis_comments_to_tag(data->tag, NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment