aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins/mp3_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-26 08:27:12 +0200
committerEric Wong <normalperson@yhbt.net>2008-08-30 19:21:10 -0700
commit34b5a1c80be51698acc7ac22a3480097ca33e7ad (patch)
tree1bccb34d2e2c5360141db829003be43906fd61b8 /src/inputPlugins/mp3_plugin.c
parenta7eebfdd0e84653e2a005b47f4091c263c0bbd99 (diff)
downloadmpd-34b5a1c80be51698acc7ac22a3480097ca33e7ad.tar.gz
mpd-34b5a1c80be51698acc7ac22a3480097ca33e7ad.tar.xz
mpd-34b5a1c80be51698acc7ac22a3480097ca33e7ad.zip
mp3: moved code to dither_buffer()
Preparing for simplifying and thus speeding up the dithering code: moved dithering to a separate function which contains a trivial loop. With this patch, only one sample is dithered at a time, but the following patches will allow us to dither a whole block at a time, without complicated buffer length checks.
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/mp3_plugin.c44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index 11d543199..87c8d6ea9 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -105,6 +105,30 @@ static signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample,
return output >> scalebits;
}
+static unsigned dither_buffer(mpd_sint16 *dest0, const struct mad_synth *synth,
+ struct audio_dither *dither,
+ unsigned int start, unsigned int end,
+ unsigned int num_channels)
+{
+ mpd_sint16 *dest = dest0;
+ unsigned int i;
+
+ for (i = start; i < end; ++i) {
+ *dest++ = (mpd_sint16)
+ audio_linear_dither(16,
+ synth->pcm.samples[0][i],
+ dither);
+
+ if (num_channels == 2)
+ *dest++ = (mpd_sint16)
+ audio_linear_dither(16,
+ synth->pcm.samples[1][i],
+ dither);
+ }
+
+ return dest - dest0;
+}
+
/* end of stolen stuff from mpg321 */
static int mp3_plugin_init(void)
@@ -934,7 +958,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
i = 0;
for (; i < (data->synth).pcm.length; i++) {
- mpd_sint16 *sample;
+ unsigned int num_samples;
samplesLeft--;
@@ -946,19 +970,11 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
return DECODE_BREAK;
}
- sample = (mpd_sint16 *) data->outputPtr;
- *sample = (mpd_sint16) audio_linear_dither(16,
- (data->synth).pcm.samples[0][i],
- &(data->dither));
- data->outputPtr += 2;
-
- if (MAD_NCHANNELS(&(data->frame).header) == 2) {
- sample = (mpd_sint16 *) data->outputPtr;
- *sample = (mpd_sint16) audio_linear_dither(16,
- (data->synth).pcm.samples[1][i],
- &(data->dither));
- data->outputPtr += 2;
- }
+ num_samples = dither_buffer((mpd_sint16 *) data->outputPtr,
+ &data->synth, &data->dither,
+ i, i + 1,
+ MAD_NCHANNELS(&(data->frame).header));
+ data->outputPtr += 2 * num_samples;
if (data->outputPtr >= data->outputBufferEnd) {
enum dc_action action = ob_send(