aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-02-10 21:25:45 +0100
committerMax Kellermann <max@duempel.org>2009-02-10 21:25:45 +0100
commit12756c1b55dcf95364bb6ce5a476387e99067478 (patch)
treed37c650fc7ae25dbcf24969d8b82d2f890bfcfa8
parent54982f755f208c1b0c1de4734e5c1b6d78dff6ea (diff)
downloadmpd-12756c1b55dcf95364bb6ce5a476387e99067478.tar.gz
mpd-12756c1b55dcf95364bb6ce5a476387e99067478.tar.xz
mpd-12756c1b55dcf95364bb6ce5a476387e99067478.zip
shout_ogg: moved PCM conversion to a separate function
For simplification, moved the PCM conversion code to pcm16_to_ogg_buffer(). Work with a int16_t pointer instead of a char pointer.
-rw-r--r--src/output/shout_ogg.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/output/shout_ogg.c b/src/output/shout_ogg.c
index ebf84c0bf..b7c7b6706 100644
--- a/src/output/shout_ogg.c
+++ b/src/output/shout_ogg.c
@@ -238,28 +238,29 @@ static int shout_ogg_encoder_send_metadata(struct shout_data *sd,
return 0;
}
+static void
+pcm16_to_ogg_buffer(float **dest, const int16_t *src,
+ unsigned num_samples, unsigned num_channels)
+{
+ for (unsigned i = 0; i < num_samples; i++)
+ for (unsigned j = 0; j < num_channels; j++)
+ dest[j][i] = *src++ / 32768.0;
+}
+
static int shout_ogg_encoder_encode(struct shout_data *sd,
const char *chunk, size_t size)
{
struct shout_buffer *buf = &sd->buf;
- unsigned int i;
- int j;
- float **vorbbuf;
unsigned int samples;
- int bytes = audio_format_sample_size(&sd->audio_format);
struct ogg_vorbis_data *od = (struct ogg_vorbis_data *)sd->encoder_data;
- samples = size / (bytes * sd->audio_format.channels);
- vorbbuf = vorbis_analysis_buffer(&od->vd, samples);
+ samples = size / audio_format_frame_size(&sd->audio_format);
/* this is for only 16-bit audio */
- for (i = 0; i < samples; i++) {
- for (j = 0; j < sd->audio_format.channels; j++) {
- vorbbuf[j][i] = (*((const int16_t *) chunk)) / 32768.0;
- chunk += bytes;
- }
- }
+ pcm16_to_ogg_buffer(vorbis_analysis_buffer(&od->vd, samples),
+ (const int16_t *)chunk,
+ samples, sd->audio_format.channels);
vorbis_analysis_wrote(&od->vd, samples);