summaryrefslogtreecommitdiff
path: root/plugins/tta
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-08-14 13:46:33 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-08-14 13:46:33 +0200
commit2e4f1c2c4d8ff0609f475be7817287939af5ed66 (patch)
treed0a5e6cacac488a1d27a4d16897ff8d1659c6980 /plugins/tta
parent2c307507e6e8027c3e1d95c5819d3ae1f2392477 (diff)
fixed tta 8bit decoding (was lossy)
Diffstat (limited to 'plugins/tta')
-rw-r--r--plugins/tta/ttadec.c4
-rw-r--r--plugins/tta/ttaplug.c48
2 files changed, 33 insertions, 19 deletions
diff --git a/plugins/tta/ttadec.c b/plugins/tta/ttadec.c
index 4d538517..d5466359 100644
--- a/plugins/tta/ttadec.c
+++ b/plugins/tta/ttadec.c
@@ -45,8 +45,8 @@
#include "../../deadbeef.h"
-#define trace(...) { fprintf (stderr, __VA_ARGS__); }
-//#define trace(fmt,...)
+//#define trace(...) { fprintf (stderr, __VA_ARGS__); }
+#define trace(fmt,...)
extern DB_functions_t *deadbeef;
diff --git a/plugins/tta/ttaplug.c b/plugins/tta/ttaplug.c
index bc26800a..d1815b35 100644
--- a/plugins/tta/ttaplug.c
+++ b/plugins/tta/ttaplug.c
@@ -103,19 +103,16 @@ tta_free (DB_fileinfo_t *_info) {
static int
tta_read_int16 (DB_fileinfo_t *_info, char *bytes, int size) {
tta_info_t *info = (tta_info_t *)_info;
- if (info->currentsample + size / (2 * _info->channels) > info->endsample) {
- size = (info->endsample - info->currentsample + 1) * 2 * _info->channels;
+ int out_ch = min (_info->channels, 2);
+ if (info->currentsample + size / (2 * out_ch) > info->endsample) {
+ size = (info->endsample - info->currentsample + 1) * 2 * out_ch;
if (size <= 0) {
return 0;
}
}
int initsize = size;
- int out_channels = _info->channels;
- if (out_channels > 2) {
- out_channels = 2;
- }
- int sample_size = 2 * out_channels;
+ int sample_size = 2 * out_ch;
while (size > 0) {
if (info->samples_to_skip > 0 && info->remaining > 0) {
@@ -131,19 +128,36 @@ tta_read_int16 (DB_fileinfo_t *_info, char *bytes, int size) {
n = min (n, info->remaining);
int nn = n;
char *p = info->buffer;
- p += (_info->bps >> 3) - 2; // hack: shift buffer, so that we always get 2 most significant bytes (24 bit support)
- while (n > 0) {
- *((int16_t*)bytes) = (int16_t)(((uint8_t)p[1]<<8) | (uint8_t)p[0]);
- bytes += 2;
- if (_info->channels == 2) {
- *((int16_t*)bytes) = (int16_t)(((uint8_t)(p+info->tta.BSIZE)[1]<<8) | (uint8_t)(p+info->tta.BSIZE)[0]);
+ if (_info->bps > 8) {
+ // hack: shift buffer, so that we always get 2 most significant bytes (24 bit support)
+ // same hack kinda works for 8bit, but it's not lossless
+ p += (_info->bps >> 3) - 2;
+ while (n > 0) {
+ *((int16_t*)bytes) = (int16_t)(((uint8_t)p[1]<<8) | (uint8_t)p[0]);
+ bytes += 2;
+ if (_info->channels == 2) {
+ *((int16_t*)bytes) = (int16_t)(((uint8_t)(p+info->tta.BSIZE)[1]<<8) | (uint8_t)(p+info->tta.BSIZE)[0]);
+ bytes += 2;
+ }
+ n--;
+ size -= sample_size;
+ p += info->tta.NCH * info->tta.BSIZE;
+ }
+ p -= (_info->bps >> 3) - 2;
+ }
+ else {
+ while (n > 0) {
+ *((int16_t*)bytes) = ((int16_t)(p[0])) << 8;
bytes += 2;
+ if (_info->channels == 2) {
+ *((int16_t*)bytes) = ((int16_t)(p[1])) << 8;
+ bytes += 2;
+ }
+ n--;
+ size -= sample_size;
+ p += info->tta.NCH * info->tta.BSIZE;
}
- n--;
- size -= sample_size;
- p += info->tta.NCH * info->tta.BSIZE;
}
- p -= (_info->bps >> 3) - 2;
if (info->remaining > nn) {
memmove (info->buffer, p, (info->remaining - nn) * info->tta.BSIZE * info->tta.NCH);
}