diff options
author | Max Kellermann <max@duempel.org> | 2012-10-02 08:19:45 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-10-02 08:39:39 +0200 |
commit | 9e3f843291876b2cd62196c22be1130c0031bfc0 (patch) | |
tree | 323a87b073fd7f8c52d823f6c451a4c8ab070496 /src/encoder/VorbisEncoderPlugin.cxx | |
parent | e166ddf46f16ca115372bc05a880e47deafc23c1 (diff) | |
download | mpd-9e3f843291876b2cd62196c22be1130c0031bfc0.tar.gz mpd-9e3f843291876b2cd62196c22be1130c0031bfc0.tar.xz mpd-9e3f843291876b2cd62196c22be1130c0031bfc0.zip |
encoder/vorbis: accept floating point input samples
Improves quality by not squeezing 32 bit samples down to 16 bit, and
then back to 32 bit floating point. Reduces CPU usage by skipping a
conversion step.
Diffstat (limited to 'src/encoder/VorbisEncoderPlugin.cxx')
-rw-r--r-- | src/encoder/VorbisEncoderPlugin.cxx | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/encoder/VorbisEncoderPlugin.cxx b/src/encoder/VorbisEncoderPlugin.cxx index 226a59abf..ff1c6b8df 100644 --- a/src/encoder/VorbisEncoderPlugin.cxx +++ b/src/encoder/VorbisEncoderPlugin.cxx @@ -212,7 +212,7 @@ vorbis_encoder_open(struct encoder *_encoder, { struct vorbis_encoder *encoder = (struct vorbis_encoder *)_encoder; - audio_format->format = SAMPLE_FORMAT_S16; + audio_format->format = SAMPLE_FORMAT_FLOAT; encoder->audio_format = *audio_format; @@ -327,12 +327,12 @@ vorbis_encoder_tag(struct encoder *_encoder, const struct tag *tag, } static void -pcm16_to_vorbis_buffer(float **dest, const int16_t *src, - unsigned num_frames, unsigned num_channels) +interleaved_to_vorbis_buffer(float **dest, const float *src, + unsigned num_frames, unsigned num_channels) { for (unsigned i = 0; i < num_frames; i++) for (unsigned j = 0; j < num_channels; j++) - dest[j][i] = *src++ / 32768.0; + dest[j][i] = *src++; } static bool @@ -347,10 +347,11 @@ vorbis_encoder_write(struct encoder *_encoder, /* this is for only 16-bit audio */ - pcm16_to_vorbis_buffer(vorbis_analysis_buffer(&encoder->vd, - num_frames), - (const int16_t *)data, - num_frames, encoder->audio_format.channels); + interleaved_to_vorbis_buffer(vorbis_analysis_buffer(&encoder->vd, + num_frames), + (const float *)data, + num_frames, + encoder->audio_format.channels); vorbis_analysis_wrote(&encoder->vd, num_frames); vorbis_encoder_blockout(encoder); |