From b1618922db92f9bc65b0841f66eb71742bc1b553 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 21 Aug 2007 21:32:09 +0000 Subject: [PATCH] Add swap member to sbc struct and fix pcm plugin to not swap the buffer. --- audio/pcm_bluetooth.c | 13 +------------ sbc/sbc.c | 18 +++++++++++++++--- sbc/sbc.h | 1 + sbc/sbcdec.c | 1 + sbc/sbcenc.c | 1 + 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c index 80afd5626..495f15210 100644 --- a/audio/pcm_bluetooth.c +++ b/audio/pcm_bluetooth.c @@ -109,16 +109,6 @@ struct bluetooth_data { struct bluetooth_a2dp a2dp; /* A2DP data */ }; -static void memcpy_changeendian(void *dst, const void *src, int size) -{ - int i; - const uint16_t *ptrsrc = src; - uint16_t *ptrdst = dst; - - for (i = 0; i < size / 2; i++) - *ptrdst++ = htons(*ptrsrc++); -} - static int bluetooth_start(snd_pcm_ioplug_t *io) { DBG("bluetooth_start %p", io); @@ -622,8 +612,7 @@ static snd_pcm_sframes_t bluetooth_a2dp_write(snd_pcm_ioplug_t *io, /* Ready for more data */ buff = (uint8_t *) areas->addr + (areas->first + areas->step * offset) / 8; - memcpy_changeendian(data->buffer + data->count, buff, - frame_size * frames_to_read); + memcpy(data->buffer + data->count, buff, frame_size * frames_to_read); /* Remember we have some frames in the pipe now */ data->count += frames_to_read * frame_size; diff --git a/sbc/sbc.c b/sbc/sbc.c index d485a5fde..d27c1e9a8 100644 --- a/sbc/sbc.c +++ b/sbc/sbc.c @@ -1289,6 +1289,7 @@ int sbc_init(sbc_t *sbc, unsigned long flags) sbc->subbands = 8; sbc->blocks = 16; sbc->bitpool = 32; + sbc->swap = 0; return 0; } @@ -1341,8 +1342,14 @@ int sbc_decode(sbc_t *sbc, void *data, int count) for (ch = 0; ch < priv->frame.channels; ch++) { int16_t s; s = priv->frame.pcm_sample[ch][i]; - *ptr++ = (s & 0xff00) >> 8; - *ptr++ = (s & 0x00ff); + + if (sbc->swap) { + *ptr++ = (s & 0xff00) >> 8; + *ptr++ = (s & 0x00ff); + } else { + *ptr++ = (s & 0x00ff); + *ptr++ = (s & 0xff00) >> 8; + } } } @@ -1387,7 +1394,12 @@ int sbc_encode(sbc_t *sbc, void *data, int count) for (i = 0; i < priv->frame.subbands * priv->frame.blocks; i++) { for (ch = 0; ch < sbc->channels; ch++) { - int16_t s = (ptr[0] & 0xff) << 8 | (ptr[1] & 0xff); + int16_t s; + + if (sbc->swap) + s = (ptr[0] & 0xff) << 8 | (ptr[1] & 0xff); + else + s = (ptr[0] & 0xff) | (ptr[1] & 0xff) << 8; ptr += 2; priv->frame.pcm_sample[ch][i] = s; } diff --git a/sbc/sbc.h b/sbc/sbc.h index 70881c123..11d9740d0 100644 --- a/sbc/sbc.h +++ b/sbc/sbc.h @@ -40,6 +40,7 @@ struct sbc_struct { int blocks; int subbands; int bitpool; + int swap; void *data; int size; diff --git a/sbc/sbcdec.c b/sbc/sbcdec.c index b53055507..d84a631b3 100644 --- a/sbc/sbcdec.c +++ b/sbc/sbcdec.c @@ -90,6 +90,7 @@ static void decode(char *filename, char *audiodevice, int tofile) } sbc_init(&sbc, 0L); + sbc.swap = 1; framelen = sbc_decode(&sbc, stream, streamlen); printf("%d Hz, %d channels\n", sbc.rate, sbc.channels); diff --git a/sbc/sbcenc.c b/sbc/sbcenc.c index 8919fb92e..2334f8d36 100644 --- a/sbc/sbcenc.c +++ b/sbc/sbcenc.c @@ -144,6 +144,7 @@ static void encode(char *filename, int subbands, int joint) sbc.channels = BE_INT(au_hdr->channels); sbc.subbands = subbands; sbc.joint = joint; + sbc.swap = 1; count = BE_INT(au_hdr->data_size); size = len - BE_INT(au_hdr->hdr_size); memmove(buf, buf + BE_INT(au_hdr->hdr_size), size);