diff options
author | Max Kellermann <max@duempel.org> | 2014-12-24 22:40:00 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-12-24 22:40:00 +0100 |
commit | da83eae754548b047c7b27fb29d75d8467f7f20f (patch) | |
tree | 76f656b382ffda396059aa032c24df9a8997f011 | |
parent | c5409d52f5d4edace90f81585fe0f07da64e0f5d (diff) | |
download | mpd-da83eae754548b047c7b27fb29d75d8467f7f20f.tar.gz mpd-da83eae754548b047c7b27fb29d75d8467f7f20f.tar.xz mpd-da83eae754548b047c7b27fb29d75d8467f7f20f.zip |
output/jack: use SampleFormat::FLOAT
What JACK expects is already implemented in MPD, just not used. The
sample format conversion code in the JACK plugin was redundant and
could reduce sound quality.
-rw-r--r-- | src/output/plugins/JackOutputPlugin.cxx | 64 |
1 files changed, 9 insertions, 55 deletions
diff --git a/src/output/plugins/JackOutputPlugin.cxx b/src/output/plugins/JackOutputPlugin.cxx index c251048f2..9dd63562e 100644 --- a/src/output/plugins/JackOutputPlugin.cxx +++ b/src/output/plugins/JackOutputPlugin.cxx @@ -111,8 +111,6 @@ struct JackOutput { void Process(jack_nframes_t nframes); - void WriteSamples16(const int16_t *src, unsigned num_samples); - void WriteSamples24(const int32_t *src, unsigned num_samples); void WriteSamples(const void *src, unsigned num_samples); size_t Play(const void *chunk, size_t size, Error &error); }; @@ -228,9 +226,10 @@ set_audioformat(JackOutput *jd, AudioFormat &audio_format) else if (audio_format.channels > jd->num_source_ports) audio_format.channels = 2; - if (audio_format.format != SampleFormat::S16 && - audio_format.format != SampleFormat::S24_P32) - audio_format.format = SampleFormat::S24_P32; + /* JACK uses 32 bit float in the range [-1 .. 1] - just like + MPD's SampleFormat::FLOAT*/ + static_assert(jack_sample_size == sizeof(float), "Expected float32"); + audio_format.format = SampleFormat::FLOAT; } static void @@ -637,65 +636,20 @@ mpd_jack_delay(AudioOutput *ao) : 0; } -static inline jack_default_audio_sample_t -sample_16_to_jack(int16_t sample) -{ - return sample / (jack_default_audio_sample_t)(1 << (16 - 1)); -} - inline void -JackOutput::WriteSamples16(const int16_t *src, unsigned num_samples) -{ - while (num_samples-- > 0) { - for (unsigned i = 0; i < audio_format.channels; ++i) { - jack_default_audio_sample_t sample = - sample_16_to_jack(*src++); - jack_ringbuffer_write(ringbuffer[i], - (const char *)&sample, - sizeof(sample)); - } - } -} - -static inline jack_default_audio_sample_t -sample_24_to_jack(int32_t sample) -{ - return sample / (jack_default_audio_sample_t)(1 << (24 - 1)); -} - -inline void -JackOutput::WriteSamples24(const int32_t *src, unsigned num_samples) +JackOutput::WriteSamples(const void *_src, unsigned num_samples) { + const float *src = (const float *)_src; while (num_samples-- > 0) { - for (unsigned i = 0; i < audio_format.channels; ++i) { - jack_default_audio_sample_t sample = - sample_24_to_jack(*src++); + for (unsigned i = 0; i < audio_format.channels; ++i, ++src) { jack_ringbuffer_write(ringbuffer[i], - (const char *)&sample, - sizeof(sample)); + (const char *)src, + sizeof(*src)); } } } -inline void -JackOutput::WriteSamples(const void *src, unsigned num_samples) -{ - switch (audio_format.format) { - case SampleFormat::S16: - WriteSamples16((const int16_t *)src, num_samples); - break; - - case SampleFormat::S24_P32: - WriteSamples24((const int32_t *)src, num_samples); - break; - - default: - assert(false); - gcc_unreachable(); - } -} - inline size_t JackOutput::Play(const void *chunk, size_t size, Error &error) { |