aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-24 17:34:47 +0200
committerMax Kellermann <max@duempel.org>2008-10-24 17:34:47 +0200
commitb1adfaae439fd0e28724265d13aa5040afd51022 (patch)
tree0089eec135ae916a2cb2adbb6e7c45df321a13cb /src
parent03a077e8a4b0f235f4ea0b5d018a49cab9a44f46 (diff)
downloadmpd-b1adfaae439fd0e28724265d13aa5040afd51022.tar.gz
mpd-b1adfaae439fd0e28724265d13aa5040afd51022.tar.xz
mpd-b1adfaae439fd0e28724265d13aa5040afd51022.zip
jack: moved code to jack_write_samples_16()
Move sample format dependent code to a separate function.
Diffstat (limited to 'src')
-rw-r--r--src/audioOutputs/audioOutput_jack.c56
1 files changed, 42 insertions, 14 deletions
diff --git a/src/audioOutputs/audioOutput_jack.c b/src/audioOutputs/audioOutput_jack.c
index c4d6062fd..b24ce77ee 100644
--- a/src/audioOutputs/audioOutput_jack.c
+++ b/src/audioOutputs/audioOutput_jack.c
@@ -356,14 +356,50 @@ mpd_jack_cancel (mpd_unused void *data)
{
}
+static inline jack_default_audio_sample_t
+sample_16_to_jack(int16_t sample)
+{
+ return sample / (jack_default_audio_sample_t)(1 << (16 - 1));
+}
+
+static void
+mpd_jack_write_samples_16(struct jack_data *jd, const int16_t *src,
+ unsigned num_samples)
+{
+ jack_default_audio_sample_t sample;
+
+ while (num_samples-- > 0) {
+ sample = sample_16_to_jack(*src++);
+ jack_ringbuffer_write(jd->ringbuffer[0], (void*)&sample,
+ sizeof(sample));
+
+ sample = sample_16_to_jack(*src++);
+ jack_ringbuffer_write(jd->ringbuffer[1], (void*)&sample,
+ sizeof(sample));
+ }
+}
+
+static void
+mpd_jack_write_samples(struct jack_data *jd, const void *src,
+ unsigned num_samples)
+{
+ switch (jd->audio_format->bits) {
+ case 16:
+ mpd_jack_write_samples_16(jd, (const int16_t*)src,
+ num_samples);
+ break;
+
+ default:
+ assert(false);
+ }
+}
+
static int
mpd_jack_play(void *data, const char *buff, size_t size)
{
struct jack_data *jd = data;
+ const size_t frame_size = audio_format_frame_size(jd->audio_format);
size_t space, space1;
- const short *buffer = (const short *) buff;
- static const size_t frame_size = sizeof(*buffer) * 2;
- jack_default_audio_sample_t sample;
if (jd->shutdown) {
ERROR("Refusing to play, because there is no client thread.\n");
@@ -386,18 +422,10 @@ mpd_jack_play(void *data, const char *buff, size_t size)
if (space > size)
space = size;
- size -= space;
- while (space-- > 0) {
- sample = (jack_default_audio_sample_t) *(buffer++)/32768.0;
-
- jack_ringbuffer_write(jd->ringbuffer[0], (void*)&sample,
- sample_size);
+ mpd_jack_write_samples(jd, buff, space);
- sample = (jack_default_audio_sample_t) *(buffer++)/32768.0;
-
- jack_ringbuffer_write(jd->ringbuffer[1], (void*)&sample,
- sample_size);
- }
+ buff += space * frame_size;
+ size -= space;
} else {
/* XXX do something more intelligent to
synchronize */