Add swap member to sbc struct and fix pcm plugin to not swap the buffer.

This commit is contained in:
Luiz Augusto von Dentz 2007-08-21 21:32:09 +00:00
parent 38c5be0cc3
commit b1618922db
5 changed files with 19 additions and 15 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -40,6 +40,7 @@ struct sbc_struct {
int blocks;
int subbands;
int bitpool;
int swap;
void *data;
int size;

View File

@ -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);

View File

@ -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);