diff options
author | Max Kellermann <max@duempel.org> | 2008-10-29 16:14:02 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-29 16:14:02 +0100 |
commit | e0532ae0a85ef16d4ec2d701fb07ff2dcb7217d9 (patch) | |
tree | 021a6b706583bd0f4c81f5cef4fa07d937143322 | |
parent | a6ad0e40471f652bd58ed2ea2a0409050b66b279 (diff) | |
download | mpd-e0532ae0a85ef16d4ec2d701fb07ff2dcb7217d9.tar.gz mpd-e0532ae0a85ef16d4ec2d701fb07ff2dcb7217d9.tar.xz mpd-e0532ae0a85ef16d4ec2d701fb07ff2dcb7217d9.zip |
mp3: moved code to mp3_send_pcm()
Break the large function mp3_read() into smaller pieces.
-rw-r--r-- | src/decoder/mp3_plugin.c | 77 |
1 files changed, 48 insertions, 29 deletions
diff --git a/src/decoder/mp3_plugin.c b/src/decoder/mp3_plugin.c index a36f979bf..8a1f87a31 100644 --- a/src/decoder/mp3_plugin.c +++ b/src/decoder/mp3_plugin.c @@ -871,14 +871,56 @@ mp3_update_timer_next_frame(struct mp3_data *data) mad_timer_count(data->timer, MAD_UNITS_MILLISECONDS) / 1000.0; } +/** + * Sends the synthesized current frame via decoder_data(). + */ +static enum decoder_command +mp3_send_pcm(struct mp3_data *data, unsigned i, unsigned pcm_length, + ReplayGainInfo *replay_gain_info) +{ + unsigned max_samples; + + max_samples = sizeof(data->output_buffer) / + sizeof(data->output_buffer[0]) / + MAD_NCHANNELS(&(data->frame).header); + + while (i < pcm_length) { + enum decoder_command cmd; + unsigned int num_samples = pcm_length - i; + if (num_samples > max_samples) + num_samples = max_samples; + + i += num_samples; + + mad_fixed_to_24_buffer(data->output_buffer, + &data->synth, + i - num_samples, i, + MAD_NCHANNELS(&(data->frame).header)); + num_samples *= MAD_NCHANNELS(&(data->frame).header); + + cmd = decoder_data(data->decoder, data->input_stream, + data->input_stream->seekable, + data->output_buffer, + sizeof(data->output_buffer[0]) * num_samples, + data->elapsed_time, + data->bit_rate / 1000, + replay_gain_info); + if (cmd == DECODE_COMMAND_STOP) + return cmd; + } + + return DECODE_COMMAND_NONE; +} + static enum mp3_action mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) { struct decoder *decoder = data->decoder; - unsigned int pcm_length, max_samples; + unsigned int pcm_length; unsigned int i; int ret; int skip; + enum decoder_command cmd; mp3_update_timer_next_frame(data); @@ -943,34 +985,11 @@ mp3_read(struct mp3_data *data, ReplayGainInfo **replay_gain_info_r) pcm_length -= data->drop_end_samples; } - max_samples = sizeof(data->output_buffer) / - sizeof(data->output_buffer[0]) / - MAD_NCHANNELS(&(data->frame).header); - - while (i < pcm_length) { - enum decoder_command cmd; - unsigned int num_samples = pcm_length - i; - if (num_samples > max_samples) - num_samples = max_samples; - - i += num_samples; - - mad_fixed_to_24_buffer(data->output_buffer, - &data->synth, - i - num_samples, i, - MAD_NCHANNELS(&(data->frame).header)); - num_samples *= MAD_NCHANNELS(&(data->frame).header); - - cmd = decoder_data(decoder, data->input_stream, - data->input_stream->seekable, - data->output_buffer, - sizeof(data->output_buffer[0]) * num_samples, - data->elapsed_time, - data->bit_rate / 1000, - (replay_gain_info_r != NULL) ? *replay_gain_info_r : NULL); - if (cmd == DECODE_COMMAND_STOP) - return DECODE_BREAK; - } + cmd = mp3_send_pcm(data, i, pcm_length, + replay_gain_info_r != NULL + ? *replay_gain_info_r : NULL); + if (cmd == DECODE_COMMAND_STOP) + return DECODE_BREAK; if (data->drop_end_samples && (data->current_frame == data->max_frames - data->drop_end_frames)) |