diff options
author | Max Kellermann <max@duempel.org> | 2008-10-29 16:12:26 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-29 16:12:26 +0100 |
commit | a6f8776c944a91202fcd20acb8c7c1f4aed90685 (patch) | |
tree | d3fa37ba9bb9e121aeb5cf1e5db91f6e6273097a /src/decoder | |
parent | ec3083948f6eac7ec594eac63de006bcf566bc87 (diff) | |
download | mpd-a6f8776c944a91202fcd20acb8c7c1f4aed90685.tar.gz mpd-a6f8776c944a91202fcd20acb8c7c1f4aed90685.tar.xz mpd-a6f8776c944a91202fcd20acb8c7c1f4aed90685.zip |
mp3: moved code to mp3_time_to_frame()
Break the large function mp3_read() into smaller pieces.
Diffstat (limited to 'src/decoder')
-rw-r--r-- | src/decoder/mp3_plugin.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c index 29c0bde43..a4fd52738 100644 --- a/src/decoder/mp3_plugin.c +++ b/src/decoder/mp3_plugin.c @@ -820,6 +820,22 @@ mp3_open(struct input_stream *is, struct mp3_data *data, return true; } +static long +mp3_time_to_frame(const struct mp3_data *data, double t) +{ + unsigned long i; + + for (i = 0; i < data->highest_frame; ++i) { + double frame_time = + mad_timer_count(data->times[i], + MAD_UNITS_MILLISECONDS) / 1000.; + if (frame_time >= t) + break; + } + + return i; +} + static enum mp3_action mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) { @@ -951,18 +967,12 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) return DECODE_BREAK; if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK) { - unsigned long j = 0; + unsigned long j; assert(data->input_stream->seekable); - data->mute_frame = MUTEFRAME_SEEK; - while (j < data->highest_frame && - decoder_seek_where(decoder) > - ((float)mad_timer_count(data->times[j], - MAD_UNITS_MILLISECONDS)) - / 1000) { - j++; - } + j = mp3_time_to_frame(data, + decoder_seek_where(decoder)); if (j < data->highest_frame) { if (mp3_seek(data, data->frame_offsets[j])) { decoder_clear(decoder); @@ -970,8 +980,8 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) decoder_command_finished(decoder); } else decoder_seek_error(decoder); - data->mute_frame = MUTEFRAME_NONE; - } + } else + data->mute_frame = MUTEFRAME_SEEK; } } |