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.
This commit is contained in:
Max Kellermann 2012-10-02 08:19:45 +02:00
parent e166ddf46f
commit 9e3f843291
2 changed files with 10 additions and 8 deletions

1
NEWS
View File

@ -5,6 +5,7 @@ ver 0.18 (2012/??/??)
- vorbis: skip 16 bit quantisation, provide float samples - vorbis: skip 16 bit quantisation, provide float samples
* encoder: * encoder:
- opus: new encoder plugin for the Opus codec - opus: new encoder plugin for the Opus codec
- vorbis: accept floating point input samples
* output: * output:
- new option "tags" may be used to disable sending tags to output - new option "tags" may be used to disable sending tags to output
* improved decoder/output error reporting * improved decoder/output error reporting

View File

@ -212,7 +212,7 @@ vorbis_encoder_open(struct encoder *_encoder,
{ {
struct vorbis_encoder *encoder = (struct vorbis_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; encoder->audio_format = *audio_format;
@ -327,12 +327,12 @@ vorbis_encoder_tag(struct encoder *_encoder, const struct tag *tag,
} }
static void static void
pcm16_to_vorbis_buffer(float **dest, const int16_t *src, interleaved_to_vorbis_buffer(float **dest, const float *src,
unsigned num_frames, unsigned num_channels) unsigned num_frames, unsigned num_channels)
{ {
for (unsigned i = 0; i < num_frames; i++) for (unsigned i = 0; i < num_frames; i++)
for (unsigned j = 0; j < num_channels; j++) for (unsigned j = 0; j < num_channels; j++)
dest[j][i] = *src++ / 32768.0; dest[j][i] = *src++;
} }
static bool static bool
@ -347,10 +347,11 @@ vorbis_encoder_write(struct encoder *_encoder,
/* this is for only 16-bit audio */ /* this is for only 16-bit audio */
pcm16_to_vorbis_buffer(vorbis_analysis_buffer(&encoder->vd, interleaved_to_vorbis_buffer(vorbis_analysis_buffer(&encoder->vd,
num_frames), num_frames),
(const int16_t *)data, (const float *)data,
num_frames, encoder->audio_format.channels); num_frames,
encoder->audio_format.channels);
vorbis_analysis_wrote(&encoder->vd, num_frames); vorbis_analysis_wrote(&encoder->vd, num_frames);
vorbis_encoder_blockout(encoder); vorbis_encoder_blockout(encoder);