summaryrefslogtreecommitdiff
path: root/plugins/sndfile
diff options
context:
space:
mode:
authorGravatar waker <wakeroid@gmail.com>2012-05-09 18:55:53 +0200
committerGravatar waker <wakeroid@gmail.com>2012-05-09 18:55:53 +0200
commitbda0fe14a9161461df560ce8b235ec25e3599ede (patch)
treee60a11a28bb2a0d39e18aa6a7b33b8d92cb4695d /plugins/sndfile
parent7dbc5fcbba40a79a314b6d9c86170b2a874e517b (diff)
sndfile: fixed bigendian support
Diffstat (limited to 'plugins/sndfile')
-rw-r--r--plugins/sndfile/sndfile.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/sndfile/sndfile.c b/plugins/sndfile/sndfile.c
index 071dffdb..e10979be 100644
--- a/plugins/sndfile/sndfile.c
+++ b/plugins/sndfile/sndfile.c
@@ -47,6 +47,7 @@ typedef struct {
int bitrate;
int sf_format;
int read_as_short;
+ int sf_need_endswap;
} sndfile_info_t;
// vfs wrapper for sf
@@ -176,6 +177,7 @@ sndfile_init (DB_fileinfo_t *_info, DB_playItem_t *it) {
}
_info->plugin = &plugin;
info->sf_format = inf.format&0x000f;
+ info->sf_need_endswap = sf_command (info->ctx, SFC_RAW_DATA_NEEDS_ENDSWAP, NULL, 0);
switch (inf.format&0x000f) {
case SF_FORMAT_PCM_S8:
@@ -279,6 +281,36 @@ sndfile_read (DB_fileinfo_t *_info, char *bytes, int size) {
((int8_t *)bytes)[i] = sample-0x80;
}
}
+ else if (info->sf_need_endswap) {
+ switch (info->info.fmt.bps) {
+ case 16:
+ {
+ uint16_t *data = (uint16_t *)bytes;
+ for (int i = 0; i < n; i++, data++) {
+ *data = ((*data & 0xff) << 8) | ((*data & 0xff00) >> 8);
+ }
+ }
+ break;
+ case 24:
+ {
+ uint8_t *data = bytes;
+ for (int i = 0; i < n; i++, data += 3) {
+ uint8_t temp = data[0];
+ data[0] = data[2];
+ data[2] = temp;
+ }
+ }
+ break;
+ case 32:
+ {
+ uint32_t *data = (uint32_t *)bytes;
+ for (int i = 0; i < n; i++, data++) {
+ *data = ((*data & 0xff) << 24) | ((*data & 0xff00) << 8) | ((*data & 0xff0000) >> 8) | ((*data & 0xff0000) >> 24);
+ }
+ }
+ break;
+ }
+ }
n /= samplesize;
}