From 12756c1b55dcf95364bb6ce5a476387e99067478 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 10 Feb 2009 21:25:45 +0100 Subject: 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. --- src/output/shout_ogg.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/output/shout_ogg.c') 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); -- cgit v1.2.3